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

Commit 17c331c

Browse files
[FEATURE] Simplify inheritance of option vals for project create variable group cmd (#504)
* [FEATURE] Simplify inheritance of option vals for project create variable group cmd * Update i18n.json Co-authored-by: Andre Briggs <[email protected]>
1 parent c139938 commit 17c331c

File tree

5 files changed

+93
-127
lines changed

5 files changed

+93
-127
lines changed

docs/commands/data.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@
400400
{
401401
"arg": "-U, --hld-repo-url <hld-repo-url>",
402402
"description": "The high level definition (HLD) git repo url; falls back to azure_devops.org in spk config.",
403-
"required": true
403+
"required": true,
404+
"inherit": "azure_devops.hld_repository"
404405
},
405406
{
406407
"arg": "-u, --service-principal-id <service-principal-id>",
@@ -420,17 +421,20 @@
420421
{
421422
"arg": "-o, --org-name <organization-name>",
422423
"description": "Azure DevOps organization name; falls back to azure_devops.org in spk config.",
423-
"required": true
424+
"required": true,
425+
"inherit": "azure_devops.org"
424426
},
425427
{
426428
"arg": "-d, --devops-project <project>",
427429
"description": "Azure DevOps project name; falls back to azure_devops.project in spk config.",
428-
"required": true
430+
"required": true,
431+
"inherit": "azure_devops.project"
429432
},
430433
{
431434
"arg": "-a, --personal-access-token <personal-access-token>",
432435
"description": "Azure DevOps Personal access token; falls back to azure_devops.access_token in spk config.",
433-
"required": true
436+
"required": true,
437+
"inherit": "azure_devops.access_token"
434438
}
435439
],
436440
"markdown": "## Description\n\nCreate new variable group in Azure DevOps project\n\n## Command Prerequisites\n\nIn addition to an existing\n[Azure DevOps project](https://azure.microsoft.com/en-us/services/devops/), to\nlink secrets from an Azure key vault as variables in Variable Group, you will\nneed an existing key vault containing your secrets and the Service Principal for\nauthorization with Azure Key Vault.\n\n1. Use existng or\n [create a service principal either in Azure Portal](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal)\n or\n [with Azure CLI](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest).\n2. Use existing or\n [create a Azure Container Registry in Azure Portal](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal)\n or\n [with Azure CLI](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-azure-cli).\n"

src/commands/project/create-variable-group.decorator.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
{
1212
"arg": "-U, --hld-repo-url <hld-repo-url>",
1313
"description": "The high level definition (HLD) git repo url; falls back to azure_devops.org in spk config.",
14-
"required": true
14+
"required": true,
15+
"inherit": "azure_devops.hld_repository"
1516
},
1617
{
1718
"arg": "-u, --service-principal-id <service-principal-id>",
@@ -31,17 +32,20 @@
3132
{
3233
"arg": "-o, --org-name <organization-name>",
3334
"description": "Azure DevOps organization name; falls back to azure_devops.org in spk config.",
34-
"required": true
35+
"required": true,
36+
"inherit": "azure_devops.org"
3537
},
3638
{
3739
"arg": "-d, --devops-project <project>",
3840
"description": "Azure DevOps project name; falls back to azure_devops.project in spk config.",
39-
"required": true
41+
"required": true,
42+
"inherit": "azure_devops.project"
4043
},
4144
{
4245
"arg": "-a, --personal-access-token <personal-access-token>",
4346
"description": "Azure DevOps Personal access token; falls back to azure_devops.access_token in spk config.",
44-
"required": true
47+
"required": true,
48+
"inherit": "azure_devops.access_token"
4549
}
4650
]
4751
}

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

+26-33
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
PROJECT_PIPELINE_FILENAME,
1212
VERSION_MESSAGE,
1313
} from "../../lib/constants";
14-
import { AzureDevOpsOpts } from "../../lib/git";
1514
import { createTempDir } from "../../lib/ioUtil";
1615
import * as pipelineVariableGroup from "../../lib/pipelines/variableGroup";
1716
import {
@@ -25,6 +24,7 @@ import {
2524
} from "../../test/mockFactory";
2625
import { AzurePipelinesYaml, BedrockFile } from "../../types";
2726
import {
27+
CommandOptions,
2828
create,
2929
execute,
3030
setVariableGroupInBedrockFile,
@@ -33,7 +33,7 @@ import {
3333
} from "./create-variable-group";
3434
import * as createVariableGrp from "./create-variable-group";
3535
import * as fileutils from "../../lib/fileutils";
36-
import { getErrorMessage } from "../../lib/errorBuilder";
36+
import { deepClone } from "../../lib/util";
3737

3838
beforeAll(() => {
3939
enableVerboseLogging();
@@ -137,24 +137,6 @@ describe("test execute function", () => {
137137
});
138138

139139
describe("create", () => {
140-
it("Should fail with empty variable group arguments", async () => {
141-
const accessOpts: AzureDevOpsOpts = {
142-
orgName,
143-
personalAccessToken,
144-
project: devopsProject,
145-
};
146-
147-
// for some reasons, cannot get the await expect(...).rejects.toThrow() to work
148-
try {
149-
await create("", "", "", "", "", "", accessOpts);
150-
expect(true).toBeFalsy();
151-
} catch (e) {
152-
expect(e.message).toBe(
153-
getErrorMessage("project-create-variable-group-cmd-err-values-missing")
154-
);
155-
}
156-
});
157-
158140
test("Should pass with variable group arguments", async () => {
159141
// mock the function that calls the Azdo project's Task API
160142
// because unit test is unable to reach this API.
@@ -168,23 +150,18 @@ describe("create", () => {
168150
return Promise.resolve({});
169151
});
170152

171-
const accessOpts: AzureDevOpsOpts = {
172-
orgName,
173-
personalAccessToken,
174-
project: devopsProject,
175-
};
176-
177153
try {
178154
logger.info("calling create");
179-
await create(
180-
variableGroupName,
155+
await create(variableGroupName, {
181156
registryName,
182157
hldRepoUrl,
183158
servicePrincipalId,
184159
servicePrincipalPassword,
185160
tenant,
186-
accessOpts
187-
);
161+
orgName,
162+
devopsProject,
163+
personalAccessToken,
164+
});
188165
} catch (err) {
189166
// should not reach here
190167
expect(true).toBe(false);
@@ -396,18 +373,34 @@ describe("updateLifeCyclePipeline", () => {
396373
});
397374
});
398375

376+
const mockConfigValues: CommandOptions = {
377+
hldRepoUrl,
378+
orgName,
379+
personalAccessToken,
380+
devopsProject,
381+
registryName,
382+
servicePrincipalId,
383+
servicePrincipalPassword,
384+
tenant,
385+
};
386+
399387
describe("test validateValues function", () => {
400388
it("valid org and project name", () => {
401-
validateValues(devopsProject, orgName);
389+
const data = deepClone(mockConfigValues);
390+
validateValues(data);
402391
});
403392
it("invalid project name", () => {
393+
const data = deepClone(mockConfigValues);
394+
data.devopsProject = "project\\abc";
404395
expect(() => {
405-
validateValues("project\\abc", orgName);
396+
validateValues(data);
406397
}).toThrow();
407398
});
408399
it("invalid org name", () => {
400+
const data = deepClone(mockConfigValues);
401+
data.orgName = "org name";
409402
expect(() => {
410-
validateValues(devopsProject, "org name");
403+
validateValues(data);
411404
}).toThrow();
412405
});
413406
});

0 commit comments

Comments
 (0)