mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Create shared access signature RPC (#18823)
* Rebase from main branch * Made mssql a module * remove rpc specific stuff * Added create sas RPC call * Backup to url works now * Moved createSas RPC to the BlobService * Relocated createSas RPC from sql-dataprotocolclient to the mssql * After rebase * Removed duplicate symbol * Renamed Blob to AzureBlob and relocated CreateSasResponse to mssql extension * Removed AzureBlobProvider, removed AzureBlobService feature * renamed blob to azureblob, converted thenable to promise * Simplify API * fixes * docs update, blob to azureblob update * bumped sts version * Fix config Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
e9fefd2487
commit
1cf905a7b8
26
extensions/mssql/src/azureBlob/azureBlobService.ts
Normal file
26
extensions/mssql/src/azureBlob/azureBlobService.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as mssql from 'mssql';
|
||||
import { SqlOpsDataClient } from 'dataprotocol-client';
|
||||
import * as contracts from '../contracts';
|
||||
|
||||
export class AzureBlobService implements mssql.IAzureBlobService {
|
||||
|
||||
public constructor(protected readonly client: SqlOpsDataClient) { }
|
||||
|
||||
public async createSas(ownerUri: string, blobContainerUri: string, blobContainerKey: string, storageAccountName: string, expirationDate: string): Promise<mssql.CreateSasResponse> {
|
||||
// This isn't registered as a feature since it's not something that we expect every tools client to implement currently since the usage is
|
||||
// specifically for ADS and SqlToolsService.
|
||||
const params: contracts.CreateSasParams = { ownerUri, blobContainerUri, blobContainerKey, storageAccountName, expirationDate };
|
||||
return this.client.sendRequest(contracts.CreateSasRequest.type, params).then(
|
||||
undefined,
|
||||
e => {
|
||||
this.client.logFailedRequest(contracts.CreateSasRequest.type, e);
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ export const objectExplorerPrefix: string = 'objectexplorer://';
|
||||
export const SqlAssessmentService = 'sqlAssessmentService';
|
||||
export const SqlMigrationService = 'sqlMigrationService';
|
||||
export const NotebookConvertService = 'notebookConvertService';
|
||||
export const AzureBlobService = 'azureBlobService';
|
||||
|
||||
export enum BuiltInCommands {
|
||||
SetContext = 'setContext'
|
||||
|
||||
@@ -1111,6 +1111,20 @@ export namespace DisposeTableDesignerRequest {
|
||||
}
|
||||
// ------------------------------- < Table Designer > ------------------------------------
|
||||
|
||||
// ------------------------------- < Azure Blob > ------------------------------------
|
||||
export interface CreateSasParams {
|
||||
ownerUri: string;
|
||||
blobContainerUri: string;
|
||||
blobContainerKey: string;
|
||||
storageAccountName: string;
|
||||
expirationDate: string;
|
||||
}
|
||||
|
||||
export namespace CreateSasRequest {
|
||||
export const type = new RequestType<CreateSasParams, mssql.CreateSasResponse, void, void>('blob/createSas');
|
||||
}
|
||||
|
||||
// ------------------------------- < Azure Blob > ------------------------------------
|
||||
|
||||
// ------------------------------- < Execution Plan > ------------------------------------
|
||||
|
||||
|
||||
19
extensions/mssql/src/mssql.d.ts
vendored
19
extensions/mssql/src/mssql.d.ts
vendored
@@ -48,6 +48,8 @@ declare module 'mssql' {
|
||||
readonly sqlAssessment: ISqlAssessmentService;
|
||||
|
||||
readonly sqlMigration: ISqlMigrationService;
|
||||
|
||||
readonly azureBlob: IAzureBlobService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -901,4 +903,21 @@ declare module 'mssql' {
|
||||
export interface ISqlMigrationService {
|
||||
getAssessments(ownerUri: string, databases: string[]): Promise<AssessmentResult | undefined>;
|
||||
}
|
||||
|
||||
export interface CreateSasResponse {
|
||||
sharedAccessSignature: string;
|
||||
}
|
||||
|
||||
export interface IAzureBlobService {
|
||||
/**
|
||||
* Create a shared access signature for the specified blob container URI and saves it to the server specified with the connectionUri
|
||||
* @param connectionUri The connection URI of the server to save the SAS to
|
||||
* @param blobContainerUri The blob container URI to create the SAS for
|
||||
* @param blobStorageKey The key used to access the storage account
|
||||
* @param storageAccountName The name of the storage account the SAS will be created for
|
||||
* @param expirationDate The expiration date of the SAS
|
||||
* @returns A created shared access signature token
|
||||
*/
|
||||
createSas(connectionUri: string, blobContainerUri: string, blobStorageKey: string, storageAccountName: string, expirationDate: string): Promise<CreateSasResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { AppContext } from './appContext';
|
||||
import { IExtension, ICmsService, IDacFxService, ISchemaCompareService, MssqlObjectExplorerBrowser, ILanguageExtensionService, ISqlAssessmentService, ISqlMigrationService } from 'mssql';
|
||||
import { IExtension, ICmsService, IDacFxService, ISchemaCompareService, MssqlObjectExplorerBrowser, ILanguageExtensionService, ISqlAssessmentService, ISqlMigrationService, IAzureBlobService } from 'mssql';
|
||||
import * as constants from './constants';
|
||||
import { MssqlObjectExplorerNodeProvider } from './objectExplorerNodeProvider/objectExplorerNodeProvider';
|
||||
import * as azdata from 'azdata';
|
||||
@@ -40,6 +40,9 @@ export function createMssqlApi(context: AppContext, sqlToolsServer: SqlToolsServ
|
||||
},
|
||||
get sqlMigration() {
|
||||
return context.getService<ISqlMigrationService>(constants.SqlMigrationService);
|
||||
},
|
||||
get azureBlob() {
|
||||
return context.getService<IAzureBlobService>(constants.AzureBlobService);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { SqlAssessmentService } from './sqlAssessment/sqlAssessmentService';
|
||||
import { NotebookConvertService } from './notebookConvert/notebookConvertService';
|
||||
import { SqlMigrationService } from './sqlMigration/sqlMigrationService';
|
||||
import { SqlCredentialService } from './credentialstore/sqlCredentialService';
|
||||
import { AzureBlobService } from './azureBlob/azureBlobService';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
const outputChannel = vscode.window.createOutputChannel(Constants.serviceName);
|
||||
@@ -91,6 +92,7 @@ export class SqlToolsServer {
|
||||
const resourceProvider = new AzureResourceProvider(context.extensionContext.logPath, this.config);
|
||||
this.disposables.push(credsStore);
|
||||
this.disposables.push(resourceProvider);
|
||||
context.registerService(Constants.AzureBlobService, new AzureBlobService(this.client));
|
||||
return Promise.all([credsStore.start(), resourceProvider.start()]).then();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user