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

[BUG-FIX] do not prompt for key vault value in spk init command #492

Merged
merged 5 commits into from
Apr 2, 2020
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
2 changes: 1 addition & 1 deletion docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"defaultValue": false
}
],
"markdown": "This command creates a configuration file, `config.yaml` in a folder `.spk`\nunder your home directory. There are two options for creating this file\n\n1. an interactive mode where you have to answer a few questions; and\n2. you provide a `yaml` file and this `yaml` will be copied to the target\n location.\n\n## Interactive mode\n\nThe command line tool attempts to read `config.yaml` in a folder `.spk` under\nyour home directory. Configuration values shall be read from it if it exists.\nAnd these values shall be default values for the questions. Otherwise, there\nshall be no default values. These are the questions\n\n1. Organization Name of Azure dev-op account\n2. Project Name of Azure dev-op account\n3. Personal Access Token (guides)\n4. Would like to have introspection configuration setup? If yes\n 1. Storage Account Name\n 1. Storage Table Name\n 1. Storage Partition Key\n 1. Storage Access Key\n 1. Key Vault Name (optional)\n\nThis tool shall verify these values by making an API call to Azure dev-op. They\nshall be written to `config.yaml` regardless the verification is successful or\nnot.\n\n> Note: In the event that you do not have internet connection, this verification\n> shall not be possible\n\n## Example\n\n```\nspk init --interactive\n```\n\nor\n\n```\nspk init --file myConfig.yaml\n```\n"
"markdown": "This command creates a configuration file, `config.yaml` in a folder `.spk`\nunder your home directory. There are two options for creating this file\n\n1. an interactive mode where you have to answer a few questions; and\n2. you provide a `yaml` file and this `yaml` will be copied to the target\n location.\n\n## Interactive mode\n\nThe command line tool attempts to read `config.yaml` in a folder `.spk` under\nyour home directory. Configuration values shall be read from it if it exists.\nAnd these values shall be default values for the questions. Otherwise, there\nshall be no default values. These are the questions\n\n1. Organization Name of Azure dev-op account\n2. Project Name of Azure dev-op account\n3. Personal Access Token (guides)\n4. Would like to have introspection configuration setup? If yes\n 1. Storage Account Name\n 1. Storage Table Name\n 1. Storage Partition Key\n 1. Storage Access Key\n\nThis tool shall verify these values by making an API call to Azure dev-op. They\nshall be written to `config.yaml` regardless the verification is successful or\nnot.\n\n> Note: In the event that you do not have internet connection, this verification\n> shall not be possible\n\n## Example\n\n```\nspk init --interactive\n```\n\nor\n\n```\nspk init --file myConfig.yaml\n```\n"
},
"setup": {
"command": "setup",
Expand Down
1 change: 0 additions & 1 deletion src/commands/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ shall be no default values. These are the questions
1. Storage Table Name
1. Storage Partition Key
1. Storage Access Key
1. Key Vault Name (optional)

This tool shall verify these values by making an API call to Azure dev-op. They
shall be written to `config.yaml` regardless the verification is successful or
Expand Down
12 changes: 1 addition & 11 deletions src/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ describe("test prompt function", () => {
});

const testHandleIntrospectionInteractive = async (
withIntrospection = false,
withKeyVault = false
withIntrospection = false
): Promise<void> => {
const config: ConfigYaml = {};
if (!withIntrospection) {
Expand All @@ -242,26 +241,17 @@ const testHandleIntrospectionInteractive = async (
azdo_storage_table_name: "storagetabletest",
azdo_storage_partition_key: "test1234key",
azdo_storage_access_key: "accessKey",
azdo_storage_key_vault_name: withKeyVault ? "keyvault" : "",
});
await handleIntrospectionInteractive(config);
expect(config.introspection?.azure?.account_name).toBe("storagetest");
expect(config.introspection?.azure?.table_name).toBe("storagetabletest");
expect(config.introspection?.azure?.partition_key).toBe("test1234key");
expect(config.introspection?.azure?.key).toBe("accessKey");

if (withKeyVault) {
expect(config.key_vault_name).toBe("keyvault");
} else {
expect(config.key_vault_name).toBeUndefined();
}
};

describe("test handleIntrospectionInteractive function", () => {
it("positive test", async () => {
await testHandleIntrospectionInteractive(false);
await testHandleIntrospectionInteractive(true);
await testHandleIntrospectionInteractive(false, true);
await testHandleIntrospectionInteractive(true, true);
});
});
8 changes: 0 additions & 8 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,11 @@ export const handleIntrospectionInteractive = async (
promptBuilder.azureStorageTableName(azure.table_name),
promptBuilder.azureStoragePartitionKey(azure.partition_key),
promptBuilder.azureStorageAccessKey(azure.key),
promptBuilder.azureKeyVaultName(curConfig.key_vault_name),
]);
azure["account_name"] = ans.azdo_storage_account_name;
azure["table_name"] = ans.azdo_storage_table_name;
azure["partition_key"] = ans.azdo_storage_partition_key;
azure.key = ans.azdo_storage_access_key;

const keyVaultName = ans.azdo_storage_key_vault_name.trim();
if (keyVaultName) {
curConfig["key_vault_name"] = keyVaultName;
} else {
delete curConfig["key_vault_name"];
}
};

/**
Expand Down