Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
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
32 changes: 23 additions & 9 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,37 @@
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Personal Access Token",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.access_token",
"required": true
},
{
"arg": "-o, --org-name <organization-name>",
"description": "Organization Name for Azure DevOps",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.org",
"required": true
},
{
"arg": "-u, --hld-url <hld-url>",
"description": "HLD Repository URL",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.hld_repository",
"required": true
},
{
"arg": "-m, --manifest-url <manifest-url>",
"description": "Manifest Repository URL",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.manifest_repository",
"required": true
},
{
"arg": "-d, --devops-project <devops-project>",
"description": "Azure DevOps Project",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.project",
"required": true
},
{
"arg": "-b, --build-script-url <build-script-url>",
Expand Down Expand Up @@ -389,7 +399,8 @@
{
"arg": "-U, --hld-repo-url <hld-repo-url>",
"description": "The high level definition (HLD) git repo url; falls back to azure_devops.org in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.hld_repository"
},
{
"arg": "-u, --service-principal-id <service-principal-id>",
Expand All @@ -409,17 +420,20 @@
{
"arg": "-o, --org-name <organization-name>",
"description": "Azure DevOps organization name; falls back to azure_devops.org in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.org"
},
{
"arg": "-d, --devops-project <project>",
"description": "Azure DevOps project name; falls back to azure_devops.project in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.project"
},
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Azure DevOps Personal access token; falls back to azure_devops.access_token in spk config.",
"required": true
"required": true,
"inherit": "azure_devops.access_token"
}
],
"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"
Expand Down
6 changes: 1 addition & 5 deletions src/commands/deployment/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { isPortNumberString, validatePrereqs } from "../../lib/validator";
import { logger } from "../../logger";
import { ConfigYaml } from "../../types";
import decorator from "./dashboard.decorator.json";
import {
build as buildError,
log as logError,
build,
} from "../../lib/errorBuilder";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

