Add Arc MIAA username configuration (#12429)

* Add Arc MIAA username configuration

* username -> userName
This commit is contained in:
Charles Gagnon
2020-09-18 07:33:58 -07:00
committed by GitHub
parent eea35d4920
commit cac14ff181
7 changed files with 37 additions and 17 deletions

View File

@@ -109,6 +109,12 @@
"else:\n", "else:\n",
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_INSTANCE_NAME was not defined. Exiting\\n')\n", " sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_INSTANCE_NAME was not defined. Exiting\\n')\n",
"\n", "\n",
"env_var = \"AZDATA_NB_VAR_SQL_USERNAME\" in os.environ\n",
"if env_var:\n",
" mssql_username = os.environ[\"AZDATA_NB_VAR_SQL_USERNAME\"]\n",
"else:\n",
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_USERNAME was not defined. Exiting\\n')\n",
"\n",
"env_var = \"AZDATA_NB_VAR_SQL_PASSWORD\" in os.environ\n", "env_var = \"AZDATA_NB_VAR_SQL_PASSWORD\" in os.environ\n",
"if env_var:\n", "if env_var:\n",
" mssql_password = os.environ[\"AZDATA_NB_VAR_SQL_PASSWORD\"]\n", " mssql_password = os.environ[\"AZDATA_NB_VAR_SQL_PASSWORD\"]\n",
@@ -192,6 +198,7 @@
"memory_request_option = f' -mr \"{sql_instance_memory_request}Mi\"' if sql_instance_memory_request else \"\"\n", "memory_request_option = f' -mr \"{sql_instance_memory_request}Mi\"' if sql_instance_memory_request else \"\"\n",
"memory_limit_option = f' -ml \"{sql_instance_memory_limit}Mi\"' if sql_instance_memory_limit else \"\"\n", "memory_limit_option = f' -ml \"{sql_instance_memory_limit}Mi\"' if sql_instance_memory_limit else \"\"\n",
"\n", "\n",
"os.environ[\"AZDATA_USERNAME\"] = mssql_username\n",
"os.environ[\"AZDATA_PASSWORD\"] = mssql_password\n", "os.environ[\"AZDATA_PASSWORD\"] = mssql_password\n",
"cmd = f'azdata arc sql mi create -n {mssql_instance_name} -scd {mssql_storage_class_data} -scl {mssql_storage_class_logs}{cores_request_option}{cores_limit_option}{memory_request_option}{memory_limit_option}'\n", "cmd = f'azdata arc sql mi create -n {mssql_instance_name} -scd {mssql_storage_class_data} -scl {mssql_storage_class_logs}{cores_request_option}{cores_limit_option}{memory_request_option}{memory_limit_option}'\n",
"out=run_command()" "out=run_command()"

View File

