17
17
***********************************************************************/
18
18
19
19
import * as extensionApi from '@podman-desktop/api' ;
20
- import type { ServiceAccountV1 } from '@redhat-developer/rhcra-client' ;
21
- import { ContainerRegistryAuthorizerClient } from '@redhat-developer/rhcra-client' ;
22
- import { SubscriptionManagerClient } from '@redhat-developer/rhsm-client' ;
23
20
24
21
import icon from '../icon.png' ;
25
22
import { onDidChangeSessions , RedHatAuthenticationService } from './authentication-service' ;
@@ -35,10 +32,11 @@ import {
35
32
runSubscriptionManagerRegister ,
36
33
runSubscriptionManagerUnregister ,
37
34
} from './podman-cli' ;
35
+ import { ContainerRegistryAuthorizerClient } from './rh-api/registry-authorizer' ;
36
+ import { isRedHatRegistryConfigured , REGISTRY_REDHAT_IO , SubscriptionManagerClient } from './rh-api/subscription' ;
38
37
import { SSOStatusBarItem } from './status-bar-item' ;
39
- import { isRedHatRegistryConfigured , REGISTRY_REDHAT_IO , signIntoRedHatDeveloperAccount } from './subscription' ;
40
38
import { ExtensionTelemetryLogger as TelemetryLogger } from './telemetry' ;
41
- import { isLinux } from './util' ;
39
+ import { isLinux , signIntoRedHatDeveloperAccount } from './util' ;
42
40
43
41
interface JwtToken {
44
42
organization : {
@@ -101,24 +99,29 @@ async function createOrReuseRegistryServiceAccount(): Promise<void> {
101
99
TOKEN : currentSession ! . accessToken ,
102
100
} ) ;
103
101
const saApiV1 = client . serviceAccountsApiV1 ;
104
- let selectedServiceAccount : ServiceAccountV1 | undefined ;
105
- try {
106
- selectedServiceAccount = await saApiV1 . serviceAccountByNameUsingGet1 (
107
- 'podman-desktop' ,
108
- accessTokenJson . organization . id ,
109
- ) ;
110
- } catch ( err ) {
102
+ await saApiV1 . removeServiceAccountUsingDelete1 ( 'podman-desktop' , accessTokenJson . organization . id ) ;
103
+ let { data : serviceAccount } = await saApiV1 . serviceAccountByNameUsingGet1 (
104
+ 'podman-desktop' ,
105
+ accessTokenJson . organization . id ,
106
+ ) ;
107
+
108
+ if ( ! serviceAccount ) {
111
109
// ignore error when there is no podman-desktop service account yet
112
- selectedServiceAccount = await saApiV1 . createServiceAccountUsingPost1 ( {
110
+ const { data : createdServiceAccount } = await saApiV1 . createServiceAccountUsingPost1 ( {
113
111
name : 'podman-desktop' ,
114
112
description : 'Service account to use from Podman Desktop' ,
115
113
redHatAccountId : accessTokenJson . organization . id ,
116
114
} ) ;
115
+ if ( createdServiceAccount ) {
116
+ serviceAccount = createdServiceAccount ;
117
+ } else {
118
+ throw new Error ( `Can't create registry authorizer service account.` ) ;
119
+ }
117
120
}
118
121
119
122
await createRegistry (
120
- selectedServiceAccount ! . credentials ! . username ! ,
121
- selectedServiceAccount ! . credentials ! . password ! ,
123
+ serviceAccount ! . credentials ! . username ! ,
124
+ serviceAccount ! . credentials ! . password ! ,
122
125
currentSession . account . label ,
123
126
) ;
124
127
}
@@ -131,20 +134,20 @@ async function createOrReuseActivationKey(connection: extensionApi.ProviderConta
131
134
TOKEN : currentSession ! . accessToken ,
132
135
} ) ;
133
136
134
- try {
135
- await client . activationKey . showActivationKey ( 'podman-desktop' ) ;
136
- // podman-desktop activation key exists
137
- } catch ( err ) {
138
- // ignore and continue with activation key creation
139
- // TODO: add check that used role and usage exists in organization
140
- await client . activationKey . createActivationKeys ( {
137
+ const { error : showKeyErr } = await client . activationKey . showActivationKey ( 'podman-desktop' ) ;
138
+
139
+ if ( showKeyErr ) {
140
+ // error is undefined when activation key already exists
141
+ const { error : createKeyErr } = await client . activationKey . createActivationKeys ( {
141
142
name : 'podman-desktop' ,
142
- role : 'RHEL Server ' ,
143
+ role : 'RHEl Workstation ' ,
143
144
usage : 'Development/Test' ,
144
145
serviceLevel : 'Self-Support' ,
145
146
} ) ;
147
+ if ( createKeyErr ) {
148
+ throw new Error ( createKeyErr . error ?. message ) ;
149
+ }
146
150
}
147
-
148
151
await runSubscriptionManagerRegister ( connection , 'podman-desktop' , accessTokenJson . organization . id ) ;
149
152
}
150
153
@@ -155,7 +158,7 @@ async function isSimpleContentAccessEnabled(): Promise<boolean> {
155
158
TOKEN : currentSession ! . accessToken ,
156
159
} ) ;
157
160
const response = await client . organization . checkOrgScaCapability ( ) ;
158
- return ! ! response . body && response . body . simpleContentAccess === 'enabled' ;
161
+ return response . data ? .body ? .simpleContentAccess === 'enabled' ;
159
162
}
160
163
161
164
async function isSubscriptionManagerInstalled ( connection : extensionApi . ProviderContainerConnection ) : Promise < boolean > {
0 commit comments