Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: secret name match if exists #10

Merged
merged 1 commit into from
May 17, 2024
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 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
Loading