@@ -583,8 +583,10 @@
"label": "%arc.sql.username%", "label": "%arc.sql.username%",
"variableName": "AZDATA_NB_VAR_SQL_USERNAME", "variableName": "AZDATA_NB_VAR_SQL_USERNAME",
"type": "text", "type": "text",
"defaultValue": "sa", "required": true,
"enabled": false "textValidationRequired": true,
"textValidationRegex": "^(?!sa$)",
"textValidationDescription": "%arc.sql.invalidusername%"
}, },
{ {
"label": "%arc.password%", "label": "%arc.password%",

View File

@@ -76,6 +76,7 @@
"arc.azure.section.title": "Azure information", "arc.azure.section.title": "Azure information",
"arc.sql.instance.name": "Instance name (lower case letters and digits only)", "arc.sql.instance.name": "Instance name (lower case letters and digits only)",
"arc.sql.username": "Username", "arc.sql.username": "Username",
"arc.sql.invalidusername": "sa username is disabled, please choose another username",
"arc.storage-class.dc.label": "Storage Class", "arc.storage-class.dc.label": "Storage Class",
"arc.sql.storage-class.dc.description": "The storage class to be used for all data and logs persistent volumes for all data controller pods that require them.", "arc.sql.storage-class.dc.description": "The storage class to be used for all data and logs persistent volumes for all data controller pods that require them.",
"arc.storage-class.data.label": "Storage Class (Data)", "arc.storage-class.data.label": "Storage Class (Data)",

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ResourceInfo } from 'arc'; import { MiaaResourceInfo } from 'arc';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as azdataExt from 'azdata-ext'; import * as azdataExt from 'azdata-ext';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
@@ -37,8 +37,8 @@ export class MiaaModel extends ResourceModel {
private _refreshPromise: Deferred<void> | undefined = undefined; private _refreshPromise: Deferred<void> | undefined = undefined;
constructor(private _controllerModel: ControllerModel, info: ResourceInfo, registration: Registration, private _treeDataProvider: AzureArcTreeDataProvider) { constructor(private _controllerModel: ControllerModel, private _miaaInfo: MiaaResourceInfo, registration: Registration, private _treeDataProvider: AzureArcTreeDataProvider) {
super(info, registration); super(_miaaInfo, registration);
this._azdataApi = <azdataExt.IExtension>vscode.extensions.getExtension(azdataExt.extension.name)?.exports; this._azdataApi = <azdataExt.IExtension>vscode.extensions.getExtension(azdataExt.extension.name)?.exports;
} }
@@ -165,7 +165,7 @@ export class MiaaModel extends ResourceModel {
authenticationType: 'SqlLogin', authenticationType: 'SqlLogin',
providerName: 'MSSQL', providerName: 'MSSQL',
connectionName: '', connectionName: '',
userName: 'sa', userName: this._miaaInfo.userName || '',
password: '', password: '',
savePassword: true, savePassword: true,
groupFullName: undefined, groupFullName: undefined,
@@ -183,6 +183,8 @@ export class MiaaModel extends ResourceModel {
if (credentials.password) { if (credentials.password) {
// Try to connect to verify credentials are still valid // Try to connect to verify credentials are still valid
connectionProfile.password = credentials.password; connectionProfile.password = credentials.password;
// If we don't have a username for some reason then just continue on and we'll prompt for the username below
if (connectionProfile.userName) {
const result = await azdata.connection.connect(connectionProfile, false, false); const result = await azdata.connection.connect(connectionProfile, false, false);
if (!result.connected) { if (!result.connected) {
vscode.window.showErrorMessage(loc.connectToSqlFailed(connectionProfile.serverName, result.errorMessage)); vscode.window.showErrorMessage(loc.connectToSqlFailed(connectionProfile.serverName, result.errorMessage));
@@ -191,13 +193,14 @@ export class MiaaModel extends ResourceModel {
connectionProfile = await connectToSqlDialog.waitForClose(); connectionProfile = await connectToSqlDialog.waitForClose();
} }
} }
}
} catch (err) { } catch (err) {
console.warn(`Unexpected error fetching password for MIAA instance ${err}`); console.warn(`Unexpected error fetching password for MIAA instance ${err}`);
// ignore - something happened fetching the password so just reprompt // ignore - something happened fetching the password so just reprompt
} }
} }
if (!connectionProfile?.password) { if (!connectionProfile?.userName || !connectionProfile?.password) {
// Need to prompt user for password since we don't have one stored // Need to prompt user for password since we don't have one stored
const connectToSqlDialog = new ConnectToSqlDialog(this._controllerModel, this); const connectToSqlDialog = new ConnectToSqlDialog(this._controllerModel, this);
connectToSqlDialog.showDialog(connectionProfile); connectToSqlDialog.showDialog(connectionProfile);
@@ -214,6 +217,7 @@ export class MiaaModel extends ResourceModel {
private async updateConnectionProfile(connectionProfile: azdata.IConnectionProfile): Promise<void> { private async updateConnectionProfile(connectionProfile: azdata.IConnectionProfile): Promise<void> {
this._connectionProfile = connectionProfile; this._connectionProfile = connectionProfile;
this.info.connectionId = connectionProfile.id; this.info.connectionId = connectionProfile.id;
this._miaaInfo.userName = connectionProfile.userName;
await this._treeDataProvider.saveControllers(); await this._treeDataProvider.saveControllers();
} }
} }

View File

@@ -3,7 +3,6 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
declare module 'arc' { declare module 'arc' {
import * as vscode from 'vscode';
/** /**
* Covers defining what the arc extension exports to other extensions * Covers defining what the arc extension exports to other extensions
@@ -20,6 +19,10 @@ declare module 'arc' {
sqlManagedInstances = 'sqlManagedInstances' sqlManagedInstances = 'sqlManagedInstances'
} }
export type MiaaResourceInfo = ResourceInfo & {
userName?: string
};
export type ResourceInfo = { export type ResourceInfo = {
name: string, name: string,
resourceType: ResourceType | string, resourceType: ResourceType | string,

View File

@@ -40,8 +40,7 @@ export class ConnectToSqlDialog extends InitializingComponent {
}).component(); }).component();
this.usernameInputBox = this.modelBuilder.inputBox() this.usernameInputBox = this.modelBuilder.inputBox()
.withProperties<azdata.InputBoxProperties>({ .withProperties<azdata.InputBoxProperties>({
value: connectionProfile?.userName, value: connectionProfile?.userName
enabled: false
}).component(); }).component();
this.passwordInputBox = this.modelBuilder.inputBox() this.passwordInputBox = this.modelBuilder.inputBox()
.withProperties<azdata.InputBoxProperties>({ .withProperties<azdata.InputBoxProperties>({

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ResourceInfo, ResourceType } from 'arc'; import { MiaaResourceInfo, ResourceInfo, ResourceType } from 'arc';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { UserCancelledError } from '../../common/utils'; import { UserCancelledError } from '../../common/utils';
import * as loc from '../../localizedConstants'; import * as loc from '../../localizedConstants';
@@ -105,6 +105,10 @@ export class ControllerTreeNode extends TreeNode {
node = new PostgresTreeNode(postgresModel, this.model, this._context); node = new PostgresTreeNode(postgresModel, this.model, this._context);
break; break;
case ResourceType.sqlManagedInstances: case ResourceType.sqlManagedInstances:
// Fill in the username too if we already have it
(resourceInfo as MiaaResourceInfo).userName = (this.model.info.resources.find(info =>
info.name === resourceInfo.name &&
info.resourceType === resourceInfo.resourceType) as MiaaResourceInfo)?.userName;
const miaaModel = new MiaaModel(this.model, resourceInfo, registration, this._treeDataProvider); const miaaModel = new MiaaModel(this.model, resourceInfo, registration, this._treeDataProvider);
node = new MiaaTreeNode(miaaModel, this.model); node = new MiaaTreeNode(miaaModel, this.model);
break; break;