3

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?

1 Answers1

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