首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何使用Python在GCP Secret Manager中添加用户管理的复制

在GCP Secret Manager中添加用户管理的复制,需要按照以下步骤进行:

  1. 创建一个秘密: import google.auth import google.cloud.secretmanager.v1 as secretmanager # 获取认证 credentials = google.auth.default() client = secretmanager.SecretManagerServiceClient(credentials=credentials) # 创建秘密 secret_id = "my-secret" secret_value = "my-secret-value" secret = { "name": client.secret_path(project_id, "secrets", secret_id), "labels": {"key": "value"}, "secret": secret_value } client.create_secret(request=secret)
  2. 创建一个用户管理的复制: # 创建一个用户管理的复制 replication = { "automatic": false, "user_managed": { "replicas": [ { "location": "us-central1", "storage_class": "STANDARD" } ] } } client.create_secret_version(request=secret, secret_version=replication)
  3. 验证复制是否成功
代码语言:javascript
复制
# 获取秘密的版本
versions = client.list_secret_versions(secret.name)
for version in versions:
    if version.name == "my-secret/versions/1" and version.status == "READY" and not version.secret_version_id == "1"   ```python
# 获取秘密的版本
versions = client.list_secret_versions(secret.name)
for version in versions:
    if version.name == "my-secret/versions/1" and version.status == "READY" and not version.secret_version_id == "1"
    {
        print("复制成功")
    }
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • 领券