Skip to content

Commit

Permalink
Updates for release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
caleteeter committed Feb 28, 2020
1 parent 549a3af commit be5d092
Show file tree
Hide file tree
Showing 55 changed files with 3,137 additions and 724 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

All notable changes to the "azure blockchain" extension will be documented in this file.

## 0.1.14
## 1.1.0

### Enhancements

- Implement BDM core operations

### Fixes

- Fixed error when adding Mocks category from OpenZeppelin
- Removed unnecessary notifications when deploying to removed networks

### Internal Improvements

## 1.0.0

### Enhancements

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"publisher": "AzBlockchain",
"preview": false,
"icon": "images/blockchain-service-logo.png",
"version": "1.0.0",
"version": "1.1.0",
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/vscode-azure-blockchain-ethereum"
Expand Down
209 changes: 113 additions & 96 deletions src/ARMBlockchain/AzureBlockchainServiceClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { HttpMethods, IncomingMessage, ServiceClientCredentials, ServiceError, WebResource } from 'ms-rest';
import { AzureServiceClient, AzureServiceClientOptions, UserTokenCredentials } from 'ms-rest-azure';
import * as uuid from 'uuid';
import { Uri, window } from 'vscode';
import { ServiceClientCredentials } from 'ms-rest';
import { AzureServiceClientOptions, UserTokenCredentials } from 'ms-rest-azure';
import { Constants } from '../Constants';
import { vscodeEnvironment } from '../helpers';
import { Output } from '../Output';
import { Telemetry } from '../TelemetryClient';
import { BaseClient } from './BaseClient';
import { BlockchainDataManagerResource } from './Operations/BlockchainDataManagerResource';
import { ConsortiumResource } from './Operations/ConsortiumResource';
import { MemberResource } from './Operations/MemberResource';
Expand All @@ -17,7 +14,7 @@ import { TransactionNodeResource } from './Operations/TransactionNodeResource';

const { preview20180601, preview20190601 } = Constants.azureApiVersions;

