diff --git a/.eslintrc.json b/.eslintrc.json index 9c549edf..e2dcf579 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,9 @@ "ecmaVersion": 2022 }, "extends": "airbnb-base", + "parserOptions": { + "ecmaVersion": 2020 + }, "rules": { "no-underscore-dangle": [ 0 diff --git a/package-lock.json b/package-lock.json index afb72fff..21e8c4f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -690,17 +690,46 @@ "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" } }, + "node_modules/@hapi/address": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@hapi/address/-/address-5.1.0.tgz", + "integrity": "sha512-b/OicomrGhG+aRgAhtxqOArHDH7kE2sY0IQ5MwIU6EkzUIOmsfi4YfYPZxGSauHLgVzcwk2rseCi7fjeMpQh+w==", + "dependencies": { + "@hapi/hoek": "^11.0.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@hapi/formula": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@hapi/formula/-/formula-3.0.2.tgz", + "integrity": "sha512-hY5YPNXzw1He7s0iqkRQi+uMGh383CGdyyIGYtB+W5N3KHPXoqychklvHhKCC9M3Xtv0OCs/IHw+r4dcHtBYWw==" + }, "node_modules/@hapi/hoek": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", - "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==" + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-11.0.2.tgz", + "integrity": "sha512-aKmlCO57XFZ26wso4rJsW4oTUnrgTFw2jh3io7CAtO9w4UltBNwRXvXIVzzyfkaaLRo3nluP/19msA8vDUUuKw==" + }, + "node_modules/@hapi/pinpoint": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@hapi/pinpoint/-/pinpoint-2.0.1.tgz", + "integrity": "sha512-EKQmr16tM8s16vTT3cA5L0kZZcTMU5DUOZTuvpnY738m+jyP3JIUj+Mm1xc1rsLkGBQ/gVnfKYPwOmPg1tUR4Q==" + }, + "node_modules/@hapi/tlds": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@hapi/tlds/-/tlds-1.0.1.tgz", + "integrity": "sha512-OXs5OliWsLTmvzQKZtb3KhfEz30WuuaizwAn95GLfeK+JpGnBxR55lALv3kA4T1RRb3wlrNjnboBg6ur1Czvig==", + "engines": { + "node": ">=14.0.0" + } }, "node_modules/@hapi/topo": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", - "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-6.0.1.tgz", + "integrity": "sha512-JioWUZL1Bm7r8bnCDx2AUggiPwpV7djFfDTWT1aZSyHjN++fVz7XPdW8YVCxvyv9bSWcbbOLV/h4U1zGdwrN3w==", "dependencies": { - "@hapi/hoek": "^9.0.0" + "@hapi/hoek": "^11.0.2" } }, "node_modules/@humanwhocodes/config-array": { @@ -882,24 +911,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/@sideway/address": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", - "integrity": "sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==", - "dependencies": { - "@hapi/hoek": "^9.0.0" - } - }, - "node_modules/@sideway/formula": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz", - "integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==" - }, - "node_modules/@sideway/pinpoint": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", - "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==" - }, "node_modules/@sindresorhus/is": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-5.3.0.tgz", @@ -8071,17 +8082,40 @@ "integrity": "sha512-9anpBMM9mEgZN4wr2v8wHJI2/u5TnnggewRN6OlvXTTnuVyoY19X6rOv9XTqKRw6dcGKwZsBi8n0kDE2I5i4VA==", "requires": {} }, + "@hapi/address": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@hapi/address/-/address-5.1.0.tgz", + "integrity": "sha512-b/OicomrGhG+aRgAhtxqOArHDH7kE2sY0IQ5MwIU6EkzUIOmsfi4YfYPZxGSauHLgVzcwk2rseCi7fjeMpQh+w==", + "requires": { + "@hapi/hoek": "^11.0.2" + } + }, + "@hapi/formula": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@hapi/formula/-/formula-3.0.2.tgz", + "integrity": "sha512-hY5YPNXzw1He7s0iqkRQi+uMGh383CGdyyIGYtB+W5N3KHPXoqychklvHhKCC9M3Xtv0OCs/IHw+r4dcHtBYWw==" + }, "@hapi/hoek": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", - "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==" + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-11.0.2.tgz", + "integrity": "sha512-aKmlCO57XFZ26wso4rJsW4oTUnrgTFw2jh3io7CAtO9w4UltBNwRXvXIVzzyfkaaLRo3nluP/19msA8vDUUuKw==" + }, + "@hapi/pinpoint": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@hapi/pinpoint/-/pinpoint-2.0.1.tgz", + "integrity": "sha512-EKQmr16tM8s16vTT3cA5L0kZZcTMU5DUOZTuvpnY738m+jyP3JIUj+Mm1xc1rsLkGBQ/gVnfKYPwOmPg1tUR4Q==" + }, + "@hapi/tlds": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@hapi/tlds/-/tlds-1.0.1.tgz", + "integrity": "sha512-OXs5OliWsLTmvzQKZtb3KhfEz30WuuaizwAn95GLfeK+JpGnBxR55lALv3kA4T1RRb3wlrNjnboBg6ur1Czvig==" }, "@hapi/topo": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", - "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-6.0.1.tgz", + "integrity": "sha512-JioWUZL1Bm7r8bnCDx2AUggiPwpV7djFfDTWT1aZSyHjN++fVz7XPdW8YVCxvyv9bSWcbbOLV/h4U1zGdwrN3w==", "requires": { - "@hapi/hoek": "^9.0.0" + "@hapi/hoek": "^11.0.2" } }, "@humanwhocodes/config-array": { diff --git a/src/commands/docker.js b/src/commands/docker.js index 9030ded5..2e1c7ca6 100644 --- a/src/commands/docker.js +++ b/src/commands/docker.js @@ -1,7 +1,3 @@ -import debugSetup from 'debug'; -import URL from 'url-parse'; -import { printSuccess, printError, callMe } from './utils.js'; -import { generateJwt, loadProfile } from '../config.js'; /* * Copyright 2023 Cognitive Scale, Inc. All Rights Reserved. * @@ -17,7 +13,12 @@ import { generateJwt, loadProfile } from '../config.js'; * See the License for the specific language governing permissions and * limitations under the License. */ +import debugSetup from 'debug'; +import URL from 'url-parse'; +import { printSuccess, printError, callMe } from './utils.js'; +import { generateJwt, loadProfile } from '../config.js'; const debug = debugSetup('cortex:cli'); + export default class DockerLoginCommand { constructor(program) { this.program = program; @@ -27,8 +28,13 @@ export default class DockerLoginCommand { const profile = await loadProfile(options.profile); const ttl = options.ttl || '14d'; try { - // TODO fetch this from new endpoint or maybe store this in the profile?? - const registryUrl = (new URL(profile.url)).hostname.replace('api', 'private-registry'); + // First try to see if we have of registries from /v4/info, grab the first one with isCortex == true + let registryUrl = Object.values(profile?.registries ?? {}).find((v) => v?.isCortex === true)?.url; + // If not found try to guess the url, assuming our recommended install api. and private-registry. + if (registryUrl === undefined) { + registryUrl = (new URL(profile.url)).hostname.replace('api', 'private-registry'); + printWarning(`Using default docker registry url: ${registryUrl}`); + } const jwt = await generateJwt(profile, ttl); const command = `docker login -u cli --password ${jwt} ${registryUrl}`; debug('%s.executeDockerLogin(%s)', profile.name, command);