mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Delete azurecore value provider and simplify type (#17543)
This commit is contained in:
@@ -322,11 +322,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"resourceDeploymentValueProviders": [
|
|
||||||
{
|
|
||||||
"id": "subscription-id-to-tenant-id"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"hasAzureResourceProviders": true
|
"hasAzureResourceProviders": true
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import * as vscode from 'vscode';
|
|||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as resourceDeployment from 'resource-deployment';
|
|
||||||
|
|
||||||
import { AppContext } from './appContext';
|
import { AppContext } from './appContext';
|
||||||
import { AzureAccountProviderService } from './account-provider/azureAccountProviderService';
|
import { AzureAccountProviderService } from './account-provider/azureAccountProviderService';
|
||||||
@@ -115,40 +114,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Don't block on this since there's a bit of a circular dependency here with the extension activation since resource deployment
|
|
||||||
// depends on this extension too. It's fine to wait a bit for that to finish before registering the provider
|
|
||||||
vscode.extensions.getExtension(resourceDeployment.extension.name).activate().then((api: resourceDeployment.IExtension) => {
|
|
||||||
context.subscriptions.push(api.registerValueProvider({
|
|
||||||
id: 'subscription-id-to-tenant-id',
|
|
||||||
getValue: async (triggerValue: string) => {
|
|
||||||
if (triggerValue === '') {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
let accounts: azurecore.AzureAccount[] = [];
|
|
||||||
try {
|
|
||||||
accounts = await azdata.accounts.getAllAccounts();
|
|
||||||
} catch (err) {
|
|
||||||
console.warn(`Error fetching accounts for subscription-id-to-tenant-id provider : ${err}`);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const account of accounts) {
|
|
||||||
// Ignore any errors - they'll be logged in the called function and we still want to look
|
|
||||||
// at any subscriptions that are returned - worst case we'll just return an empty string if we didn't
|
|
||||||
// find the matching subscription
|
|
||||||
const subs = await azureResourceUtils.getSubscriptions(appContext, account, true);
|
|
||||||
const sub = subs.subscriptions.find(sub => sub.id === triggerValue);
|
|
||||||
if (sub) {
|
|
||||||
return sub.tenant;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
console.error(`Unable to find subscription with ID ${triggerValue} when mapping subscription ID to tenant ID`);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}).then(undefined, err => console.error('Error registering Azure ResourceDeployment value provider ', err));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getSubscriptions(account?: azurecore.AzureAccount, ignoreErrors?: boolean, selectedOnly: boolean = false): Promise<azurecore.GetSubscriptionsResult> {
|
getSubscriptions(account?: azurecore.AzureAccount, ignoreErrors?: boolean, selectedOnly: boolean = false): Promise<azurecore.GetSubscriptionsResult> {
|
||||||
return selectedOnly
|
return selectedOnly
|
||||||
|
|||||||
1
extensions/azurecore/src/typings/ref.d.ts
vendored
1
extensions/azurecore/src/typings/ref.d.ts
vendored
@@ -7,5 +7,4 @@
|
|||||||
/// <reference path='../../../../src/vs/vscode.proposed.d.ts'/>
|
/// <reference path='../../../../src/vs/vscode.proposed.d.ts'/>
|
||||||
/// <reference path='../../../../src/sql/azdata.d.ts'/>
|
/// <reference path='../../../../src/sql/azdata.d.ts'/>
|
||||||
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
|
/// <reference path='../../../../src/sql/azdata.proposed.d.ts'/>
|
||||||
/// <reference path='../../../resource-deployment/src/typings/resource-deployment.d.ts'/>
|
|
||||||
/// <reference types='@types/node'/>
|
/// <reference types='@types/node'/>
|
||||||
|
|||||||
@@ -27,12 +27,16 @@ declare module 'resource-deployment' {
|
|||||||
export type InputValueType = string | number | boolean | undefined;
|
export type InputValueType = string | number | boolean | undefined;
|
||||||
|
|
||||||
export interface IValueProvider {
|
export interface IValueProvider {
|
||||||
|
/**
|
||||||
|
* The ID associated with this value provider. Fields use this ID in the package.json to indicate which provider to use to get the value for that field.
|
||||||
|
* Each ID must be globally unique - an error will be thrown if the same ID is already registered.
|
||||||
|
*/
|
||||||
readonly id: string,
|
readonly id: string,
|
||||||
/**
|
/**
|
||||||
* Gets a calculated value based on the given input values.
|
* Gets a calculated value based on the given input values.
|
||||||
* @param triggerValues A map of the trigger field names and their current values specified in the valueProvider field info
|
* @param triggerValues A map of the trigger field names and their current values specified in the valueProvider field info
|
||||||
*/
|
*/
|
||||||
getValue(triggerValues: string | {[key: string]: InputValueType}): Promise<InputValueType>;
|
getValue(triggerValues: {[key: string]: InputValueType}): Promise<InputValueType>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +48,12 @@ declare module 'resource-deployment' {
|
|||||||
|
|
||||||
export interface IExtension {
|
export interface IExtension {
|
||||||
registerOptionsSourceProvider(provider: IOptionsSourceProvider): vscode.Disposable,
|
registerOptionsSourceProvider(provider: IOptionsSourceProvider): vscode.Disposable,
|
||||||
|
/**
|
||||||
|
* Registers a value provider that resource deployment definitions can use to dynamically fetch the value for specified fields.
|
||||||
|
* @param provider The provider to register
|
||||||
|
* @returns A disposable is returned that will unregister the provider when is disposed - this should be used to ensure
|
||||||
|
* that the provider is unregistered when the extension is uninstalled/deactivated.
|
||||||
|
*/
|
||||||
registerValueProvider(provider: IValueProvider): vscode.Disposable
|
registerValueProvider(provider: IValueProvider): vscode.Disposable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user