export class AzureBlockchainServiceClient extends AzureServiceClient {
export class AzureBlockchainServiceClient extends BaseClient {
public memberResource: MemberResource;
public transactionNodeResource: TransactionNodeResource;
public consortiumResource: ConsortiumResource;
Expand All @@ -26,27 +23,13 @@ export class AzureBlockchainServiceClient extends AzureServiceClient {

constructor(
credentials: ServiceClientCredentials | UserTokenCredentials,
public readonly subscriptionId: string,
public readonly resourceGroup: string,
public readonly location: string,
public readonly baseUri: string,
public readonly options: AzureServiceClientOptions,
subscriptionId: string,
resourceGroup: string,
location: string,
baseUri: string,
options: AzureServiceClientOptions,
) {
super(credentials, options);

if (!credentials) {
const error = new Error(Constants.errorMessageStrings.VariableShouldBeDefined('Credentials'));
Telemetry.sendException(error);
throw error;
}
if (!subscriptionId) {
const error = new Error(Constants.errorMessageStrings.VariableShouldBeDefined('SubscriptionId'));
Telemetry.sendException(error);
throw error;
}

const packageInfo = this.getPackageJsonInfo(__dirname);
this.addUserAgentInfo(`${packageInfo.name}/${packageInfo.version}`);
super(credentials, subscriptionId, resourceGroup, location, baseUri, options);

this.memberResource = new MemberResource(this);
this.transactionNodeResource = new TransactionNodeResource(this);
Expand All @@ -55,33 +38,91 @@ export class AzureBlockchainServiceClient extends AzureServiceClient {
this.bdmResource = new BlockchainDataManagerResource(this);
}

public async createConsortium(memberName: string, body: string): Promise<void> {
public createConsortium(
memberName: string,
body: string,
callback: (error: Error | null, result?: any) => void,
): Promise<void> {
const url = this.getUrl(memberName, preview20180601, true, true);
const urlDetailsOfConsortium = url.slice(url.indexOf('subscriptions'), url.lastIndexOf(memberName)) + memberName;

const httpRequest = this.getHttpRequest(url, 'PUT', body);

// @ts-ignore
await this.pipeline(httpRequest, (err: ServiceError, response: IncomingMessage, responseBody: string) => {
if (err) {
Telemetry.sendException(new Error('AzureBlockchainServiceClient.createProject.pipeline.error'));
Output.outputLine(Constants.outputChannel.azureBlockchainServiceClient, err.message);
} else if (response.statusCode! < 200 || response.statusCode! > 299) {
Telemetry.sendException(new Error('AzureBlockchainServiceClient.createProject.pipeline.invalidStatus'));
Output.outputLine(
Constants.outputChannel.azureBlockchainServiceClient,
`${response.statusMessage}(${response.statusCode}): ${responseBody}`,
);

window.showErrorMessage(Constants.executeCommandMessage.failedToRunCommand('CreateConsortium'));
return this.sendRequestToAzure(httpRequest, (error) => {
if (error) {
Telemetry.sendEvent('AzureBlockchainServiceClient.createConsortium.createdFailed');
callback(error);
} else {
Telemetry.sendEvent('AzureBlockchainServiceClient.createConsortium.createdSuccessfully');
callback(null);
}
});
}

public startBlockchainDataManager(bdmName: string, callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(`watchers/${bdmName}/start`, preview20190601, true, false);

const httpRequest = this.getHttpRequest(url, 'POST');

return this.sendRequestToAzure(httpRequest, (error) => {
if (error) {
Telemetry.sendEvent('AzureBlockchainServiceClient.startBlockchainDataManager.createdFailed');
callback(error);
} else {
vscodeEnvironment.openExternal(
Uri.parse(`${Constants.azureResourceExplorer.portalBasUri}/resource/${urlDetailsOfConsortium}`),
);
Telemetry.sendEvent('AzureBlockchainServiceClient.startBlockchainDataManager.runSuccessfully');
callback(null);
}
});
}

public createBlockchainDataManager(
bdmName: string,
body: string,
callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(`watchers/${bdmName}`, preview20190601, true, false);

const httpRequest = this.getHttpRequest(url, 'PUT', body);

return this.sendRequestToAzure(httpRequest, callback);
}

public createBlockchainDataManagerInput(
bdmName: string,
transactionNodeName: string,
body: string,
callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(
`watchers/${bdmName}/inputs/${bdmName}${transactionNodeName}`, preview20190601, true, false);

const httpRequest = this.getHttpRequest(url, 'PUT', body);

return this.sendRequestToAzure(httpRequest, callback);
}

public createBlockchainDataManagerOutput(
bdmName: string,
connectionName: string,
body: string,
callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(`watchers/${bdmName}/outputs/${connectionName}`, preview20190601, true, false);

const httpRequest = this.getHttpRequest(url, 'PUT', body);

return this.sendRequestToAzure(httpRequest, callback);
}

public removeBlockchainDataManager(bdmName: string, callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(`watchers/${bdmName}`, preview20190601, true, false);

const httpRequest = this.getHttpRequest(url, 'DELETE');

return this.sendRequestToAzure(httpRequest, callback);
}

public getBlockchainDataManagers(callback: (error: Error | null, result?: any) => void): Promise<void> {
const url = this.getUrl('watchers', preview20190601, true, false);

Expand Down Expand Up @@ -138,6 +179,31 @@ export class AzureBlockchainServiceClient extends AzureServiceClient {
return this.sendRequestToAzure(httpRequest, callback);
}

public getTransactionNode(
memberName: string,
transactionNodeName: string,
callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(`${memberName}/transactionNodes/${transactionNodeName}`, preview20180601, true, true);

const httpRequest = this.getHttpRequest(url, 'GET');

return this.sendRequestToAzure(httpRequest, callback);
}

public createTransactionNode(
memberName: string,
transactionNodeName: string,
body: string,
callback: (error: Error | null, result?: any) => void)
: Promise<void> {
const url = this.getUrl(`${memberName}/transactionNodes/${transactionNodeName}`, preview20180601, true, true);

const httpRequest = this.getHttpRequest(url, 'PUT', body);

return this.sendRequestToAzure(httpRequest, callback);
}

public getTransactionNodeAccessKeys(
memberName: string,
nodeName: string,
Expand All @@ -162,56 +228,7 @@ export class AzureBlockchainServiceClient extends AzureServiceClient {
return this.sendRequestToAzure(httpRequest, callback);
}

public async sendRequestToAzure(httpRequest: WebResource, callback: (error: Error | null, result?: any) => void)
: Promise<void> {
// @ts-ignore
return this.pipeline(httpRequest, (err: ServiceError | null, response: IncomingMessage, responseBody: string) => {
if (err) {
Telemetry.sendException(new Error('AzureBlockchainServiceClient.sendRequestToAzure.pipeline.error'));
window.showErrorMessage(err.message);
return callback(err);
}

const statusCode = response.statusCode;
if (statusCode !== 200) {
const error = new Error(responseBody);
Telemetry.sendException(
new Error('AzureBlockchainServiceClient.sendRequestToAzure.pipeline.statusCodeNotSuccess'));
return callback(error);
}

// Deserialize Response
try {
const parsedResult = JSON.parse(responseBody);
return callback(null, parsedResult);
} catch (error) {
Telemetry.sendException(new Error('Unexpected token in JSON at position 1'));
return callback(new Error(`Error ${error.message} occurred in deserialize the responseBody`));
}
});
}

public getHttpRequest(url: string, method: HttpMethods, body?: string): WebResource {
const httpRequest = new WebResource();

httpRequest.method = method;
httpRequest.url = url;
httpRequest.headers = {};

httpRequest.headers['Content-Type'] = Constants.azureResourceExplorer.contentType;
if (this.options && this.options.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = uuid.v4();
}
if (this.options && this.options.acceptLanguage) {
httpRequest.headers['accept-language'] = this.options.acceptLanguage;
}

httpRequest.body = body;

return httpRequest;
}

public async checkExistence(name: string, type: string): Promise<{
public checkExistence(name: string, type: string): Promise<{
message: string | null,
nameAvailable: boolean,
reason: string,
Expand Down Expand Up @@ -248,6 +265,6 @@ export class AzureBlockchainServiceClient extends AzureServiceClient {
const blockchainMember = useBlockchainMembers ? 'blockchainMembers/' : '';

return `${this.baseUri}/subscriptions/${this.subscriptionId}/${resourceGroup}` +
`providers/Microsoft.Blockchain/${blockchainMember}${mainPartOfUrl}?api-version=${apiVersion}`;
`providers/${Constants.azureProviders.blockchain}/${blockchainMember}${mainPartOfUrl}?api-version=${apiVersion}`;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { ISkuDto } from '..';
import { ISkuDto } from '../..';

export interface IAzureBlockchainDataManagerDto {
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

export interface ICreateBlockchainDataManagerDto {
location: string;
properties: {
sku: string;
state: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

export interface ICreateBlockchainDataManagerInputDto {
properties: {
dataSource: {
enableBackfilling: string;
resourceId: string;
};
inputType: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

export interface ICreateBlockchainDataManagerOutputDto {
properties: {
dataSource: {
resourceId: string;
},
outputType: string;
};
}
1 change: 1 addition & 0 deletions src/ARMBlockchain/AzureDto/ConsortiumDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface IAzureConsortiumDto {
consortiumManagementAccountPassword: string;
rootContractAddress: string;
publicKey: string;
location: string;
}
6 changes: 6 additions & 0 deletions src/ARMBlockchain/AzureDto/CreateEventGridDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

export interface ICreateEventGridDto {
location: string;
}
9 changes: 9 additions & 0 deletions src/ARMBlockchain/AzureDto/CreateTransactionNodeDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

export interface ICreateTransactionNodeDto {
location: string;
properties: {
password: string;
};
}
16 changes: 16 additions & 0 deletions src/ARMBlockchain/AzureDto/EventGridDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

export interface IEventGridDto {
properties: {
provisioningState: string;
endpoint: string;
inputSchema: string;
metricResourceId: string;
};
location: string;
tags: string;
id: string;
name: string;
type: string;
}
Loading

0 comments on commit be5d092

Please sign in to comment.