Skip to content

Commit 706d23c

Browse files
committed
fix: request login to get pull-secret, fallback for input if canceled
Signed-off-by: Denis Golovin <[email protected]>
1 parent e45ded3 commit 706d23c

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

src/crc-start.ts

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -93,40 +93,30 @@ export async function startCrc(
9393

9494
async function askAndStorePullSecret(logger: extensionApi.Logger): Promise<boolean> {
9595
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',
96+
const authSession: extensionApi.AuthenticationSession | undefined = await extensionApi.authentication.getSession(
97+
'redhat.authentication-provider',
98+
[
99+
'api.iam.registry_service_accounts', //scope that gives access to hydra service accounts API
100+
'api.console', // scope that gives access to console.redhat.com APIs
101+
'id.username',
102+
], // adds claim to accessToken that used to render account label
103+
{ createIfNone: true }, // will request to login in browser if session does not exists
100104
);
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;
105+
if (authSession) {
106+
const client = new AccountManagementClient({
107+
BASE: 'https://api.openshift.com',
108+
TOKEN: authSession.accessToken,
109+
});
110+
const accessTokenCfg = await client.default.postApiAccountsMgmtV1AccessToken();
111+
pullSecret = JSON.stringify(accessTokenCfg);
112+
}
113+
if (!pullSecret) { // ask for text in field
114+
pullSecret = await extensionApi.window.showInputBox({
115+
prompt: 'Provide a pull secret',
116+
markdownDescription:
117+
'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',
118+
ignoreFocusOut: true,
119+
});
130120
}
131121

132122
if (!pullSecret) {

0 commit comments

Comments
 (0)