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
12 changes: 4 additions & 8 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@
{
"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,
"inherit": "azure_devops.hld_repository"
"required": true
},
{
"arg": "-u, --service-principal-id <service-principal-id>",
Expand All @@ -420,20 +419,17 @@
{
"arg": "-o, --org-name <organization-name>",
"description": "Azure DevOps organization name; falls back to azure_devops.org in spk config.",
"required": true,
"inherit": "azure_devops.org"
"required": true
},
{
"arg": "-d, --devops-project <project>",
"description": "Azure DevOps project name; falls back to azure_devops.project in spk config.",
"required": true,
"inherit": "azure_devops.project"
"required": true
},
{
"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,
"inherit": "azure_devops.access_token"
"required": true
}
],
"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
7 changes: 3 additions & 4 deletions src/commands/project/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
getRepositoryName,
getRepositoryUrl,
isGitHubUrl,
validateRepoUrl
validateRepoUrl,
} from "../../lib/gitutils";
import {
createPipelineForDefinition,
Expand Down Expand Up @@ -98,16 +98,15 @@ export const fetchValidateValues = (
);
}
const azureDevops = spkConfig?.azure_devops;
const repoUrl = validateRepoUrl(opts,gitOriginUrl);
const repoUrl = validateRepoUrl(opts, gitOriginUrl);
const values: CommandOptions = {
buildScriptUrl: opts.buildScriptUrl || BUILD_SCRIPT_URL,
devopsProject: opts.devopsProject || azureDevops?.project,
orgName: opts.orgName || azureDevops?.org,
personalAccessToken: opts.personalAccessToken || azureDevops?.access_token,
pipelineName:
opts.pipelineName || getRepositoryName(gitOriginUrl) + "-lifecycle",
repoName:
getRepositoryName(repoUrl) || getRepositoryName(gitOriginUrl),
repoName: getRepositoryName(repoUrl) || getRepositoryName(gitOriginUrl),
repoUrl: opts.repoUrl || getRepositoryUrl(gitOriginUrl),
yamlFileBranch: opts.yamlFileBranch,
};
Expand Down
38 changes: 27 additions & 11 deletions src/commands/ring/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import {
read as loadBedrockFile,
} from "../../lib/bedrockYaml";
import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
import {
BEDROCK_FILENAME,
PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE,
} from "../../lib/constants";
import { BEDROCK_FILENAME } from "../../lib/constants";
import { updateTriggerBranchesForServiceBuildAndUpdatePipeline } from "../../lib/fileutils";
import * as dns from "../../lib/net/dns";
import { hasValue } from "../../lib/validator";
import { logger } from "../../logger";
import { BedrockFile, BedrockFileInfo } from "../../types";
import decorator from "./create.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

