LoginSignup
1
1

More than 1 year has passed since last update.

PythonでGCP の Secret Managerのシークレットの値を取得する

Posted at

背景

GCPのSecret Managerで設定したシークレットの値を、pythonで取得するスクリプト

実装

from google.cloud import secretmanager


class SecretManagerUtil:

    def get_secret(self, project_id: str, secret_id: str) -> str:
        client = secretmanager.SecretManagerServiceClient()
        name = f"projects/{project_id}/secrets/{secret_id}/versions/latest"
        response = client.access_secret_version(request={"name": name})
        return response.payload.data.decode("UTF-8")

if __name__ == '__main__'
    SecretManagerUtil().get_secret(PROJECT_ID, SECRET_ID)

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1