Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: value is possibly undefined errors #431

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,33 @@ function removeRegistry(serverUrl: string = REGISTRY_REDHAT_IO): void {

async function createOrReuseRegistryServiceAccount(): Promise<void> {
const currentSession = await signIntoRedHatDeveloperAccount();
if (!currentSession) return;
const accessTokenJson = parseJwt(currentSession!.accessToken);
const client = new ContainerRegistryAuthorizerClient({
BASE: 'https://access.redhat.com/hydra/rest/terms-based-registry',
TOKEN: currentSession!.accessToken,
TOKEN: currentSession.accessToken,
});
const saApiV1 = client.serviceAccountsApiV1;
let selectedServiceAccount: ServiceAccountV1 | undefined;
let selectedServiceAccount: ServiceAccountV1;
try {
selectedServiceAccount = await saApiV1.serviceAccountByNameUsingGet1(
'podman-desktop',
accessTokenJson.organization.id,
);
} catch (err) {
// ignore error when there is no podman-desktop service account yet
selectedServiceAccount = await saApiV1.createServiceAccountUsingPost1({
name: 'podman-desktop',
description: 'Service account to use from Podman Desktop',
redHatAccountId: accessTokenJson.organization.id,
});
console.info('Red Hat registry service account does not exist.');
}

selectedServiceAccount = await saApiV1.createServiceAccountUsingPost1({
name: 'podman-desktop',
description: 'Service account to use from Podman Desktop',
redHatAccountId: accessTokenJson.organization.id,
});

await createRegistry(
selectedServiceAccount!.credentials!.username!,
selectedServiceAccount!.credentials!.password!,
selectedServiceAccount.credentials!.username!,
selectedServiceAccount.credentials!.password!,
currentSession.account.label,
);
}
Expand Down Expand Up @@ -165,15 +168,15 @@ async function isSimpleContentAccessEnabled(): Promise<boolean> {
TOKEN: currentSession!.accessToken,
});
const response = await client.organization.checkOrgScaCapability();
return response.body && response.body.simpleContentAccess === 'enabled';
return !!response.body && response.body.simpleContentAccess === 'enabled';
}

async function isSubscriptionManagerInstalled(machineName: string): Promise<boolean> {
const exitCode = await runSubscriptionManager(machineName);
return exitCode === 0;
}

async function installSubscriptionManger(machineName: string): Promise<extensionApi.RunResult> {
async function installSubscriptionManger(machineName: string): Promise<extensionApi.RunResult | undefined> {
try {
return await runRpmInstallSubscriptionManager(machineName);
} catch (err) {
Expand Down
Loading