Skip to content

Commit

Permalink
fix: secret name match if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
danteay committed May 17, 2024
1 parent 970c8b4 commit 8a7ec2e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 4 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inputs:
description: "Dry run mode (preview changes without modifying the secret)"
required: false
show_values:
description: "Dry run mode (preview changes without modifying the secret)"
description: "Show secret values when viewing change set"
required: false
exclude:
description: "List of regular expressions that determines if a secret key should be excluded from sync"
Expand Down
51 changes: 51 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /usr/bin/env node

import { program } from "commander";

import Action from "../src/action/Action.js";

const sync = async (secret, options) => {
console.log(secret);
console.log(options);

const action = new Action(
options.awsAccessKey,
options.awsSecretKey,
options.awsRegion,
secret,
options.file,
options.exclude || "^_",
options.showValues,
options.createSecret,
);

const changeSet = await action.run();

for (const desc of changeSet.changeDesc()) {
console.log(desc);
}

if (!dryRun) {
await changeSet.apply();
console.log("Secrets has been synced!!");
}
};

program
.command("sync")
.argument("<secret-name>", "Secret name")
.option("--file <string>", "Path to json file to be synced", "")
.option("--create-secret", "Create secret if not exists")
.option("--show-values", "Show secret values when viewing change set")
.option("--dry-run", "Preview changes without modifying the secret")
.option("--aws-access-key <string>", "AWS Access key id", "")
.option("--aws-secret-key <string>", "AWS Secret access key", "")
.option("--aws-region <string>", "AWS region", "")
.option(
"--exclude <string>",
"Regular expression to match keys to be excluded from sync",
)
.description("Sync secrets file")
.action(sync);

program.parse();
36 changes: 36 additions & 0 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "cli",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^5.3.0",
"commander": "^12.0.0"
}
}
14 changes: 11 additions & 3 deletions src/secrets-manager/SecretsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,19 @@ export default class SecretsManager {

const res = await this.client.send(listCommand);

if (res.SecretList.length > 0) {
return true;
if (res.SecretList.length == 0) {
return false;
}

return false;
let exists = false;

res.SecretList.forEach((secret) => {
if (secret.Name === this.secretName) {
exists = true;
}
});

return exists;
}

/**
Expand Down

0 comments on commit 8a7ec2e

Please sign in to comment.