Skip to content
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

Chrisdias/browse azure portal #187

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dockerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import { DockerExplorerProvider } from './explorer/dockerExplorer';
import { removeContainer } from './commands/remove-container';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Middleware, Proposed, ProposedFeatures, DidChangeConfigurationNotification } from 'vscode-languageclient';
import { WebAppCreator } from './explorer/deploy/webAppCreator';
import { AzureImageNode } from './explorer/models/azureRegistryNodes';
import { AzureImageNode, AzureRegistryNode, AzureRepositoryNode } from './explorer/models/azureRegistryNodes';
import { DockerHubImageNode, DockerHubRepositoryNode, DockerHubOrgNode } from './explorer/models/dockerHubNodes';
import { AzureAccountWrapper } from './explorer/deploy/azureAccountWrapper';
import * as util from "./explorer/deploy/util";
import { dockerHubLogout, browseDockerHub } from './explorer/models/dockerHubUtils';
import { dockerHubLogout, browseDockerHub } from './explorer/utils/dockerHubUtils';
import { AzureAccount } from './typings/azure-account.api';
import * as opn from 'opn';
import { DockerDebugConfigProvider } from './configureWorkspace/configDebugProvider';
import { browseAzurePortal } from './explorer/utils/azureUtils';


export const FROM_DIRECTIVE_PATTERN = /^\s*FROM\s*([\w-\/:]*)(\s*AS\s*[a-z][a-z0-9-_\\.]*)?$/i;
Expand Down Expand Up @@ -127,9 +128,13 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.browseDockerHub', async (context?: DockerHubImageNode | DockerHubRepositoryNode | DockerHubOrgNode) => {
browseDockerHub(context);
}));
ctx.subscriptions.push(vscode.commands.registerCommand('vscode-docker.browseAzurePortal', async (context?: AzureRegistryNode | AzureRepositoryNode | AzureImageNode ) => {
browseAzurePortal(context);
}));

ctx.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('docker', new DockerDebugConfigProvider()));


activateLanguageClient(ctx);
}

Expand Down
43 changes: 29 additions & 14 deletions explorer/models/azureRegistryNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as moment from 'moment';
import * as request from 'request-promise';

import * as ContainerModels from '../../node_modules/azure-arm-containerregistry/lib/models';
import { NodeBase } from './nodeBase';
import { SubscriptionClient, ResourceManagementClient, SubscriptionModels } from 'azure-arm-resource';
import { AzureAccount, AzureSession } from '../../typings/azure-account.api';
Expand All @@ -21,10 +21,11 @@ export class AzureRegistryNode extends NodeBase {
this._azureAccount = azureAccount;
}

public type: RegistryType;
public password: string;
public registry: ContainerModels.Registry;
public subscription: SubscriptionModels.Subscription;
public type: RegistryType;
public userName: string;
public password: string;

