forked from microsoft/vscode-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first fully functional version of delete through input bar AND right click * refactored code to make it prettier! * comments * comments, added subscription function * fixed to style guide * style fixes, refactoring * delete image after reviews put my functions from azureCredentialsManager into two new files: utils/azure/acrTools.ts, and commands/utils/quick-pick-azure.ts Edited code based on Esteban's and Bin's reviews * One last little change to delete image * moved repository, azureimage, and getsubscriptions to the correct places within deleteImage * changes from PR reviews on delete image * fixed authentication issue, got rid of azureAccount property for repository and image **on constructor for repository, azurecredentialsmanager was being recreated and thus couldn't find the azureAccount. For this reason, I got rid of the azureAccount property of the classes Repository and AzureImage. This bug may lead to future problems (Esteban and I couldn't see why it was happening) * minor fixes deleteImage * delete a parentheses
- Loading branch information
1 parent
37d8a27
commit b80af87
Showing
8 changed files
with
482 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Registry } from "azure-arm-containerregistry/lib/models"; | ||
import { SubscriptionModels } from 'azure-arm-resource'; | ||
import * as vscode from "vscode"; | ||
import { AzureImageNode } from '../../explorer/models/AzureRegistryNodes'; | ||
import { Repository } from "../../utils/Azure/models/repository"; | ||
import { AzureCredentialsManager } from '../../utils/azureCredentialsManager'; | ||
const teleCmdId: string = 'vscode-docker.deleteAzureImage'; | ||
import * as quickPicks from '../../commands/utils/quick-pick-azure'; | ||
import * as acrTools from '../../utils/Azure/acrTools'; | ||
|
||
/** | ||
* function to delete an Azure repository and its associated images | ||
* @param context : if called through right click on AzureRepositoryNode, the node object will be passed in. See azureRegistryNodes.ts for more info | ||
*/ | ||
export async function deleteAzureImage(context?: AzureImageNode): Promise<void> { | ||
if (!AzureCredentialsManager.getInstance().isLoggedIn()) { | ||
vscode.window.showErrorMessage('You are not logged into Azure'); | ||
return; | ||
} | ||
let registry: Registry; | ||
let subscription: SubscriptionModels.Subscription; | ||
let repoName: string; | ||
let username: string; | ||
let password: string; | ||
let tag: string; | ||
if (!context) { | ||
registry = await quickPicks.quickPickACRRegistry(); | ||
subscription = acrTools.getRegistrySubscription(registry); | ||
let repository: Repository = await quickPicks.quickPickACRRepository(registry); | ||
repoName = repository.name; | ||
const image = await quickPicks.quickPickACRImage(repository); | ||
tag = image.tag; | ||
} | ||
|
||
//ensure user truly wants to delete image | ||
let opt: vscode.InputBoxOptions = { | ||
ignoreFocusOut: true, | ||
placeHolder: 'No', | ||
value: 'No', | ||
prompt: 'Are you sure you want to delete this image? Enter Yes to continue: ' | ||
}; | ||
let answer = await vscode.window.showInputBox(opt); | ||
answer = answer.toLowerCase(); | ||
if (answer !== 'yes') { return; } | ||
|
||
if (context) { | ||
repoName = context.label; | ||
subscription = context.subscription; | ||
registry = context.registry; | ||
let wholeName = repoName.split(':'); | ||
repoName = wholeName[0]; | ||
tag = wholeName[1]; | ||
} | ||
|
||
let creds = await acrTools.loginCredentials(subscription, registry); | ||
username = creds.username; | ||
password = creds.password; | ||
let path = `/v2/_acr/${repoName}/tags/${tag}`; | ||
await acrTools.requestDataFromRegistry('delete', registry.loginServer, path, username, password); //official call to delete the image | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ContainerRegistryManagementClient } from 'azure-arm-containerregistry'; | ||
import { Registry } from 'azure-arm-containerregistry/lib/models'; | ||
import * as vscode from "vscode"; | ||
import * as acrTools from '../../utils/Azure/acrTools'; | ||
import { AzureImage } from "../../utils/Azure/models/image"; | ||
import { Repository } from "../../utils/Azure/models/Repository"; | ||
import { AzureCredentialsManager } from '../../utils/azureCredentialsManager'; | ||
|
||
/** | ||
* function to allow user to pick a desired image for use | ||
* @param repository the repository to look in | ||
* @returns an AzureImage object (see azureUtils.ts) | ||
*/ | ||
export async function quickPickACRImage(repository: Repository): Promise<AzureImage> { | ||
const repoImages: AzureImage[] = await acrTools.getAzureImages(repository); | ||
let imageListNames: string[] = []; | ||
for (let tempImage of repoImages) { | ||
imageListNames.push(tempImage.tag); | ||
} | ||
let desiredImage = await vscode.window.showQuickPick(imageListNames, { 'canPickMany': false, 'placeHolder': 'Choose the image you want to delete' }); | ||
if (!desiredImage) { return; } | ||
const image = repoImages.find((myImage): boolean => { return desiredImage === myImage.tag }); | ||
return image; | ||
} | ||
|
||
/** | ||
* function to allow user to pick a desired repository for use | ||
* @param registry the registry to choose a repository from | ||
* @returns a Repository object (see azureUtils.ts) | ||
*/ | ||
export async function quickPickACRRepository(registry: Registry): Promise<Repository> { | ||
const myRepos: Repository[] = await acrTools.getAzureRepositories(registry); | ||
let rep: string[] = []; | ||
for (let repo of myRepos) { | ||
rep.push(repo.name); | ||
} | ||
let desiredRepo = await vscode.window.showQuickPick(rep, { 'canPickMany': false, 'placeHolder': 'Choose the repository from which your desired image exists' }); | ||
if (!desiredRepo) { return; } | ||
const repository = myRepos.find((currentRepo): boolean => { return desiredRepo === currentRepo.name }); | ||
return repository; | ||
} | ||
|
||
/** | ||
* function to let user choose a registry for use | ||
* @returns a Registry object | ||
*/ | ||
export async function quickPickACRRegistry(): Promise<Registry> { | ||
//first get desired registry | ||
let registries = await AzureCredentialsManager.getInstance().getRegistries(); | ||
let reg: string[] = []; | ||
for (let registryName of registries) { | ||
reg.push(registryName.name); | ||
} | ||
let desired = await vscode.window.showQuickPick(reg, { 'canPickMany': false, 'placeHolder': 'Choose the Registry from which your desired image exists' }); | ||
if (!desired) { return; } | ||
const registry = registries.find((currentReg): boolean => { return desired === currentReg.name }); | ||
return registry; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.