Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/plugins/deploy/azureDeployPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> };
public commands: any;

public constructor(serverless: Serverless, private options: Serverless.Options) {
public constructor(serverless: Serverless, private options: Serverless.Options & AzureLoginOptions) {
super(serverless);

this.hooks = {
Expand All @@ -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",
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/login/azureLoginPlugin.ts
Original file line number Diff line number Diff line change
@@ -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<any> };

public constructor(serverless: Serverless, private options: Serverless.Options) {
public constructor(serverless: Serverless, private options: Serverless.Options & AzureLoginOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs new unit tests to validate this behavior.

super(serverless);
this.provider = (this.serverless.getProvider("azure") as any) as AzureProvider;

Expand All @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/services/loginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
InteractiveLoginOptions,
} from "@azure/ms-rest-nodeauth";

export interface AzureLoginOptions {
subscriptionId?: string;
}

export class AzureLoginService {

/**
Expand Down