diff --git a/src/api/types/secrets.ts b/src/api/types/secrets.ts index 477c067..b6d036e 100644 --- a/src/api/types/secrets.ts +++ b/src/api/types/secrets.ts @@ -36,7 +36,7 @@ export interface ListSecretsRequest { workspaceId: string; environment: string; expandSecretReferences?: string; - includeImports?: string; + include_imports?: string; recursive?: string; secretPath?: string; tagSlugs?: string; diff --git a/src/custom/secrets.ts b/src/custom/secrets.ts index e8090a5..c1ca118 100644 --- a/src/custom/secrets.ts +++ b/src/custom/secrets.ts @@ -14,33 +14,41 @@ const defaultBoolean = (value?: boolean, defaultValue: boolean = false) => { export default class SecretsClient { constructor(private apiClient: SecretsApi) {} - listSecrets = async (options: ListSecretsOptions) => { - try { - const res = await this.apiClient.listSecrets({ - workspaceId: options.projectId, - environment: options.environment, - expandSecretReferences: convertBool( - defaultBoolean(options.expandSecretReferences, true) - ), - includeImports: convertBool(options.includeImports), - recursive: convertBool(options.recursive), - secretPath: options.secretPath, - tagSlugs: options.tagSlugs ? options.tagSlugs.join(",") : undefined, - viewSecretValue: convertBool(options.viewSecretValue ?? true), - }); + listSecrets = async (options: ListSecretsOptions) => { + try { + const res = await this.apiClient.listSecrets({ + workspaceId: options.projectId, + environment: options.environment, + expandSecretReferences: convertBool(defaultBoolean(options.expandSecretReferences, true)), + include_imports: convertBool(options.includeImports), + recursive: convertBool(options.recursive), + secretPath: options.secretPath, + tagSlugs: options.tagSlugs ? options.tagSlugs.join(",") : undefined, + viewSecretValue: convertBool(options.viewSecretValue ?? true) + }); - if (options.attachToProcessEnv) { - for (const secret of res.secrets) { + if (options.attachToProcessEnv) { + let includedSecrets = res.secrets; + if (res.imports?.length) { + for (const imp of res.imports) { + for (const importSecret of imp.secrets) { + if (!includedSecrets.find(includedSecret => includedSecret.secretKey === importSecret.secretKey)) { + includedSecrets.push(importSecret); + } + } + } + } + + for (const secret of includedSecrets) { process.env[secret.secretKey] = secret.secretValue; } } - return res; - - } catch (err) { - throw newInfisicalError(err); - } - }; + return res; + } catch (err) { + throw newInfisicalError(err); + } + }; listSecretsWithImports = async ( options: Omit