export interface IntrospectionManifest {
Expand Down
20 changes: 15 additions & 5 deletions src/commands/hld/pipeline.decorator.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,37 @@
{
"arg": "-a, --personal-access-token <personal-access-token>",
"description": "Personal Access Token",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.access_token",
"required": true
},
{
"arg": "-o, --org-name <organization-name>",
"description": "Organization Name for Azure DevOps",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.org",
"required": true
},
{
"arg": "-u, --hld-url <hld-url>",
"description": "HLD Repository URL",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.hld_repository",
"required": true
},
{
"arg": "-m, --manifest-url <manifest-url>",
"description": "Manifest Repository URL",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.manifest_repository",
"required": true
},
{
"arg": "-d, --devops-project <devops-project>",
"description": "Azure DevOps Project",
"defaultValue": ""
"defaultValue": "",
"inherit": "azure_devops.project",
"required": true
},
{
"arg": "-b, --build-script-url <build-script-url>",
Expand Down
12 changes: 7 additions & 5 deletions src/commands/hld/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const orgNameTest = (hasVal: boolean): void => {
hldUrl: "https://dev.azure.com/mocked/fabrikam/_git/hld",
manifestUrl: "https://dev.azure.com/mocked/fabrikam/_git/materialized",
orgName: hasVal ? "org Name" : "",
personalAccessToken: "",
personalAccessToken: "somesecret",
pipelineName: "",
yamlFileBranch: "",
};
Expand All @@ -93,7 +93,8 @@ const orgNameTest = (hasVal: boolean): void => {
);
} else {
expect(() => populateValues(data)).toThrow(
"value for -o, --org-name <organization-name> is missing"
`The following arguments are required:
-o, --org-name <organization-name>`
);
}
};
Expand All @@ -107,7 +108,7 @@ const projectNameTest = (hasVal: boolean): void => {
hldUrl: "https://dev.azure.com/mocked/fabrikam/_git/hld",
manifestUrl: "https://dev.azure.com/mocked/fabrikam/_git/materialized",
orgName: "orgName",
personalAccessToken: "",
personalAccessToken: "somesecret",
pipelineName: "",
yamlFileBranch: "",
};
Expand All @@ -118,7 +119,8 @@ const projectNameTest = (hasVal: boolean): void => {
);
} else {
expect(() => populateValues(data)).toThrow(
"value for -d, --devops-project <devops-project> is missing"
`The following arguments are required:
-d, --devops-project <devops-project>`
);
}
};
Expand Down Expand Up @@ -176,7 +178,7 @@ describe("test populateValues function", () => {
hldUrl: "https://github.com/fabrikam/hld",
manifestUrl: "https://github.com/fabrikam/materialized",
orgName: "orgName",
personalAccessToken: "",
personalAccessToken: "somevalue",
pipelineName: "",
yamlFileBranch: "",
})
Expand Down
50 changes: 8 additions & 42 deletions src/commands/hld/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { validateRepository } from "../../lib/azdoClient";
import {
build as buildCmd,
exit as exitCmd,
getOption as getCmdOption,
populateInheritValueFromConfig,
validateForRequiredValues,
} from "../../lib/commandBuilder";
import {
BUILD_SCRIPT_URL,
Expand All @@ -24,13 +25,12 @@ import {
IAzureRepoPipelineConfig,
queueBuild,
} from "../../lib/pipelines/pipelines";
import { logger } from "../../logger";
import decorator from "./pipeline.decorator.json";
import {
hasValue,
validateOrgNameThrowable,
validateProjectNameThrowable,
} from "../../lib/validator";
import { logger } from "../../logger";
import decorator from "./pipeline.decorator.json";

export interface CommandOptions {
pipelineName: string;
Expand All @@ -57,47 +57,13 @@ const validateRepos = (hldRepoUrl: string, manifestRepoUrl: string): void => {
};

export const populateValues = (opts: CommandOptions): CommandOptions => {
// NOTE: all the values in opts are defaulted to ""

// exception will be thrown if spk's config.yaml is missing
const { azure_devops } = Config();

opts.hldUrl =
opts.hldUrl || emptyStringIfUndefined(azure_devops?.hld_repository);

opts.manifestUrl =
opts.manifestUrl ||
emptyStringIfUndefined(azure_devops?.manifest_repository);
populateInheritValueFromConfig(decorator, Config(), opts);
validateForRequiredValues(decorator, opts, true);
validateOrgNameThrowable(opts.orgName);
validateProjectNameThrowable(opts.devopsProject);

opts.hldName = getRepositoryName(opts.hldUrl);

opts.orgName = opts.orgName || emptyStringIfUndefined(azure_devops?.org);

if (hasValue(opts.orgName)) {
validateOrgNameThrowable(opts.orgName);
} else {
throw Error(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
`value for ${getCmdOption(decorator, "org-name")!.arg} is missing`
);
}

opts.personalAccessToken =
opts.personalAccessToken ||
emptyStringIfUndefined(azure_devops?.access_token);

opts.devopsProject =
opts.devopsProject || emptyStringIfUndefined(azure_devops?.project);

if (hasValue(opts.devopsProject)) {
validateProjectNameThrowable(opts.devopsProject);
} else {
throw Error(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
`value for ${getCmdOption(decorator, "devops-project")!.arg} is missing`
);
}

opts.pipelineName =
opts.hldName + "-to-" + getRepositoryName(opts.manifestUrl);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/commandBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe("test populateInheritValueFromConfig function", () => {
inherit: "introspection.test",
},
],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{} as any,
opts
);
Expand Down
6 changes: 4 additions & 2 deletions src/lib/commandBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ export const validateForRequiredValues = (
const errors = missingItems.map((item) => item.opt.arg);

if (toThrow && errors.length !== 0) {
throw `The following arguments are required: ${errors.join("\n ")}`;
throw `The following arguments are required:\n ${errors.join("\n ")}`;
}

if (errors.length !== 0) {
logger.error(`the following arguments are required: ${errors.join("\n ")}`);
logger.error(
`the following arguments are required:\n ${errors.join("\n ")}`
);
}
return errors;
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gitutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const validateRepoUrl = (
opts: CommandOptions,
gitOriginUrl: string
): string => {
return opts.repoUrl || getRepositoryUrl(gitOriginUrl)
return opts.repoUrl || getRepositoryUrl(gitOriginUrl);
};

/**
Expand Down