Skip to content

Commit

Permalink
feat: add option to force infisical select env
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhtuan0409 committed Nov 22, 2023
1 parent b3a9dfe commit 0206a7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anduintransaction/rivendell",
"version": "0.3.0",
"version": "0.3.1",
"repository": {
"type": "git",
"url": "git+https://github.com/anduintransaction/rivendell.git"
Expand Down
17 changes: 14 additions & 3 deletions js/src/secrets/infisical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@ import { SecretProvider } from "../context";

export class InfisicalSecretProvider implements SecretProvider {
client: InfisicalClient;
forceEnv: string | undefined;

constructor(siteURL: string, token: string, debug: boolean = false) {
constructor(
siteURL: string,
token: string,
debug: boolean = false,
forceEnv?: string,
) {
this.forceEnv = forceEnv;
this.client = new InfisicalClient({
token: token,
siteURL: siteURL,
debug: debug,
});
}

getTargetEnv(env: string): string {
return this.forceEnv || env;
}

async get(env: string, name: string) {
const parts = name.split("/");
const [secretName, ...paths] = parts.reverse();
const secret = await this.client.getSecret(secretName, {
environment: env,
environment: this.getTargetEnv(env),
path: `/${paths.reverse().join("/")}`,
type: "shared",
});
Expand All @@ -28,7 +39,7 @@ export class InfisicalSecretProvider implements SecretProvider {

async getPrefix(env: string, prefix: string) {
const secrets = await this.client.getAllSecrets({
environment: env,
environment: this.getTargetEnv(env),
path: `/${prefix}`,
attachToProcessEnv: false,
includeImports: false,
Expand Down

0 comments on commit 0206a7d

Please sign in to comment.