Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 60c3cca

Browse files
authored
Variable Groups bug fix (#200)
* Fixes #889 * Incorporated feedback * Incorporated feedback
1 parent 24f37f2 commit 60c3cca

File tree

4 files changed

+27
-66
lines changed

4 files changed

+27
-66
lines changed

src/commands/project/create-variable-group.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export const create = async (
209209
description: "Created from spk CLI",
210210
name: variableGroupName,
211211
type: "Vsts",
212-
variables: [vars]
212+
variables: vars
213213
};
214214
return await addVariableGroup(variableGroupData, accessOpts);
215215
} catch (err) {

src/lib/pipelines/variableGroup.test.ts

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ import {
1616
enableVerboseLogging,
1717
logger
1818
} from "../../logger";
19-
import { IVariableGroupData } from "../../types";
19+
import { IVariableGroupData, IVariableGroupDataVariable } from "../../types";
2020
import {
2121
addVariableGroup,
2222
addVariableGroupWithKeyVaultMap,
2323
authorizeAccessToAllPipelines,
2424
buildVariablesMap,
2525
doAddVariableGroup,
26-
IVariablesMap,
2726
TaskApi
2827
} from "./variableGroup";
2928

@@ -381,11 +380,10 @@ describe("authorizeAccessToAllPipelines", () => {
381380
};
382381

383382
let authorized: boolean | undefined;
384-
let error: Error | undefined;
385383
try {
386384
authorized = await authorizeAccessToAllPipelines(variableGroup);
387385
} catch (err) {
388-
error = err;
386+
logger.error(err);
389387
}
390388
expect(authorized).toBeUndefined();
391389
});
@@ -406,97 +404,68 @@ describe("authorizeAccessToAllPipelines", () => {
406404

407405
describe("buildVariablesMap", () => {
408406
test("should create variable map with two variables", async () => {
409-
const var1: IVariablesMap = {
407+
const variables: IVariableGroupDataVariable = {
410408
var1: {
411409
isSecret: false,
412410
value: "val1"
413-
}
414-
};
415-
const var2: IVariablesMap = {
411+
},
416412
var2: {
417413
isSecret: true,
418414
value: "val2"
419415
}
420416
};
421417

422-
const variables: IVariablesMap[] = [];
423-
variables.push(var1);
424-
variables.push(var2);
425-
426-
let map: IVariablesMap | undefined;
427-
const expectedMap: any = `{"0":{"var1":{"isSecret":false,"value":"val1"}},"1":{"var2":{"isSecret":true,"value":"val2"}}}`;
428-
map = await buildVariablesMap(variables);
429-
expect(JSON.stringify(map)).toEqual(expectedMap);
418+
const map = await buildVariablesMap(variables);
419+
expect(map).toEqual(variables);
430420
logger.info(`map: ${JSON.stringify(map)}`);
431421
});
432422

433423
test("should create variable map with one variable", async () => {
434-
const var1: IVariablesMap = {
424+
const variables: IVariableGroupDataVariable = {
435425
var1: {
436426
isSecret: false,
437427
value: "val1"
438428
}
439429
};
440430

441-
const variables: IVariablesMap[] = [];
442-
variables.push(var1);
443-
444-
let map: IVariablesMap | undefined;
445-
const expectedMap: any = `{"0":{"var1":{"isSecret":false,"value":"val1"}}}`;
446-
map = await buildVariablesMap(variables);
447-
expect(JSON.stringify(map)).toEqual(expectedMap);
431+
const map = await buildVariablesMap(variables);
432+
expect(map).toEqual(variables);
448433
});
449434

450435
test("should create empty variable map with no variables", async () => {
451-
const variables: IVariablesMap[] = [];
452-
let map: IVariablesMap | undefined;
453-
const expectedMap: any = `{}`;
454-
map = await buildVariablesMap(variables);
455-
expect(JSON.stringify(map)).toEqual(expectedMap);
436+
const variables: IVariableGroupDataVariable = {};
437+
const map = await buildVariablesMap(variables);
438+
expect(Object.keys(map).length).toBe(0);
456439
});
457440

458441
test("should create variable map with two secrets", async () => {
459-
const var1: IVariablesMap = {
442+
const variables: IVariableGroupDataVariable = {
460443
secret1: {
461444
enabled: false
462-
}
463-
};
464-
const var2: IVariablesMap = {
445+
},
465446
secret2: {
466447
enabled: true
467448
}
468449
};
469450

470-
const variables: IVariablesMap[] = [];
471-
variables.push(var1);
472-
variables.push(var2);
473-
474-
let secretsMap: IVariablesMap | undefined;
475-
const expectedMap: any = `{"0":{"secret1":{"enabled":false}},"1":{"secret2":{"enabled":true}}}`;
476-
secretsMap = await buildVariablesMap(variables);
477-
expect(JSON.stringify(secretsMap)).toEqual(expectedMap);
451+
const secretsMap = await buildVariablesMap(variables);
452+
expect(secretsMap).toEqual(variables);
478453
});
479454

480455
test("should create variable map with one secret", async () => {
481-
const var1: IVariablesMap = {
456+
const variables: IVariableGroupDataVariable = {
482457
secret1: {
483458
enabled: true
484459
}
485460
};
486461

487-
const variables: IVariablesMap[] = [];
488-
variables.push(var1);
489-
let secretsMap: IVariablesMap | undefined;
490-
const expectedMap: any = `{"0":{"secret1":{"enabled":true}}}`;
491-
secretsMap = await buildVariablesMap(variables);
492-
expect(JSON.stringify(secretsMap)).toEqual(expectedMap);
462+
const secretsMap = await buildVariablesMap(variables);
463+
expect(secretsMap).toEqual(variables);
493464
});
494465

495466
test("should create empty variable map with no secrets", async () => {
496-
const variables: IVariablesMap[] = [];
497-
let secretsMap: IVariablesMap | undefined;
498-
const expectedMap: any = `{}`;
499-
secretsMap = await buildVariablesMap(variables);
500-
expect(JSON.stringify(secretsMap)).toEqual(expectedMap);
467+
const variables: IVariableGroupDataVariable = {};
468+
const secretsMap = await buildVariablesMap(variables);
469+
expect(Object.keys(secretsMap).length).toBe(0);
501470
});
502471
});

src/lib/pipelines/variableGroup.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,16 @@ export const authorizeAccessToAllPipelines = async (
252252
}
253253
};
254254

255-
/**
256-
* Key/value interface for variables
257-
*
258-
*/
259-
export interface IVariablesMap {
260-
[key: string]: AzureKeyVaultVariableValue;
261-
}
262-
263255
/**
264256
* Creates `IVariablesMap` object from variables key/value pairs
265257
*
266258
* @param variableGroup The Variable group object
267259
* @returns `IVariablesMap[]` with Varibale Group variables
268260
*/
269261
export const buildVariablesMap = async (
270-
variables: IVariablesMap[]
271-
): Promise<IVariablesMap> => {
272-
const variablesMap: IVariablesMap = {};
262+
variables: IVariableGroupDataVariable
263+
): Promise<IVariableGroupDataVariable> => {
264+
const variablesMap: IVariableGroupDataVariable = {};
273265
logger.debug(`variables: ${JSON.stringify(variables)}`);
274266

275267
for (const [key, value] of Object.entries(variables)) {

src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export interface IVariableGroupData {
143143
name: string;
144144
description: string;
145145
type: string;
146-
variables: IVariableGroupDataVariable[];
146+
variables: IVariableGroupDataVariable;
147147
key_vault_provider?: {
148148
name: string;
149149
service_endpoint: IServiceEndpointData;

0 commit comments

Comments
 (0)