Google Cloud Secret Manager - 在区域中创建秘密

Google Cloud Secret Manager - Create a secret in a region

我正在使用 Python 库 google-cloud-secret-manager,我在定义区域内创建秘密时遇到了一些问题。

在方法 secretmanager.create_secret 中似乎有一个可以填充的元数据参数,但我不断收到错误尝试类似的东西:

metadata=[{'region': 'europe-west1'}]

我下面的库代码对这些参数不是很清楚...

这是我要执行的原始片段:

response = secret_client.create_secret(
        request={
            "parent": parent,
            "secret_id": secret_id,
            "secret": {"replication": {"automatic": {}}},
        }
    )

有人可以帮助我吗?

提前致谢!!

编辑

以下完整代码取自official documentation,其中未指定如何指定区域...

def create_secret(project_id, secret_id):
"""
Create a new secret with the given name. A secret is a logical wrapper
around a collection of secret versions. Secret versions hold the actual
secret material.
"""

# Import the Secret Manager client library.
from google.cloud import secretmanager

# Create the Secret Manager client.
client = secretmanager.SecretManagerServiceClient()

# Build the resource name of the parent project.
parent = f"projects/{project_id}"

# Create the secret.
response = client.create_secret(
    request={
        "parent": parent,
        "secret_id": secret_id,
        "secret": {"replication": {"automatic": {}}},
    }
)

# Print the new secret name.
print("Created secret: {}".format(response.name))

如果你想手动指定复制键放置,你需要像下面的例子那样指定:

response = client.create_secret(
    request={
        "parent": parent,
        "secret_id": secret_id,
        "secret": {"user_managed": {
               "replicas": [
                    {"location": "europe-west1"}
                ]}
        },
    }
)

已接受的答案对我不起作用。 “user_managed”上面还有一层是“复制”。这是我的片段:

client.create_secret(
    request={
        "parent": f"projects/<project_id>",
        "secret_id":"<secret_name>",
        "secret": {"replication": {"user_managed": {"replicas":[{"location": "<region_name>"}]}}},
    }
)

将括号(“<”、“>”)中的值替换为您自己的值。