Skip to content

Commit e45ded3

Browse files
committed
feat: retrieve pull-sectret using Red Hat SSO account
Signed-off-by: Denis Golovin <[email protected]>
1 parent 12bba3d commit e45ded3

File tree

3 files changed

+272
-1042
lines changed

3 files changed

+272
-1042
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
"desk:run": "ts-node-esm ./scripts/run.mts run",
7070
"test": "vitest run --coverage --passWithNoTests"
7171
},
72-
"dependencies": {},
72+
"dependencies": {
73+
"@redhat-developer/rhaccm-client": "^0.0.1"
74+
},
7375
"devDependencies": {
7476
"@podman-desktop/api": "next",
7577
"@rollup/plugin-commonjs": "^24.0.1",
@@ -94,5 +96,8 @@
9496
"vitest": "^1.6.0",
9597
"which": "^3.0.0",
9698
"zip-local": "^0.3.5"
97-
}
99+
},
100+
"extensionDependencies": [
101+
"redhat.redhat-authentication"
102+
]
98103
}

src/crc-start.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { crcStatus } from './crc-status';
2222
import { commander } from './daemon-commander';
2323
import { crcLogProvider } from './log-provider';
2424
import { productName } from './util';
25+
import { AccountManagementClient } from '@redhat-developer/rhaccm-client';
2526

2627
interface ImagePullSecret {
2728
auths: Auths;
@@ -91,12 +92,42 @@ export async function startCrc(
9192
}
9293

9394
async function askAndStorePullSecret(logger: extensionApi.Logger): Promise<boolean> {
94-
const pullSecret = await extensionApi.window.showInputBox({
95-
prompt: 'Provide a pull secret',
96-
markdownDescription:
97-
'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',
98-
ignoreFocusOut: true,
99-
});
95+
let pullSecret: string;
96+
const howToPull = await extensionApi.window.showInformationMessage(
97+
'To pull container images from the registry, a *pull secret* is necessary. You can login into your Red Hat SSO account to get it configured automatically or manually copy it from browser and paste when requested.',
98+
'Sign in with Red Hat SSO',
99+
'Configure manually',
100+
);
101+
if (howToPull) {
102+
if (howToPull === 'Use Red Hat SSO Account') {
103+
const authSession: extensionApi.AuthenticationSession | undefined = await extensionApi.authentication.getSession(
104+
'redhat.authentication-provider',
105+
[
106+
'api.iam.registry_service_accounts', //scope that gives access to hydra service accounts API
107+
'api.console', // scope that gives access to console.redhat.com APIs
108+
'id.username',
109+
], // adds claim to accessToken that used to render account label
110+
{ createIfNone: true }, // will request to login in browser if session does not exists
111+
);
112+
if (authSession) {
113+
const client = new AccountManagementClient({
114+
BASE: 'https://api.openshift.com',
115+
TOKEN: authSession.accessToken,
116+
});
117+
const accessTokenCfg = await client.default.postApiAccountsMgmtV1AccessToken();
118+
pullSecret = JSON.stringify(accessTokenCfg);
119+
}
120+
} else {
121+
pullSecret = await extensionApi.window.showInputBox({
122+
prompt: 'Provide a pull secret',
123+
markdownDescription:
124+
'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',
125+
ignoreFocusOut: true,
126+
});
127+
}
128+
} else {
129+
return false;
130+
}
100131

101132
if (!pullSecret) {
102133
return false;

0 commit comments

Comments
 (0)