Skip to content

Commit 585bd33

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

File tree

3 files changed

+109
-8
lines changed

3 files changed

+109
-8
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
"desk:prepare": "ts-node-esm ./scripts/run.mts prepare",
6969
"desk:run": "ts-node-esm ./scripts/run.mts run"
7070
},
71-
"dependencies": {},
71+
"dependencies": {
72+
"@redhat-developer/rhaccm-client": "^0.0.1"
73+
},
7274
"devDependencies": {
7375
"7zip-min": "^1.4.4",
7476
"@podman-desktop/api": "next",
@@ -91,5 +93,8 @@
9193
"typescript": "^4.9.5",
9294
"which": "^3.0.0",
9395
"zip-local": "^0.3.5"
94-
}
96+
},
97+
"extensionDependencies": [
98+
"redhat.redhat-authentication"
99+
]
95100
}

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;

yarn.lock

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@
121121
resolved "https://registry.yarnpkg.com/@podman-desktop/api/-/api-0.0.202307181956-83816f5.tgz#5906cb7e6e46667791d03e0d0ff764cbda6f3479"
122122
integrity sha512-53rLR1pVfcfSAm9DxyMA7rJoiQP5Mn6qjacM8xBfqXx2lN4zPlJXrrXYMMPVxdN8HjmVBd9Fw2lm+yC7tOW1Ig==
123123

124+
"@redhat-developer/rhaccm-client@^0.0.1":
125+
version "0.0.1"
126+
resolved "https://registry.yarnpkg.com/@redhat-developer/rhaccm-client/-/rhaccm-client-0.0.1.tgz#95f2e3a6a4d92658463ed9017dc22655faa528d5"
127+
integrity sha512-xkfm5HtYy1CqErb/1/rXivrM7i6EwH0GWvM1KcT5x3aqSuwWRfK/yXKXYKCGcx1XfR8XU1lGnvH66M8jsmgHXQ==
128+
dependencies:
129+
axios "^1.6.7"
130+
form-data "^4.0.0"
131+
124132
"@rollup/plugin-commonjs@^24.0.1":
125133
version "24.1.0"
126134
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz#79e54bd83bb64396761431eee6c44152ef322100"
@@ -372,6 +380,20 @@ async@^1.4.2:
372380
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
373381
integrity sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==
374382

383+
asynckit@^0.4.0:
384+
version "0.4.0"
385+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
386+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
387+
388+
axios@^1.6.7:
389+
version "1.6.8"
390+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66"
391+
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==
392+
dependencies:
393+
follow-redirects "^1.15.6"
394+
form-data "^4.0.0"
395+
proxy-from-env "^1.1.0"
396+
375397
balanced-match@^1.0.0:
376398
version "1.0.2"
377399
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
@@ -447,6 +469,13 @@ color-name@~1.1.4:
447469
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
448470
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
449471

472+
combined-stream@^1.0.8:
473+
version "1.0.8"
474+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
475+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
476+
dependencies:
477+
delayed-stream "~1.0.0"
478+
450479
commondir@^1.0.1:
451480
version "1.0.1"
452481
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
@@ -505,6 +534,11 @@ defer-to-connect@^2.0.1:
505534
resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-2.0.1.tgz#8016bdb4143e4632b77a3449c6236277de520587"
506535
integrity sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==
507536

537+
delayed-stream@~1.0.0:
538+
version "1.0.0"
539+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
540+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
541+
508542
diff@^4.0.1:
509543
version "4.0.2"
510544
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
@@ -704,11 +738,25 @@ flatted@^3.1.0:
704738
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
705739
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==
706740

741+
follow-redirects@^1.15.6:
742+
version "1.15.6"
743+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
744+
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==
745+
707746
form-data-encoder@^2.1.2:
708747
version "2.1.4"
709748
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-2.1.4.tgz#261ea35d2a70d48d30ec7a9603130fa5515e9cd5"
710749
integrity sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==
711750

751+
form-data@^4.0.0:
752+
version "4.0.0"
753+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
754+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
755+
dependencies:
756+
asynckit "^0.4.0"
757+
combined-stream "^1.0.8"
758+
mime-types "^2.1.12"
759+
712760
fs.realpath@^1.0.0:
713761
version "1.0.0"
714762
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1027,6 +1075,18 @@ micromatch@^4.0.4:
10271075
braces "^3.0.2"
10281076
picomatch "^2.3.1"
10291077

1078+
1079+
version "1.52.0"
1080+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
1081+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
1082+
1083+
mime-types@^2.1.12:
1084+
version "2.1.35"
1085+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
1086+
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
1087+
dependencies:
1088+
mime-db "1.52.0"
1089+
10301090
mimic-response@^3.1.0:
10311091
version "3.1.0"
10321092
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9"
@@ -1166,6 +1226,11 @@ prettier@^2.8.4:
11661226
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
11671227
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
11681228

1229+
proxy-from-env@^1.1.0:
1230+
version "1.1.0"
1231+
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
1232+
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
1233+
11691234
punycode@^2.1.0:
11701235
version "2.3.0"
11711236
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f"

0 commit comments

Comments
 (0)