I have an application which wants to access only the secrets for that application. Is there anyway to access multiple secrets instead of accessing single secret each time?
Asked
Active
Viewed 869 times
3
-
Can you show some codes you already tried and in what way they didnt work? Can you share what frameworks and or languages you use? we need more details – Luke_ Jul 16 '21 at 08:18
-
No, you must access each secret individually – sethvargo Jul 16 '21 at 10:56
-
@Luke_ In my code i was trying fetch individually thats all. I am using nodejs with nestjs and expressjs framework – Kanika D Shetty Jul 19 '21 at 05:42
1 Answers
1
Each secret must be accessed individually via a separate API call. You can logically group secrets using labels and then "list + access" based on a label.
At present, this is only available via the API using the querystring filter
parameter. In the next two weeks, the SDKs will be updated and you could do something like:
const [secrets] = await client.listSecrets({
parent: "projects/my-project",
filter: "labels.app=my-app",
});
const versions = secrets.map((secret) => async {
return await client.accessSecretVersion({
name: `${secret.name}/versions/latest`,
});
});
In the meantime, you can perform this filtering client-side. Unless you have thousands of secrets, the performance will be negligible:
const [secrets] = await client.listSecrets({
parent: "projects/my-project",
});
const versions = await secrets
.filter((secret) => {
return secret.labels.app === "my-app";
})
.map((secret) => async {
return await client.accessSecretVersion({
name: `${secret.name}/versions/latest`,
});
});

sethvargo
- 26,739
- 10
- 86
- 156