Skip to content

Commit

Permalink
feat: retrieve pull-secret using Red Hat SSO account (#216)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin <[email protected]>
  • Loading branch information
dgolovin authored Jun 27, 2024
1 parent fcf98df commit e568606
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2,249 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"test": "vitest run --coverage --passWithNoTests"
},
"dependencies": {
"@redhat-developer/rhaccm-client": "^0.0.1"
},
"devDependencies": {
"@podman-desktop/api": "next",
Expand All @@ -92,5 +93,8 @@
"vitest": "^1.6.0",
"which": "^3.0.0",
"zip-local": "^0.3.5"
}
},
"extensionDependencies": [
"redhat.redhat-authentication"
]
}
34 changes: 28 additions & 6 deletions src/crc-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { crcStatus } from './crc-status';
import { commander } from './daemon-commander';
import { crcLogProvider } from './log-provider';
import { productName } from './util';
import { AccountManagementClient } from '@redhat-developer/rhaccm-client';

interface ImagePullSecret {
auths: Auths;
Expand Down Expand Up @@ -91,12 +92,33 @@ export async function startCrc(
}

async function askAndStorePullSecret(logger: extensionApi.Logger): Promise<boolean> {
const pullSecret = await extensionApi.window.showInputBox({
prompt: 'Provide a pull secret',
markdownDescription:
'To pull container images from the registry, a *pull secret* is necessary. You can get a pull secret from the [Red Hat OpenShift Local download page](https://console.redhat.com/openshift/create/local?sc_cid=7013a000003SUmqAAG). Use the *"Copy pull secret"* option and paste the content into the field above',
ignoreFocusOut: true,
});
let pullSecret: string;
const authSession: extensionApi.AuthenticationSession | undefined = await extensionApi.authentication.getSession(
'redhat.authentication-provider',
[
'api.iam.registry_service_accounts', //scope that gives access to hydra service accounts API
'api.console', // scope that gives access to console.redhat.com APIs
'id.username',
], // adds claim to accessToken that used to render account label
{ createIfNone: true }, // will request to login in browser if session does not exists
);
if (authSession) {
const client = new AccountManagementClient({
BASE: 'https://api.openshift.com',
TOKEN: authSession.accessToken,
});
const accessTokenCfg = await client.default.postApiAccountsMgmtV1AccessToken();
pullSecret = JSON.stringify(accessTokenCfg);
}
if (!pullSecret) {
// ask for text in field
pullSecret = await extensionApi.window.showInputBox({
prompt: 'Provide a pull secret',
markdownDescription:
'To pull container images from the registry, a *pull secret* is necessary. You can get a pull secret from the [Red Hat OpenShift Local download page](https://console.redhat.com/openshift/create/local?sc_cid=7013a000003SUmqAAG). Use the *"Copy pull secret"* option and paste the content into the field above',
ignoreFocusOut: true,
});
}

if (!pullSecret) {
return false;
Expand Down
Loading

0 comments on commit e568606

Please sign in to comment.