/**
* Check for bedrock.yaml
Expand All @@ -28,15 +27,19 @@ export const checkDependencies = (
): void => {
const fileInfo: BedrockFileInfo = bedrockFileInfo(projectPath);
if (fileInfo.exist === false) {
throw new Error(PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE);
throw buildError(
errorStatusCode.VALIDATION_ERR,
"ring-create-cmd-err-dependency"
);
}

// Check if ring already exists, if it does, warn and exit
const bedrockFile: BedrockFile = loadBedrockFile(projectPath);
if (ringName in bedrockFile.rings) {
throw new Error(
`ring: ${ringName} already exists in project ${BEDROCK_FILENAME}.`
);
throw buildError(errorStatusCode.EXE_FLOW_ERR, {
errorKey: "ring-create-cmd-err-ring-exists",
values: [ringName, BEDROCK_FILENAME],
});
}
};

Expand All @@ -52,7 +55,12 @@ export const execute = async (
exitFn: (status: number) => Promise<void>
): Promise<void> => {
if (!hasValue(ringName)) {
logger.error(`No ring name given.`);
logError(
buildError(
errorStatusCode.VALIDATION_ERR,
"ring-create-cmd-err-name-missing"
)
);
await exitFn(1);
return;
}
Expand Down Expand Up @@ -82,8 +90,16 @@ export const execute = async (
logger.info(`Successfully created ring: ${ringName} for this project!`);
await exitFn(0);
} catch (err) {
logger.error(`Error occurred while creating ring: ${ringName}`);
logger.error(err);
logError(
buildError(
errorStatusCode.CMD_EXE_ERR,
{
errorKey: "ring-create-cmd-failed",
values: [ringName],
Comment thread
edaena marked this conversation as resolved.
},
err
)
);
await exitFn(1);
}
};
Expand Down
20 changes: 16 additions & 4 deletions src/commands/ring/delete.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import commander from "commander";
import * as bedrock from "../../lib/bedrockYaml";
import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
import { PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE } from "../../lib/constants";
import { updateTriggerBranchesForServiceBuildAndUpdatePipeline } from "../../lib/fileutils";
import { hasValue } from "../../lib/validator";
import { logger } from "../../logger";
import { BedrockFileInfo } from "../../types";
import decorator from "./delete.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

/**
* Check the bedrock.yaml and the target ring exists
Expand All @@ -15,7 +16,10 @@ import decorator from "./delete.decorator.json";
export const checkDependencies = (projectPath: string): void => {
const fileInfo: BedrockFileInfo = bedrock.fileInfo(projectPath);
if (fileInfo.exist === false) {
throw Error(PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE);
throw buildError(
errorStatusCode.VALIDATION_ERR,
"ring-delete-cmd-err-dependency"
);
}
};

Expand Down Expand Up @@ -60,8 +64,16 @@ export const execute = async (
logger.info(`Successfully deleted ring: ${ringName} from this project!`);
await exitFn(0);
} catch (err) {
logger.error(`Error occurred while deleting ring: ${ringName}`);
logger.error(err);
logError(
buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "ring-delete-cmd-failed",
values: [ringName],
},
err
)
);
await exitFn(1);
}
};
Expand Down
20 changes: 16 additions & 4 deletions src/commands/ring/set-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import {
setDefaultRing,
} from "../../lib/bedrockYaml";
import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
import { PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE } from "../../lib/constants";
import { hasValue } from "../../lib/validator";
import { logger } from "../../logger";
import { BedrockFileInfo } from "../../types";
import decorator from "./set-default.decorator.json";
import { build as buildError, log as logError } from "../../lib/errorBuilder";
import { errorStatusCode } from "../../lib/errorStatusCode";

/**
* Check for bedrock.yaml
Expand All @@ -18,7 +19,10 @@ import decorator from "./set-default.decorator.json";
export const checkDependencies = (projectPath: string): void => {
const fileInfo: BedrockFileInfo = bedrockFileInfo(projectPath);
if (fileInfo.exist === false) {
throw new Error(PROJECT_INIT_DEPENDENCY_ERROR_MESSAGE);
throw buildError(
errorStatusCode.VALIDATION_ERR,
"ring-set-default-cmd-err-dependency"
);
}
};

Expand Down Expand Up @@ -50,8 +54,16 @@ export const execute = async (
logger.info(`Successfully set default ring: ${ringName} for this project!`);
await exitFn(0);
} catch (err) {
logger.error(`Error occurred while setting default ring: ${ringName}`);
logger.error(err);
logError(
buildError(
errorStatusCode.EXE_FLOW_ERR,
{
errorKey: "ring-set-default-cmd-failed",
values: [ringName],
},
err
)
);
await exitFn(1);
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/commands/service/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getRepositoryName,
getRepositoryUrl,
isGitHubUrl,
validateRepoUrl
validateRepoUrl,
} from "../../lib/gitutils";
import {
createPipelineForDefinition,
Expand Down Expand Up @@ -87,7 +87,6 @@ export const requiredPipelineVariables = (
};
};


/**
* Install a pipeline for the service in an azure devops org.
*
Expand Down
8 changes: 6 additions & 2 deletions src/lib/gitutils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ describe("Returns an azure devops git repo url if it is defined", () => {
yamlFileBranch: "master",
};
const gitUrl = "https://github.com/CatalystCode/spk.git";
expect(validateRepoUrl(mockValues, gitUrl)).toBe("https://dev.azure.com/myOrg/myProject/_git/myRepo");
expect(validateRepoUrl(mockValues, gitUrl)).toBe(
"https://dev.azure.com/myOrg/myProject/_git/myRepo"
);
});
it("another positive test", async () => {
const mockValues: ConfigValues = {
Expand All @@ -600,6 +602,8 @@ describe("Returns an azure devops git repo url if it is defined", () => {
yamlFileBranch: "master",
};
const gitUrl = "https://github.com/CatalystCode/spk";
expect(validateRepoUrl(mockValues, gitUrl)).toBe("https://github.com/CatalystCode/spk");
expect(validateRepoUrl(mockValues, gitUrl)).toBe(
"https://github.com/CatalystCode/spk"
);
});
});
9 changes: 9 additions & 0 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@
"deployment-table-add-src-to-acr-pipeline": "Could not add source to ACR pipeline information to storage table.",
"deployment-table-add-acr-to-hld-pipeline": "Could not add ACR to HLD pipeline information to storage table.",

"ring-create-cmd-failed": "Error occurred while creating ring: {0}",
"ring-create-cmd-err-ring-exists": "Could not create ring {0} in project {1} because it already exists. Provide a different name.",
"ring-create-cmd-err-dependency": "Please run `spk project init` command before running this command to initialize the project.",
"ring-delete-cmd-err-dependency": "Please run `spk project init` command before running this command to initialize the project.",
"ring-set-default-cmd-err-dependency": "Please run `spk project init` command before running this command to initialize the project.",
"ring-create-cmd-err-name-missing": "No ring name was provided. Provide a ring name",
"ring-delete-cmd-failed": "Error occurred while deleting ring: {0}.",
"ring-set-default-cmd-failed": "Error occurred while setting default ring: {0}",

"validation-err-org-name-missing": "Organization name was missing. Provide it.",
"validation-err-org-name": "Organization name must start with a letter or number, followed by letters, numbers or hyphens, and must end with a letter or number.",
"validation-err-password-missing": "Password was missing. Provide it.",
Expand Down