async function readSecret()

in devai-vscode-extension/src/review.ts [41:58]


async function readSecret(secretName: string): Promise<string | null> {
  try {
    // Create the Secret Manager client.
    const client = new SecretManagerServiceClient();

    // Build the resource name of the secret.
    const name = client.secretPath(GCP_PROJECT_ID, secretName);

    // Access the secret version.
    const [version] = await client.accessSecretVersion({ name });

    // Return the secret payload using optional chaining.
    return version.payload?.data?.toString() ?? null;
  } catch (error) {
    console.error('Error accessing secret:', error);
    return null;
  }
}