Skip to content

Commit

Permalink
Improved handling of the registry URL
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Saurin <[email protected]>
  • Loading branch information
inercia committed Jan 16, 2021
1 parent 2bf01a7 commit a97798e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@
"category": "Kubernetes: k3d",
"title": "Delete a Server node"
}

],
"keybindings": [
{
Expand Down Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -356,4 +357,4 @@
"bugs": {
"url": "https://github.com/inercia/vscode-k3d/issues"
}
}
}
11 changes: 8 additions & 3 deletions src/utils/registry.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<Errorable<ITag[]>> {

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<ITags>('GET', url.toString());
// TODO: we should check the response errors
Expand Down

0 comments on commit a97798e

Please sign in to comment.