Skip to content

Instantly share code, notes, and snippets.

@battis
Created November 22, 2022 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/7ad8550cb157d7b7f320c7608099ebaf to your computer and use it in GitHub Desktop.
Save battis/7ad8550cb157d7b7f320c7608099ebaf to your computer and use it in GitHub Desktop.
Accessing Google Cloud Secrets API
<?php
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
class Secrets {
private static ?SecretManagerServiceClient $client = null;
private function __construct()
{}
private static function getClient(): SecretManagerServiceClient
{
if (self::$client === null) {
self::$client = new SecretManagerServiceClient();
}
return self::$client;
}
public static function get(string $key, $version = 'latest')
{
return self::getClient()->accessSecretVersion("projects/{$_ENV['GOOGLE_CLOUD_PROJECT']}/secrets/$key/versions/$version")->getPayload()->getData();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment