diff --git a/package-lock.json b/package-lock.json index 2c445fc..42f1f00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -261,6 +261,12 @@ "@types/node": "*" } }, + "@types/url-join": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/url-join/-/url-join-4.0.0.tgz", + "integrity": "sha512-awrJu8yML4E/xTwr2EMatC+HBnHGoDxc2+ImA9QyeUELI1S7dOCIZcyjki1rkwoA8P2D2NVgLAJLjnclkdLtAw==", + "dev": true + }, "@types/vscode": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.52.0.tgz", @@ -5130,6 +5136,11 @@ } } }, + "url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" + }, "url-parse-lax": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", diff --git a/package.json b/package.json index 156c2b0..26a82e3 100644 --- a/package.json +++ b/package.json @@ -242,7 +242,6 @@ "category": "Kubernetes: k3d", "title": "Delete a Server node" } - ], "keybindings": [ { @@ -325,6 +324,7 @@ "@types/request-promise-native": "^1.0.17", "@types/shelljs": "^0.8.3", "@types/tmp": "0.0.33", + "@types/url-join": "^4.0.0", "@types/vscode": "^1.44.0", "ts-loader": "^6.0.4", "tslint": "^5.8.0", @@ -346,6 +346,7 @@ "shelljs": "^0.8.3", "spawn-rx": "^3.0.0", "tmp": "^0.0.33", + "url-join": "^4.0.1", "vscode-azureextensionui": "^0.38.2", "vscode-kubernetes-tools-api": "^1.0.0" }, @@ -356,4 +357,4 @@ "bugs": { "url": "https://github.com/inercia/vscode-k3d/issues" } -} \ No newline at end of file +} diff --git a/src/utils/registry.ts b/src/utils/registry.ts index 2546a64..96aa2c5 100644 --- a/src/utils/registry.ts +++ b/src/utils/registry.ts @@ -1,10 +1,11 @@ import { workspace } from "vscode"; import { Response } from "request"; import * as request from 'request-promise-native'; -import { URL } from "url"; import { Errorable } from '../utils/errorable'; +const urljoin = require('url-join'); + // maximum number of tags to return const MAX_TAGS_RESULTS = 12; @@ -54,9 +55,13 @@ function ITagCompare(a: ITag, b: ITag): number { export async function registryTagsForImage(registry: string, namespace: string, repoName: string, regex?: RegExp, arch?: string, limit: number = MAX_TAGS_RESULTS): Promise> { + if (!registry.startsWith("http")) { + registry = `https://${registry}`; + } + let res: ITag[] = []; - const urlInit = new URL(`${registry}/v2/repositories/${namespace}/${repoName}/tags`); - let url: string = urlInit.toString(); + + let url: string = urljoin(registry, "v2", "repositories", namespace, repoName, "tags").toString(); while (true) { let response = await registryRequest('GET', url.toString()); // TODO: we should check the response errors