forked from microsoft/vscode-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Julia/delete image #29
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
de90f8c
first fully functional version of delete through input bar AND right …
julialieberman 6cadf53
refactored code to make it prettier!
julialieberman 52af8cd
comments
julialieberman 0963084
comments, added subscription function
julialieberman 459e9a7
fixed to style guide
julialieberman 1a2d16f
style fixes, refactoring
julialieberman 8cdb747
delete image after reviews
julialieberman 6fdd94e
One last little change to delete image
julialieberman 20a73ab
moved repository, azureimage, and getsubscriptions to the correct pla…
julialieberman d4dfb37
changes from PR reviews on delete image
julialieberman cb0d992
fixed authentication issue, got rid of azureAccount property for repo…
julialieberman ca9620b
minor fixes deleteImage
julialieberman 92dd859
delete a parentheses
julialieberman 86a5b6e
Merge branch 'dev' into Julia/deleteImage
julialieberman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use const when items are not changed |
||
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' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Const |
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registryRepos would be a more accurate name?