From 47a5cd68dbdff9ab346fec802842c40927cf7a7f Mon Sep 17 00:00:00 2001 From: alexyaang <59073590+alexyaang@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:41:40 -0400 Subject: [PATCH 1/6] added github registry context value --- .../src/clients/GitHub/GitHubRegistryDataProvider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts index 3b4d9835..3de3f65b 100644 --- a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts +++ b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts @@ -74,6 +74,7 @@ export class GitHubRegistryDataProvider extends RegistryV2DataProvider { baseUrl: GitHubContainerRegistryUri, label: org, type: 'commonregistry', + additionalContextValues: ['githubRegistry'] } )); } From bf1310d0013a6e8af6e78dde0b30e9ec37472d0d Mon Sep 17 00:00:00 2001 From: alexyaang <59073590+alexyaang@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:55:31 -0400 Subject: [PATCH 2/6] refined github secret prompt --- .../src/clients/GitHub/GitHubRegistryDataProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts index 3de3f65b..827bda51 100644 --- a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts +++ b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts @@ -40,7 +40,7 @@ export class GitHubRegistryDataProvider extends RegistryV2DataProvider { public async onConnect(): Promise { const wizardContext: RegistryWizardContext = { usernamePrompt: vscode.l10n.t('GitHub Username'), - secretPrompt: vscode.l10n.t('GitHub Personal Access Token (requires `repo` scope for read-only operations)'), // TODO: add scope for write + secretPrompt: vscode.l10n.t('GitHub Personal Access Token (requires `repo` and `write:packages` scopes)'), }; const wizard = new RegistryWizard( From 8bd33e9da482cf300fcba4b43f82dfe6819a02f5 Mon Sep 17 00:00:00 2001 From: alexyaang <59073590+alexyaang@users.noreply.github.com> Date: Thu, 24 Aug 2023 17:33:11 -0400 Subject: [PATCH 3/6] saving delete tag progress --- .../GitHub/GitHubRegistryDataProvider.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts index 827bda51..2ca8c158 100644 --- a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts +++ b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts @@ -15,6 +15,7 @@ import { RegistryWizardSecretPromptStep, RegistryWizardUsernamePromptStep } from import { BasicCredentials } from '../../contracts/BasicCredentials'; const GitHubContainerRegistryUri = vscode.Uri.parse('https://ghcr.io'); +const GitHubApiUri = vscode.Uri.parse('https://api.github.com'); interface Config { digest: string; @@ -131,6 +132,28 @@ export class GitHubRegistryDataProvider extends RegistryV2DataProvider { return tagsWithAdditionalContext; } + public async deleteTag(item: V2Tag): Promise { + const results: string[] = []; + + const creds = await this.authenticationProvider.getBasicCredentials(); + results.push(creds.username); + // user/packages/{package_type}/{package_name}/versions/{package_version_id} + const requestUrl = vscode.Uri.parse('https://api.github.com/user/packages/docker'); + const response = await httpRequest<{ login: string }[]>(requestUrl.toString(), { + method: 'DELETE', + headers: { + 'Accept': 'application/vnd.github+json', + // eslint-disable-next-line @typescript-eslint/naming-convention + 'X-GitHub-Api-Version': '2022-11-28', + 'Authorization': `Bearer ${creds.secret}` + } + }); + + for (const org of await response.json()) { + results.push(org.login); + } + } + protected getAuthenticationProvider(item: V2RegistryItem): AuthenticationProvider { return this.authenticationProvider; } From a5b2aed29166f6efaf888f7e9efa3e1045e09d9c Mon Sep 17 00:00:00 2001 From: alexyaang <59073590+alexyaang@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:40:32 -0400 Subject: [PATCH 4/6] scrap delete tag logic --- .../GitHub/GitHubRegistryDataProvider.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts index 2ca8c158..fbf205ea 100644 --- a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts +++ b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts @@ -132,28 +132,6 @@ export class GitHubRegistryDataProvider extends RegistryV2DataProvider { return tagsWithAdditionalContext; } - public async deleteTag(item: V2Tag): Promise { - const results: string[] = []; - - const creds = await this.authenticationProvider.getBasicCredentials(); - results.push(creds.username); - // user/packages/{package_type}/{package_name}/versions/{package_version_id} - const requestUrl = vscode.Uri.parse('https://api.github.com/user/packages/docker'); - const response = await httpRequest<{ login: string }[]>(requestUrl.toString(), { - method: 'DELETE', - headers: { - 'Accept': 'application/vnd.github+json', - // eslint-disable-next-line @typescript-eslint/naming-convention - 'X-GitHub-Api-Version': '2022-11-28', - 'Authorization': `Bearer ${creds.secret}` - } - }); - - for (const org of await response.json()) { - results.push(org.login); - } - } - protected getAuthenticationProvider(item: V2RegistryItem): AuthenticationProvider { return this.authenticationProvider; } From badfbcd480268675a0bb67be34fc75a96b52f325 Mon Sep 17 00:00:00 2001 From: alexyaang <59073590+alexyaang@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:41:25 -0400 Subject: [PATCH 5/6] nit --- .../src/clients/GitHub/GitHubRegistryDataProvider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts index fbf205ea..827bda51 100644 --- a/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts +++ b/packages/vscode-docker-registries/src/clients/GitHub/GitHubRegistryDataProvider.ts @@ -15,7 +15,6 @@ import { RegistryWizardSecretPromptStep, RegistryWizardUsernamePromptStep } from import { BasicCredentials } from '../../contracts/BasicCredentials'; const GitHubContainerRegistryUri = vscode.Uri.parse('https://ghcr.io'); -const GitHubApiUri = vscode.Uri.parse('https://api.github.com'); interface Config { digest: string; From 576c2ea8bf1b684946b8084c4de46828b0620c2c Mon Sep 17 00:00:00 2001 From: alexyaang <59073590+alexyaang@users.noreply.github.com> Date: Fri, 25 Aug 2023 11:56:25 -0400 Subject: [PATCH 6/6] removed unnecessary headers --- .../clients/Azure/AzureRegistryDataProvider.ts | 16 ---------------- .../clients/RegistryV2/RegistryV2DataProvider.ts | 5 +---- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/packages/vscode-docker-registries-extension/src/clients/Azure/AzureRegistryDataProvider.ts b/packages/vscode-docker-registries-extension/src/clients/Azure/AzureRegistryDataProvider.ts index 7ccc731e..9cacad9e 100644 --- a/packages/vscode-docker-registries-extension/src/clients/Azure/AzureRegistryDataProvider.ts +++ b/packages/vscode-docker-registries-extension/src/clients/Azure/AzureRegistryDataProvider.ts @@ -162,22 +162,6 @@ export class AzureRegistryDataProvider extends RegistryV2DataProvider implements } } - public async deleteTag(item: AzureTag): Promise { - const authenticationProvider = this.getAuthenticationProvider(item.parent.parent as unknown as AzureRegistryItem); - - const reponse = await registryV2Request({ - method: 'DELETE', - registryUri: item.baseUrl, - path: ['v2', '_acr', `${item.parent.label}`, 'tags', `${item.label}`], - scopes: [`repository:${item.parent.label}:delete`], - authenticationProvider: authenticationProvider, - }); - - if (!reponse.succeeded) { - throw new Error(`Failed to delete tag: ${reponse.statusText}`); - } - } - protected override getAuthenticationProvider(item: AzureRegistryItem): ACROAuthProvider { const registryString = item.baseUrl.toString(); diff --git a/packages/vscode-docker-registries/src/clients/RegistryV2/RegistryV2DataProvider.ts b/packages/vscode-docker-registries/src/clients/RegistryV2/RegistryV2DataProvider.ts index f092db22..3b60f3f6 100644 --- a/packages/vscode-docker-registries/src/clients/RegistryV2/RegistryV2DataProvider.ts +++ b/packages/vscode-docker-registries/src/clients/RegistryV2/RegistryV2DataProvider.ts @@ -122,10 +122,7 @@ export abstract class RegistryV2DataProvider extends CommonRegistryDataProvider method: 'DELETE', registryUri: registry.baseUrl, path: ['v2', item.parent.label, 'manifests', digest], - scopes: [`repository:${item.parent.label}:pull`], - headers: { - 'accept': 'application/vnd.docker.distribution.manifest.v2+json' - } + scopes: [`repository:${item.parent.label}:delete`] }); }