Added no subscription support (#73)

* Added no subscription support

* Added L0s

* added no subcriptions login support

* test changes

Co-authored-by: Ganesh S <ganeshs@CBREV-KESTUR.redmond.corp.microsoft.com>
Co-authored-by: aksm-ms <58936966+aksm-ms@users.noreply.github.com>
This commit is contained in:
Ganeshrockz
2020-11-03 13:49:13 +05:30
committed by GitHub
parent fa833a8f44
commit 481142a71d
6 changed files with 56 additions and 9 deletions

View File

@@ -13,12 +13,18 @@ export class ServicePrincipalLogin implements IAzurePowerShellSession {
servicePrincipalKey: string;
tenantId: string;
subscriptionId: string;
allowNoSubscriptionsLogin: boolean;
constructor(servicePrincipalId: string, servicePrincipalKey: string, tenantId: string, subscriptionId: string) {
constructor(servicePrincipalId: string,
servicePrincipalKey: string,
tenantId: string,
subscriptionId: string,
allowNoSubscriptionsLogin: boolean) {
this.servicePrincipalId = servicePrincipalId;
this.servicePrincipalKey = servicePrincipalKey;
this.tenantId = tenantId;
this.subscriptionId = subscriptionId;
this.allowNoSubscriptionsLogin = allowNoSubscriptionsLogin;
}
async initialize() {
@@ -42,7 +48,8 @@ export class ServicePrincipalLogin implements IAzurePowerShellSession {
servicePrincipalKey: this.servicePrincipalKey,
subscriptionId: this.subscriptionId,
environment: ServicePrincipalLogin.environment,
scopeLevel: ServicePrincipalLogin.scopeLevel
scopeLevel: ServicePrincipalLogin.scopeLevel,
allowNoSubscriptionsLogin: this.allowNoSubscriptionsLogin
}
const script: string = new ScriptBuilder().getAzPSLoginScript(ServicePrincipalLogin.scheme, this.tenantId, args);
await PowerShellToolRunner.init();

View File

@@ -12,7 +12,7 @@ export default class ScriptBuilder {
command += `Connect-AzAccount -ServicePrincipal -Tenant '${tenantId}' -Credential \
(New-Object System.Management.Automation.PSCredential('${args.servicePrincipalId}',(ConvertTo-SecureString '${args.servicePrincipalKey.replace("'", "''")}' -AsPlainText -Force))) \
-Environment '${args.environment}' | out-null;`;
if (args.scopeLevel === Constants.Subscription) {
if (args.scopeLevel === Constants.Subscription && !args.allowNoSubscriptionsLogin) {
command += `Set-AzContext -SubscriptionId '${args.subscriptionId}' -TenantId '${tenantId}' | out-null;`;
}
}