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