Skip to content

Commit 284f772

Browse files
authored
Added WIF support to AzureIoTEdgeV2 (#18627)
Added WIF support to AzureIoTEdgeV2
1 parent f9d10cf commit 284f772

File tree

7 files changed

+123
-34
lines changed

7 files changed

+123
-34
lines changed

Tasks/AzureIoTEdgeV2/deployimage.ts

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from "fs";
22
import * as path from "path";
33
import * as tl from 'azure-pipelines-task-lib/task';
44
import * as os from "os";
5+
import { loginAzureRM } from 'azure-pipelines-tasks-artifacts-common/azCliUtils';
56
import util from "./util";
67
import Constants from "./constant";
78
import { TelemetryEvent } from './telemetry';
@@ -16,7 +17,7 @@ class azureclitask {
1617
return !!tl.which("az", false);
1718
}
1819

19-
static async runMain(deploymentJson, telemetryEvent: TelemetryEvent) {
20+
static async runMain(deploymentJson, telemetryEvent: TelemetryEvent): Promise<void> {
2021
var toolExecutionError = null;
2122
try {
2223
let iothub: string = tl.getInput("iothubname", true);
@@ -41,9 +42,9 @@ class azureclitask {
4142
configId = util.normalizeDeploymentId(configId);
4243
console.log(tl.loc('NomralizedDeployementId', configId));
4344

44-
this.loginAzure();
45+
await this.loginAzure();
4546

46-
tl.debug('OS release:' + os.release());
47+
tl.debug('OS release:' + os.release());
4748
let showIotExtensionCommand = ["extension", "show", "--name", "azure-iot"];
4849
let result = tl.execSync('az', showIotExtensionCommand, Constants.execSyncSilentOption);
4950
if (result.code !== 0) { // The extension is not installed
@@ -115,9 +116,9 @@ class azureclitask {
115116
let execOptions: IExecOptions = {
116117
errStream: outputStream as stream.Writable
117118
} as IExecOptions;
118-
119+
119120
// check azcli version
120-
let checkAzureIoTVersionExtensionCommand = ["--version"];
121+
let checkAzureIoTVersionExtensionCommand = ["--version"];
121122
let viewAzVersionResult = tl.execSync('az', checkAzureIoTVersionExtensionCommand, execOptions);
122123
if(viewAzVersionResult.code !== 0)
123124
{
@@ -131,35 +132,21 @@ class azureclitask {
131132
}
132133
}
133134

134-
static loginAzure() {
135+
static async loginAzure(): Promise<void> {
135136
var connectedService = tl.getInput("connectedServiceNameARM", true);
136-
this.loginAzureRM(connectedService);
137-
}
138-
139-
static loginAzureRM(connectedService) {
140-
var servicePrincipalId = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalid", false);
141-
var servicePrincipalKey = tl.getEndpointAuthorizationParameter(connectedService, "serviceprincipalkey", false);
142-
var tenantId = tl.getEndpointAuthorizationParameter(connectedService, "tenantid", false);
143-
var subscriptionName = tl.getEndpointDataParameter(connectedService, "SubscriptionName", true);
144-
var environment = tl.getEndpointDataParameter(connectedService, "environment", true);
145137
// Work around for build agent az command will exit with non-zero code since configuration files are missing.
146138
tl.debug(tl.execSync("az", "--version", Constants.execSyncSilentOption).stdout);
147139

140+
var environment = tl.getEndpointDataParameter(connectedService, "environment", true);
148141
// Set environment if it is not AzureCloud (global Azure)
149142
if (environment && environment !== 'AzureCloud') {
150143
let result = tl.execSync("az", ["cloud", "set", "--name", environment], Constants.execSyncSilentOption);
151144
tl.debug(JSON.stringify(result));
152145
}
153146

154-
//login using svn
155-
let result = tl.execSync("az", ["login", "--service-principal", "-u", servicePrincipalId, "-p", servicePrincipalKey, "--tenant", tenantId], Constants.execSyncSilentOption);
156-
tl.debug(JSON.stringify(result));
157-
this.throwIfError(result);
147+
await loginAzureRM(connectedService);
148+
158149
this.isLoggedIn = true;
159-
//set the subscription imported to the current subscription
160-
result = tl.execSync("az", ["account", "set", "--subscription", subscriptionName], Constants.execSyncSilentOption);
161-
tl.debug(JSON.stringify(result));
162-
this.throwIfError(result);
163150
}
164151

165152
static logoutAzure() {
@@ -171,12 +158,6 @@ class azureclitask {
171158
tl.warning(tl.loc("FailedToLogout"));
172159
}
173160
}
174-
175-
static throwIfError(resultOfToolExecution) {
176-
if (resultOfToolExecution.stderr) {
177-
throw resultOfToolExecution;
178-
}
179-
}
180161
}
181162

182163
class imagevalidationtask {
@@ -253,7 +234,7 @@ class imagevalidationtask {
253234
}
254235
}
255236

256-
export async function run(telemetryEvent: TelemetryEvent) {
237+
export async function run(telemetryEvent: TelemetryEvent): Promise<void> {
257238
let inBuildPipeline: boolean = util.checkSelfInBuildPipeline();
258239
console.log(tl.loc('DeployTaskRunningInBuild', inBuildPipeline));
259240
let deploymentFilePath: string = tl.getPathInput('deploymentFilePath', true);

Tasks/AzureIoTEdgeV2/make.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"rm": [
33
{
44
"items": [
5-
"node_modules/azure-pipelines-tasks-utility-common/node_modules/azure-pipelines-task-lib"
5+
"node_modules/azure-pipelines-tasks-artifacts-common/node_modules/azure-pipelines-task-lib",
6+
"node_modules/azure-pipelines-tasks-utility-common/node_modules/azure-pipelines-task-lib",
7+
"node_modules/azure-pipelines-tool-lib/node_modules/azure-pipelines-task-lib"
68
],
79
"options": "-Rf"
810
}

Tasks/AzureIoTEdgeV2/package-lock.json

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/AzureIoTEdgeV2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@types/q": "^1.5.4",
88
"applicationinsights": "^1.0.2",
99
"azure-pipelines-task-lib": "^3.3.1",
10+
"azure-pipelines-tasks-artifacts-common": "^2.225.0",
1011
"azure-pipelines-tasks-utility-common": "^3.210.0",
1112
"minimatch": "^3.1.2"
1213
},

Tasks/AzureIoTEdgeV2/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 2,
16-
"Minor": 222,
16+
"Minor": 225,
1717
"Patch": 0
1818
},
1919
"preview": false,

Tasks/AzureIoTEdgeV2/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 2,
16-
"Minor": 222,
16+
"Minor": 225,
1717
"Patch": 0
1818
},
1919
"preview": false,

Tasks/AzureIoTEdgeV2/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class Util {
8181

8282
let cmds: Cmd[] = [];
8383
let edgeDevVersion = Constants.iotedgedevDefaultVersion;
84-
let lockSimVersion = tl.getVariable(Constants.iotedgehubdevLockVersionKey);
84+
let lockSimVersion = tl.getVariable(Constants.iotedgehubdevLockVersionKey);
8585
// if no version is specified, iotedgedev installs default simulator version
8686

8787
let lockVersion = tl.getVariable(Constants.iotedgedevLockVersionKey);

0 commit comments

Comments
 (0)