From 9fc41afe9cc0a8a82d924676c1d7f55adcd4f9cf Mon Sep 17 00:00:00 2001 From: Neeraj Mandal Date: Thu, 11 Jul 2019 15:34:51 -0700 Subject: [PATCH 1/2] Deployment with specified subscription ID feature added --- src/plugins/deploy/azureDeployPlugin.ts | 8 ++++++-- src/plugins/login/azureLoginPlugin.ts | 8 +++++--- src/services/loginService.ts | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/plugins/deploy/azureDeployPlugin.ts b/src/plugins/deploy/azureDeployPlugin.ts index 52e451c5..47f19456 100644 --- a/src/plugins/deploy/azureDeployPlugin.ts +++ b/src/plugins/deploy/azureDeployPlugin.ts @@ -3,12 +3,13 @@ import { FunctionAppService } from "../../services/functionAppService"; import { ResourceService } from "../../services/resourceService"; import { Utils } from "../../shared/utils"; import { AzureBasePlugin } from "../azureBasePlugin"; +import { AzureLoginOptions } from "../../services/loginService"; export class AzureDeployPlugin extends AzureBasePlugin { public hooks: { [eventName: string]: Promise }; public commands: any; - public constructor(serverless: Serverless, private options: Serverless.Options) { + public constructor(serverless: Serverless, private options: Serverless.Options & AzureLoginOptions) { super(serverless); this.hooks = { @@ -30,6 +31,10 @@ export class AzureDeployPlugin extends AzureBasePlugin { "resourceGroup": { usage: "Resource group for the service", shortcut: "g", + }, + subscriptionId: { + usage: "Sets the Azure subscription ID", + shortcut: "i", } } } @@ -62,7 +67,6 @@ export class AzureDeployPlugin extends AzureBasePlugin { private async deploy() { const resourceService = new ResourceService(this.serverless, this.options); - await resourceService.deployResourceGroup(); const functionAppService = new FunctionAppService(this.serverless, this.options); diff --git a/src/plugins/login/azureLoginPlugin.ts b/src/plugins/login/azureLoginPlugin.ts index d59b0492..54ffbe65 100644 --- a/src/plugins/login/azureLoginPlugin.ts +++ b/src/plugins/login/azureLoginPlugin.ts @@ -1,13 +1,13 @@ import Serverless from "serverless"; import AzureProvider from "../../provider/azureProvider"; -import { AzureLoginService } from "../../services/loginService"; +import { AzureLoginService, AzureLoginOptions } from "../../services/loginService"; import { AzureBasePlugin } from "../azureBasePlugin"; export class AzureLoginPlugin extends AzureBasePlugin { private provider: AzureProvider; public hooks: { [eventName: string]: Promise }; - public constructor(serverless: Serverless, private options: Serverless.Options) { + public constructor(serverless: Serverless, private options: Serverless.Options & AzureLoginOptions) { super(serverless); this.provider = (this.serverless.getProvider("azure") as any) as AzureProvider; @@ -32,7 +32,9 @@ export class AzureLoginPlugin extends AzureBasePlugin { this.serverless.variables["azureCredentials"] = authResult.credentials; // Use environment variable for sub ID or use the first subscription in the list (service principal can // have access to more than one subscription) - this.serverless.variables["subscriptionId"] = process.env.azureSubId || authResult.subscriptions[0].id; + this.serverless.variables["subscriptionId"] = this.options.subscriptionId || process.env.azureSubId || authResult.subscriptions[0].id; + this.serverless.cli.log(`Deploying with subscription ID: ${ this.serverless.variables["subscriptionId"]}`); + } catch (e) { this.log("Error logging into azure"); diff --git a/src/services/loginService.ts b/src/services/loginService.ts index 736671a4..c3b60463 100644 --- a/src/services/loginService.ts +++ b/src/services/loginService.ts @@ -7,6 +7,14 @@ import { InteractiveLoginOptions, } from "@azure/ms-rest-nodeauth"; +export interface AzureLoginOptions { + subscriptionId?: string; + clientId?: string; + tenantId?: string; + password?: string; + interactive?: boolean; +} + export class AzureLoginService { /** From 635d308a1ce65591ef11cd30c57976c1b4ad8842 Mon Sep 17 00:00:00 2001 From: Neeraj Mandal Date: Fri, 12 Jul 2019 11:18:39 -0700 Subject: [PATCH 2/2] AzureLoginOptions interface trimmed --- src/services/loginService.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/services/loginService.ts b/src/services/loginService.ts index c3b60463..d1843209 100644 --- a/src/services/loginService.ts +++ b/src/services/loginService.ts @@ -9,10 +9,6 @@ import { export interface AzureLoginOptions { subscriptionId?: string; - clientId?: string; - tenantId?: string; - password?: string; - interactive?: boolean; } export class AzureLoginService {