Skip to content

Instantly share code, notes, and snippets.

@henriquez
Last active May 1, 2024 21:58
Show Gist options
  • Save henriquez/2f91fcc9a8417a8e76c1edf54e1d8002 to your computer and use it in GitHub Desktop.
Save henriquez/2f91fcc9a8417a8e76c1edf54e1d8002 to your computer and use it in GitHub Desktop.
Secret Manager create secret function examples
# Create secret in secret manager: proposed generated sample
# All of these samples assume that detail about the arguments is provided on the same page below the sample. In the case of
# protobuf types - since they are not described in the SDK reference docs, we'd create new doc content and link to them
# describing how to convert from native types to protobuf types.
# Since the existing docs are not clear, take this as an example not nec. as what the API actually requires.
# EX 1: In this example we put the types as comments, see below for other options
response = client.create_secret(
request={
"parent": parent, # REQUIRED: str
"secret_id": secret_id, # REQUIRED: str
"secret": { # REQUIRED: google.cloud.secretmanager_v1.types.Secret
"replication": { # OPTIONAL: google.cloud.secretmanager_v1.types.Replication
"automatic": {}, # OPTIONAL: google.cloud.secretmanager_v1.types.Replication.Automatic
"user_managed: { # OPTIONAL: and only if automatic is not specified: google.cloud.secretmanager_v1.types.Replication.UserManaged
"replicas": { # REQUIRED: with user_managed: MutableSequence[google.cloud.secretmanager_v1.types.Replication.UserManaged.Replica]
"location": location_id, # REQUIRED: str
"customer_managed_encryption": { # OPTIONAL: google.cloud.secretmanager_v1.types.CustomerManagedEncryption
"kms_key_name": kms_key_name # REQUIRED: The expected format is projects/*/locations/*/keyRings/*/cryptoKeys/*
}
}
}.
},
"labels": label_list, # OPTIONAL: MutableMapping[str, str]
"topics": topic_list, # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
"expire_time": timestamp # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
"ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
"etag": etag,
},
}
)
# EX 2. Here we put in placeholder strings, with the assumption that the placeholders are generated
# in a standardized way, e.g "{key_name}-{type_name}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment