Skip to content

Commit 0a0108f

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

12 files changed

+6520
-200
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.2",
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

+135-156
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
@@ -17,9 +17,6 @@
1717
***********************************************************************/
1818

1919
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';
2320

2421
import icon from '../icon.png';
2522
import { onDidChangeSessions, RedHatAuthenticationService } from './authentication-service';
@@ -35,10 +32,11 @@ import {
3532
runSubscriptionManagerRegister,
3633
runSubscriptionManagerUnregister,
3734
} from './podman-cli';
35+
import { ContainerRegistryAuthorizerClient } from './rh-api/registry-authorizer';
36+
import { isRedHatRegistryConfigured, REGISTRY_REDHAT_IO,SubscriptionManagerClient } from './rh-api/subscription';
3837
import { SSOStatusBarItem } from './status-bar-item';
39-
import { isRedHatRegistryConfigured, REGISTRY_REDHAT_IO, signIntoRedHatDeveloperAccount } from './subscription';
4038
import { ExtensionTelemetryLogger as TelemetryLogger } from './telemetry';
41-
import { isLinux } from './util';
39+
import { isLinux, signIntoRedHatDeveloperAccount } from './util';
4240

4341
interface JwtToken {
4442
organization: {
@@ -101,24 +99,29 @@ async function createOrReuseRegistryServiceAccount(): Promise<void> {
10199
TOKEN: currentSession!.accessToken,
102100
});
103101
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) {
111109
// ignore error when there is no podman-desktop service account yet
112-
selectedServiceAccount = await saApiV1.createServiceAccountUsingPost1({
110+
const { data: createdServiceAccount } = await saApiV1.createServiceAccountUsingPost1({
113111
name: 'podman-desktop',
114112
description: 'Service account to use from Podman Desktop',
115113
redHatAccountId: accessTokenJson.organization.id,
116114
});
115+
if (createdServiceAccount) {
116+
serviceAccount = createdServiceAccount;
117+
} else {
118+
throw new Error(`Can't create registry authorizer service account.`);
119+
}
117120
}
118121

119122
await createRegistry(
120-
selectedServiceAccount!.credentials!.username!,
121-
selectedServiceAccount!.credentials!.password!,
123+
serviceAccount!.credentials!.username!,
124+
serviceAccount!.credentials!.password!,
122125
currentSession.account.label,
123126
);
124127
}
@@ -131,20 +134,20 @@ async function createOrReuseActivationKey(connection: extensionApi.ProviderConta
131134
TOKEN: currentSession!.accessToken,
132135
});
133136

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({
141142
name: 'podman-desktop',
142-
role: 'RHEL Server',
143+
role: 'RHEl Workstation',
143144
usage: 'Development/Test',
144145
serviceLevel: 'Self-Support',
145146
});
147+
if (createKeyErr) {
148+
throw new Error(createKeyErr.error?.message);
149+
}
146150
}
147-
148151
await runSubscriptionManagerRegister(connection, 'podman-desktop', accessTokenJson.organization.id);
149152
}
150153

@@ -155,7 +158,7 @@ async function isSimpleContentAccessEnabled(): Promise<boolean> {
155158
TOKEN: currentSession!.accessToken,
156159
});
157160
const response = await client.organization.checkOrgScaCapability();
158-
return !!response.body && response.body.simpleContentAccess === 'enabled';
161+
return response.data?.body?.simpleContentAccess === 'enabled';
159162
}
160163

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

0 commit comments

Comments
 (0)