Skip to content

Commit d7f7ce6

Browse files
committed
fix: migrate ot openapi-typescript and openapi-fetch
Signed-off-by: Denis Golovin <[email protected]>
1 parent 40cf63a commit d7f7ce6

12 files changed

+6408
-88
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@
4949
"dependencies": {
5050
"@podman-desktop/api": "^1.14.1",
5151
"@podman-desktop/podman-extension-api": "^1.14.2",
52-
"@redhat-developer/rhcra-client": "^0.0.1",
53-
"@redhat-developer/rhsm-client": "^0.0.4",
5452
"axios": "^1.8.1",
5553
"js-yaml": "^4.1.0",
5654
"object-hash": "3.0.0",
55+
"openapi-fetch": "^0.13.4",
5756
"openid-client": "^5.7.0"
5857
},
5958
"devDependencies": {

pnpm-lock.yaml

+23-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extension.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { afterEach, beforeEach, expect, suite, test, vi } from 'vitest';
2525

2626
import * as extension from './extension';
2727
import * as podmanCli from './podman-cli';
28-
import * as subscription from './subscription';
28+
import * as subscription from './rh-api/subscription';
2929
import { ExtensionTelemetryLogger } from './telemetry';
3030
import * as util from './util';
3131

src/extension.ts

+28-25
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import { readFileSync } from 'node:fs';
2020
import path from 'node:path';
2121

2222
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';
2623

2724
import { onDidChangeSessions, RedHatAuthenticationService } from './authentication-service';
2825
import { getAuthConfig } from './configuration';
@@ -37,10 +34,11 @@ import {
3734
runSubscriptionManagerRegister,
3835
runSubscriptionManagerUnregister,
3936
} from './podman-cli';
37+
import { ContainerRegistryAuthorizerClient } from './rh-api/registry-authorizer';
38+
import { isRedHatRegistryConfigured, REGISTRY_REDHAT_IO,SubscriptionManagerClient } from './rh-api/subscription';
4039
import { SSOStatusBarItem } from './status-bar-item';
41-
import { isRedHatRegistryConfigured, REGISTRY_REDHAT_IO, signIntoRedHatDeveloperAccount } from './subscription';
4240
import { ExtensionTelemetryLogger as TelemetryLogger } from './telemetry';
43-
import { isLinux } from './util';
41+
import { isLinux, signIntoRedHatDeveloperAccount } from './util';
4442

4543
interface JwtToken {
4644
organization: {
@@ -111,24 +109,29 @@ async function createOrReuseRegistryServiceAccount(): Promise<void> {
111109
TOKEN: currentSession!.accessToken,
112110
});
113111
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) {
121119
// ignore error when there is no podman-desktop service account yet
122-
selectedServiceAccount = await saApiV1.createServiceAccountUsingPost1({
120+
const { data: createdServiceAccount } = await saApiV1.createServiceAccountUsingPost1({
123121
name: 'podman-desktop',
124122
description: 'Service account to use from Podman Desktop',
125123
redHatAccountId: accessTokenJson.organization.id,
126124
});
125+
if (createdServiceAccount) {
126+
serviceAccount = createdServiceAccount;
127+
} else {
128+
throw new Error(`Can't create registry authorizer service account.`);
129+
}
127130
}
128131

129132
await createRegistry(
130-
selectedServiceAccount!.credentials!.username!,
131-
selectedServiceAccount!.credentials!.password!,
133+
serviceAccount!.credentials!.username!,
134+
serviceAccount!.credentials!.password!,
132135
currentSession.account.label,
133136
);
134137
}
@@ -141,20 +144,20 @@ async function createOrReuseActivationKey(connection: extensionApi.ProviderConta
141144
TOKEN: currentSession!.accessToken,
142145
});
143146

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({
151152
name: 'podman-desktop',
152-
role: 'RHEL Server',
153+
role: 'RHEl Workstation',
153154
usage: 'Development/Test',
154155
serviceLevel: 'Self-Support',
155156
});
157+
if (createKeyErr) {
158+
throw new Error(createKeyErr.error?.message);
159+
}
156160
}
157-
158161
await runSubscriptionManagerRegister(connection, 'podman-desktop', accessTokenJson.organization.id);
159162
}
160163

@@ -165,7 +168,7 @@ async function isSimpleContentAccessEnabled(): Promise<boolean> {
165168
TOKEN: currentSession!.accessToken,
166169
});
167170
const response = await client.organization.checkOrgScaCapability();
168-
return !!response.body && response.body.simpleContentAccess === 'enabled';
171+
return response.data?.body?.simpleContentAccess === 'enabled';
169172
}
170173

171174
async function isSubscriptionManagerInstalled(connection: extensionApi.ProviderContainerConnection): Promise<boolean> {

0 commit comments

Comments
 (0)