Merge pull request #25 from Infisical/daniel/fix-imports-2
fix: broken imports and attach to env with imports
This commit is contained in:
@@ -36,7 +36,7 @@ export interface ListSecretsRequest {
|
||||
workspaceId: string;
|
||||
environment: string;
|
||||
expandSecretReferences?: string;
|
||||
includeImports?: string;
|
||||
include_imports?: string;
|
||||
recursive?: string;
|
||||
secretPath?: string;
|
||||
tagSlugs?: string;
|
||||
|
||||
@@ -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<ListSecretsOptions, "includeImports">
|
||||
|
||||
Reference in New Issue
Block a user