Created
November 22, 2022 16:14
-
-
Save battis/7ad8550cb157d7b7f320c7608099ebaf to your computer and use it in GitHub Desktop.
Accessing Google Cloud Secrets API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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