Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-p-smith committed Oct 17, 2023
1 parent 5b7afad commit 056244a
Show file tree
Hide file tree
Showing 9 changed files with 10,935 additions and 13,767 deletions.
24,449 changes: 10,746 additions & 13,703 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-apimanagement",
"displayName": "Azure API Management",
"description": "An Azure API Management extension for Visual Studio Code.",
"version": "1.0.8",
"version": "1.0.9",
"publisher": "ms-azuretools",
"icon": "resources/apim-icon-newone.png",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
Expand Down Expand Up @@ -856,6 +856,7 @@
"@azure/ms-rest-js": "^2.7.0",
"@types/fs-extra": "^4.0.3",
"@types/gulp": "^4.0.6",
"@types/js-yaml": "^4.0.7",
"@types/mocha": "^5.2.6",
"@types/node": "^8.10.59",
"@types/request": "^2.48.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import * as yaml from 'js-yaml';
import * as path from 'path';
import { ProgressLocation, Uri, window } from "vscode";
import { IActionContext } from 'vscode-azureextensionui';
import * as Constants from '../constants';
import { ApiTreeItem } from '../explorer/ApiTreeItem';
import { ServiceTreeItem } from '../explorer/ServiceTreeItem';
import { ext } from '../extensionVariables';
import { localize } from '../localize';
import { azUtils } from '../utils/azUtils';
import { cpUtils } from '../utils/cpUtils';
import { askFolder } from '../utils/vscodeUtils';
import ApiOpsTooling from '../utils/ApiOpsTooling';
import ExtensionHelper from '../utils/extensionUtil';
import * as Constants from '../../constants';
import { ApiTreeItem } from '../../explorer/ApiTreeItem';
import { ServiceTreeItem } from '../../explorer/ServiceTreeItem';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ApiOpsTooling } from '../../utils/ApiOpsTooling';
import { azUtils } from '../../utils/azUtils';
import { cpUtils } from '../../utils/cpUtils';
import { ExtensionHelper } from '../../utils/ExtensionHelper';
import { askFolder } from '../../utils/vscodeUtils';

export async function exportService(context: IActionContext, node?: ServiceTreeItem): Promise<void> {
if (!node) {
Expand Down Expand Up @@ -77,7 +77,7 @@ async function runExtractor(filePath: string, apimName: string, resourceGroupNam

// Check our APIOps tooling has been downloaded
const downloader = new ApiOpsTooling(ext.context, new ExtensionHelper());
await downloader.downloadExternalBinary(Constants.extractorBinaryName);
await downloader.downloadGitHubReleaseIfMissing(Constants.extractorBinaryName);

await azUtils.setSubscription(subscriptionId, ext.outputChannel);

Expand All @@ -101,7 +101,7 @@ async function runExtractor(filePath: string, apimName: string, resourceGroupNam
// This file will be set using CONFIGURATION_YAML_PATH
async function generateExtractConfig(templatesFolder: string, sourceApimName: string, apiName?: string): Promise<string> {
const extractionConfigurationFilePath = path.join(templatesFolder, "configuration.extractor.yaml");
let extractionConfiguration = {};
let extractionConfiguration: object = {};
let noticeContent = "";

if (apiName) {
Expand All @@ -117,4 +117,4 @@ async function generateExtractConfig(templatesFolder: string, sourceApimName: st
await fse.writeFile(extractionConfigurationFilePath, yamlStr);

return noticeContent;
}
}
65 changes: 65 additions & 0 deletions src/commands/apiOps/importService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ProgressLocation, window } from "vscode";
import { IActionContext } from 'vscode-azureextensionui';
import * as Constants from '../../constants';
import { ServiceTreeItem } from '../../explorer/ServiceTreeItem';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ApiOpsTooling} from "../../utils/ApiOpsTooling";
import { azUtils } from '../../utils/azUtils';
import { cpUtils } from '../../utils/cpUtils';
import { ExtensionHelper } from "../../utils/ExtensionHelper";
import { askFolder } from '../../utils/vscodeUtils';

export async function importService(context: IActionContext, node?: ServiceTreeItem): Promise<void> {
if (!node) {
node = <ServiceTreeItem>await ext.tree.showTreeItemPicker(ServiceTreeItem.contextValue, context);
}

const uri = await askFolder("Import");
const sourceApimName = node.root.serviceName;
const resourceGroup = node.root.resourceGroupName;
const subscriptionId = node.root.subscriptionId;

const noticeContent = localize("Publish", `Publishing '${uri}' to '${sourceApimName}' service.`);

window.withProgress(
{
location: ProgressLocation.Notification,
title: localize("Extracting", noticeContent),
cancellable: false
},
async () => {
await azUtils.checkAzInstalled();
await runPublisher(uri.fsPath, sourceApimName, resourceGroup, subscriptionId);
}
).then(
() => {
window.showInformationMessage(localize("Published", `Publish completed!`));
});
}

async function runPublisher(filePath: string, apimName: string, resourceGroupName: string, subscriptionId: string): Promise<void> {
ext.outputChannel.show();

// Check our APIOps tooling has been downloaded
const downloader = new ApiOpsTooling(ext.context, new ExtensionHelper());
await downloader.downloadGitHubReleaseIfMissing(Constants.publisherBinaryName);

await azUtils.setSubscription(subscriptionId, ext.outputChannel);

// It's not on the PATH so you need ./
await cpUtils.executeCommand(
ext.outputChannel,
await downloader.getDownloadStoragePath(),
`./${Constants.publisherBinaryName}`,
`AZURE_SUBSCRIPTION_ID=${subscriptionId}`,
`API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH=${filePath}`,
`API_MANAGEMENT_SERVICE_NAME=${apimName}`,
`AZURE_RESOURCE_GROUP_NAME=${resourceGroupName}`
);
}
4 changes: 2 additions & 2 deletions src/commands/setupWorkingFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { ext } from '../extensionVariables';
import { localize } from '../localize';
import { cpUtils } from '../utils/cpUtils';
import { dotnetUtils } from '../utils/dotnetUtils';
import { ExtensionHelper } from '../utils/ExtensionHelper';
import { getDefaultWorkspacePath } from '../utils/fsUtil';
import ExtensionHelper from '../utils/extensionUtil';

export async function setupWorkingFolder(this: IActionContext): Promise<void> {
ext.outputChannel.appendLine(localize("folderInitialized", "Initialization started..."));
Expand All @@ -21,7 +21,7 @@ export async function setupWorkingFolder(this: IActionContext): Promise<void> {

// check vscode csharp extension is installed.
const extensionHelper = new ExtensionHelper();
extensionHelper.checkCsharpExtensionInstalled(this);
await extensionHelper.checkCsharpExtensionInstalled(this);

const workingFolderPath = getDefaultWorkspacePath();

Expand Down
13 changes: 7 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { AzExtTreeDataProvider, AzureParentTreeItem, AzureTreeItem, AzureUserInp
import { addApiFilter } from './commands/addApiFilter';
import { addApiToGateway } from './commands/addApiToGateway';
import { addApiToProduct } from './commands/addApiToProduct';
import { exportAPI, exportService } from './commands/apiOps/exportService';
import { importService } from './commands/apiOps/importService';
import { authorizeAuthorization } from './commands/authorizations/authorizeAuthorization';
import { copyAuthorizationPolicy } from './commands/authorizations/copyAuthorizationPolicy';
import { copyAuthorizationProviderRedirectUrl } from './commands/authorizations/copyAuthorizationProviderRedirectUrl';
Expand All @@ -23,7 +25,6 @@ import { createService } from './commands/createService';
import { debugPolicy } from './commands/debugPolicies/debugPolicy';
import { deleteNode } from './commands/deleteNode';
import { copyDockerRunCommand, generateKubernetesDeployment } from './commands/deployGateway';
import { exportAPI, exportService } from './commands/exportService';
import { extractAPI, extractService } from './commands/extract';
import { generateFunctions } from './commands/generateFunctions';
import { generateNewGatewayToken } from './commands/generateNewGatewayToken';
Expand Down Expand Up @@ -79,8 +80,8 @@ import { ServiceTreeItem } from './explorer/ServiceTreeItem';
import { SubscriptionTreeItem } from './explorer/SubscriptionTreeItem';
import { ext } from './extensionVariables';
import { localize } from './localize';
import ApiOpsTooling from './utils/ApiOpsTooling';
import ExtensionHelper from './utils/extensionUtil';
import { ApiOpsTooling } from './utils/ApiOpsTooling';
import { ExtensionHelper } from './utils/ExtensionHelper';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
Expand Down Expand Up @@ -115,8 +116,8 @@ export async function activateInternal(context: vscode.ExtensionContext) {
activate(context); // activate debug context

// Download Tooling in the background when the extension is activated.
// const apiOpsTooling = new ApiOpsTooling(ext.context, new ExtensionHelper());
// await apiOpsTooling.downloadExternalBinaries();
const apiOpsTooling = new ApiOpsTooling(ext.context, new ExtensionHelper());
await apiOpsTooling.downloadApiOpsFromGithubRelease();
});
}

Expand All @@ -142,6 +143,7 @@ function registerCommands(tree: AzExtTreeDataProvider): void {
registerCommand('azureApiManagement.addApiToGateway', async (context: IActionContext, node?: GatewayApisTreeItem) => { await addApiToGateway(context, node); });
registerCommand('azureApiManagement.apiops.exportService', async (context: IActionContext, node: ServiceTreeItem) => await exportService(context, node));
registerCommand('azureApiManagement.apiops.exportApi', async (context: IActionContext, node: ApiTreeItem) => await exportAPI(context, node));
registerCommand('azureApiManagement.apiops.importService', async (context: IActionContext, node: ServiceTreeItem) => await importService(context, node));
registerCommand('azureApiManagement.extractService', async (context: IActionContext, node: ServiceTreeItem) => await extractService(context, node));
registerCommand('azureApiManagement.extractApi', async (context: IActionContext, node: ApiTreeItem) => await extractAPI(context, node));
registerCommand('azureApiManagement.importFunctionApp', async (context: IActionContext, node: ApisTreeItem) => await importFunctionApp(context, node));
Expand Down Expand Up @@ -333,7 +335,6 @@ function registerEditors(context: vscode.ExtensionContext) : void {
}, doubleClickDebounceDelay);
}


// this method is called when your extension is deactivated
// tslint:disable:typedef
// tslint:disable-next-line:no-empty
Expand Down
121 changes: 90 additions & 31 deletions src/utils/ApiOpsTooling.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import { ServiceClient } from '@azure/ms-rest-js';
import * as path from 'path';
import * as vscode from 'vscode';
import fetch from 'node-fetch';
import { createGenericClient } from 'vscode-azureextensionui';
import * as projectConstants from '../constants';
import { localize } from '../localize';
import ExtensionHelper from './extensionUtil';
import FileDownloader, { FileDownloadSettings } from './IFileDownloader';
import { ExtensionHelper } from './ExtensionHelper';
import { IFileDownloader, IFileDownloadSettings } from './IFileDownloader';

export default class ApiOpsTooling {
export class ApiOpsTooling {
constructor(private readonly context: vscode.ExtensionContext, private readonly extensionHelper: ExtensionHelper) {}

// These binaries are used for API Ops, we download them to the global storage path in the
// background as they are around 70Mb each.
public async downloadExternalBinaries(): Promise<void>{

await this.downloadExternalBinary(projectConstants.extractorBinaryName);
await this.downloadExternalBinary(projectConstants.publisherBinaryName);
}

// Get the URI of the binary, if it doesn't exist, download it.
public async downloadExternalBinary(fileName: string): Promise<void> {
await this.downloadGitHubBinaryIfNotExists(
await this.getDownloadLink(fileName),
fileName);
public async downloadApiOpsFromGithubRelease(): Promise<void> {
await this.downloadGitHubReleaseIfMissing(projectConstants.extractorBinaryName);
await this.downloadGitHubReleaseIfMissing(projectConstants.publisherBinaryName);
}

public async getDownloadStoragePath(): Promise<string> {
Expand All @@ -30,42 +23,49 @@ export default class ApiOpsTooling {

// Gets the download link for the latest release of the API Ops tooling.
public async getDownloadLink(fileName: string): Promise<string> {
const response = await fetch(projectConstants.apiOpsToolingLocation);
const data = await response.json();
const client: ServiceClient = await createGenericClient();
const result = await client.sendRequest({
method: "GET",
url: projectConstants.apiOpsToolingLocation
});

for (const asset of data.assets) {
const githubRelease = <IGithubRelease>result.parsedBody;
for (const asset of githubRelease.assets) {
if (asset.name === fileName) {
return asset.url;
}
}

vscode.window.showInformationMessage(localize("APIOps", "'{0}' not found in latest release.", fileName));
vscode.window.showErrorMessage(localize("APIOps", "'{0}' not found in latest release.", fileName));
return "";
}

public async downloadGitHubBinaryIfNotExists(url: string, fileName: string): Promise<void> {

// Maybe GitHub is is down, don't stop the extension from working.
if (url === "") {
return;
}
public async downloadGitHubReleaseIfMissing(fileName: string): Promise<void> {

const fileDownloader: FileDownloader = await this.extensionHelper.getFileDownloaderApi();
const fileDownloader: IFileDownloader = await this.extensionHelper.getFileDownloaderApi();

const exists = await fileDownloader.tryGetItem(fileName, this.context);
if (!exists) {
const url: string = await this.getDownloadLink(fileName);
// Maybe GitHub is is down, don't stop the extension from working.
if (url === "") {
return;
}

try {
const settings: FileDownloadSettings = {
const settings: IFileDownloadSettings = {
makeExecutable: true,
// eslint-disable-next-line @typescript-eslint/naming-convention
headers: {"Accept": `application/octet-stream`, "Content-Type": `application/octet-stream`}
headers: {
Accept: "application/octet-stream"
}
};
const uri: vscode.Uri = await fileDownloader.downloadFile(
vscode.Uri.parse(url),
fileName,
this.context,
/* cancellationToken */ undefined,
/* progressCallback */ undefined,
undefined, /* cancellationToken */
undefined, /* progressCallback */
settings);

if (uri.path) {
Expand All @@ -76,4 +76,63 @@ export default class ApiOpsTooling {
}
}
}
}
}

interface IGithubRelease {
url: string;
assets_url: string;
upload_url: string;
html_url: string;
id: number;
author: object;
node_id: string;
tag_name: string;
target_commitish: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: Date;
published_at: Date;
assets: IAsset[];
tarball_url: string;
zipball_url: string;
body: string;
mentions_count: number;
}

interface IAsset {
url: string;
id: number;
node_id: string;
name: string;
label: string;
uploader: object;
content_type: string;
state: string;
size: number;
download_count: number;
created_at: Date;
updated_at: Date;
browser_download_url: string;
}

// interface IAuthor {
// login: string;
// id: number;
// node_id: string;
// avatar_url: string;
// gravatar_id: string;
// url: string;
// html_url: string;
// followers_url: string;
// following_url: string;
// gists_url: string;
// starred_url: string;
// subscriptions_url: string;
// organizations_url: string;
// repos_url: string;
// events_url: string;
// received_events_url: string;
// type: string;
// site_admin: boolean;
// }
Loading

0 comments on commit 056244a

Please sign in to comment.