getTreeItem(): vscode.TreeItem {
return {
Expand Down Expand Up @@ -90,13 +91,15 @@ export class AzureRegistryNode extends NodeBase {
if (body.length > 0) {
const repositories = JSON.parse(body).repositories;
for (let i = 0; i < repositories.length; i++) {
node = new AzureRepositoryNode(repositories[i], "azureRepository");
node.repository = element.label;
node.subscription = element.subscription;
node = new AzureRepositoryNode(repositories[i], "azureRepositoryNode");
node.accessTokenARC = accessTokenARC;
node.azureAccount = element.azureAccount;
node.password = element.password;
node.refreshTokenARC = refreshTokenARC;
node.registry = element.registry;
node.repository = element.label;
node.subscription = element.subscription;
node.userName = element.userName;
node.password = element.password;
repoNodes.push(node);
}
}
Expand All @@ -107,6 +110,8 @@ export class AzureRegistryNode extends NodeBase {
}
}



export class AzureRepositoryNode extends NodeBase {

constructor(
Expand All @@ -120,12 +125,14 @@ export class AzureRepositoryNode extends NodeBase {
super(label);
}

public repository: string;
public subscription: any;
public accessTokenARC: string;
public azureAccount: AzureAccount
public password: string;
public refreshTokenARC: string;
public registry: ContainerModels.Registry;
public repository: string;
public subscription: SubscriptionModels.Subscription;
public userName: string;
public password: string;

getTreeItem(): vscode.TreeItem {
return {
Expand All @@ -144,7 +151,9 @@ export class AzureRepositoryNode extends NodeBase {
let accessTokenARC;
let tags;

const { accessToken, refreshToken } = await acquireToken(element.subscription.session);
const tenantId: string = element.subscription.tenantId;
const session: AzureSession = element.azureAccount.sessions.find((s, i, array) => s.tenantId.toLowerCase() === tenantId.toLowerCase());
const { accessToken, refreshToken } = await acquireToken(session);

if (accessToken && refreshToken) {
const tenantId = element.subscription.tenantId;
Expand Down Expand Up @@ -198,10 +207,13 @@ export class AzureRepositoryNode extends NodeBase {
}));
created = moment(new Date(JSON.parse(manifest.history[0].v1Compatibility).created)).fromNow();

node = new AzureImageNode(`${element.label}:${tags[i]} (${created})`, 'azureImageTag');
node = new AzureImageNode(`${element.label}:${tags[i]} (${created})`, 'azureImageNode');
node.azureAccount = element.azureAccount;
node.password = element.password;
node.registry = element.registry;
node.serverUrl = element.repository;
node.subscription = element.subscription;
node.userName = element.userName;
node.password = element.password;
imageNodes.push(node);

}
Expand All @@ -219,9 +231,12 @@ export class AzureImageNode extends NodeBase {
super(label);
}

public azureAccount: AzureAccount
public password: string;
public registry: ContainerModels.Registry;
public serverUrl: string;
public subscription: SubscriptionModels.Subscription;
public userName: string;
public password: string;

getTreeItem(): vscode.TreeItem {
return {
Expand Down
2 changes: 1 addition & 1 deletion explorer/models/containerNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { NodeBase } from './nodeBase';
import { trimWithElipsis } from './utils';
import { trimWithElipsis } from '../utils/utils';

export class ContainerNode extends NodeBase {

Expand Down
2 changes: 1 addition & 1 deletion explorer/models/imageNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as moment from 'moment';
import { NodeBase } from './nodeBase';
import { trimWithElipsis } from './utils';
import { trimWithElipsis } from '../utils/utils';

export class ImageNode extends NodeBase {

Expand Down
3 changes: 2 additions & 1 deletion explorer/models/registryRootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ export class RegistryRootNode extends NodeBase {
light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'Registry_16x.svg'),
dark: path.join(__filename, '..', '..', '..', '..', 'images', 'dark', 'Registry_16x.svg')
};
let node = new AzureRegistryNode(registries[j].loginServer, 'registry', iconPath, this._azureAccount);
let node = new AzureRegistryNode(registries[j].loginServer, 'azureRegistryNode', iconPath, this._azureAccount);
node.type = RegistryType.Azure;
node.password = creds.passwords[0].value;
node.userName = creds.username;
node.subscription = subs[i];
node.registry = registries[j];
azureRegistryNodes.push(node);
}
}
Expand Down
17 changes: 17 additions & 0 deletions explorer/utils/azureUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as opn from 'opn';
import { AzureRepositoryNode, AzureImageNode, AzureRegistryNode } from '../models/azureRegistryNodes';
import { AzureSession } from '../../typings/azure-account.api';

export function browseAzurePortal(context?: AzureRegistryNode | AzureRepositoryNode | AzureImageNode ): void {

if (context) {
const tenantId: string = context.subscription.tenantId;
const session: AzureSession = context.azureAccount.sessions.find((s, i, array) => s.tenantId.toLowerCase() === tenantId.toLowerCase());
let url: string = `${session.environment.portalUrl}/${tenantId}/#resource${context.registry.id}`;
if (context.contextValue === 'azureImageNode' || context.contextValue === 'azureRepositoryNode') {
url = `${url}/repository`;
}
opn(url);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import * as keytarType from 'keytar';
import * as opn from 'opn';
import request = require('request-promise');
import { DockerHubRepositoryNode, DockerHubImageNode, DockerHubOrgNode } from './dockerHubNodes';
import { DockerHubRepositoryNode, DockerHubImageNode, DockerHubOrgNode } from '../models/dockerHubNodes';

let _token: Token;

Expand Down
File renamed without changes.
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"onCommand:vscode-docker.system.prune",
"onCommand:vscode-docker.dockerHubLogout",
"onCommand:vscode-docker.browseDockerHub",
"onCommand:vscode-docker.browseAzurePortal",
"onView:dockerExplorer",
"onDebug"
],
Expand Down Expand Up @@ -193,7 +194,7 @@
},
{
"command": "vscode-docker.createWebApp",
"when": "view == dockerExplorer && viewItem == azureImageTag"
"when": "view == dockerExplorer && viewItem == azureImageNode"
},
{
"command": "vscode-docker.createWebApp",
Expand All @@ -214,6 +215,18 @@
{
"command": "vscode-docker.browseDockerHub",
"when": "view == dockerExplorer && viewItem == dockerHubNamespace"
},
{
"command": "vscode-docker.browseAzurePortal",
"when": "view == dockerExplorer && viewItem == azureRegistryNode"
},
{
"command": "vscode-docker.browseAzurePortal",
"when": "view == dockerExplorer && viewItem == azureRepositoryNode"
},
{
"command": "vscode-docker.browseAzurePortal",
"when": "view == dockerExplorer && viewItem == azureImageNode"
}
]
},
Expand Down Expand Up @@ -514,6 +527,11 @@
"command": "vscode-docker.browseDockerHub",
"title": "Browse in DockerHub",
"category": "Docker"
},
{
"command": "vscode-docker.browseAzurePortal",
"title": "Browse in the Azure Portal",
"category": "Docker"
}
],
"views": {
Expand Down