From 0206a7d91f535ac635ce7b4f40ed5e108d16bbb7 Mon Sep 17 00:00:00 2001 From: Tuan Vuong Date: Wed, 22 Nov 2023 15:45:17 +0700 Subject: [PATCH] feat: add option to force infisical select env --- js/package.json | 2 +- js/src/secrets/infisical.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/js/package.json b/js/package.json index 7bc2d3c..450b98a 100644 --- a/js/package.json +++ b/js/package.json @@ -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" diff --git a/js/src/secrets/infisical.ts b/js/src/secrets/infisical.ts index e39f1a6..827026a 100644 --- a/js/src/secrets/infisical.ts +++ b/js/src/secrets/infisical.ts @@ -3,8 +3,15 @@ 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, @@ -12,11 +19,15 @@ export class InfisicalSecretProvider implements SecretProvider { }); } + 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", }); @@ -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,