Skip to content

Instantly share code, notes, and snippets.

@henriquez
Last active May 1, 2024 21:58

Revisions

  1. henriquez revised this gist May 1, 2024. 1 changed file with 41 additions and 23 deletions.
    64 changes: 41 additions & 23 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -10,38 +10,56 @@
    # Create Secret Request
    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
    "replication": { # REQUIRED: with user_managed: MutableSequence[google.cloud.secretmanager_v1.types.Replication.UserManaged.Replica]
    "location": location, # 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/*
    # REQUIRED: str
    "parent": parent,
    # REQUIRED: str
    "secret_id": secret_id,
    # REQUIRED: google.cloud.secretmanager_v1.types.Secret
    "secret": {
    # OPTIONAL: google.cloud.secretmanager_v1.types.Replication
    "replication": {
    # OPTIONAL: google.cloud.secretmanager_v1.types.Replication.Automatic
    "automatic": {},
    # OPTIONAL: and only if automatic is not specified: google.cloud.secretmanager_v1.types.Replication.UserManaged
    "user_managed": {
    # REQUIRED: with user_managed: MutableSequence[google.cloud.secretmanager_v1.types.Replication.UserManaged.Replication
    "replicas": {
    # REQUIRED: str
    "location": location,
    # OPTIONAL: google.cloud.secretmanager_v1.types.CustomerManagedEncryption
    "customer_managed_encryption": {
    # REQUIRED: The expected format is projects/*/locations/*/keyRings/*/cryptoKeys/*
    "kms_key_name": kms_key_name
    }
    }
    }
    },
    },
    },
    "labels": { # OPTIONAL: MutableMapping[str, str]
    "keyname": "valuename". # OPTIONAL: str: str
    },
    # OPTIONAL: MutableMapping[str, str]
    "labels": {
    # OPTIONAL: str: str
    "keyname": "valuename".
    },
    # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "topics": [
    "topic-name" # OPTIONAL: str
    ], # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "expire_time": expire_time, # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
    # OPTIONAL: str
    "topic-name"
    ],
    # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "expire_time": expire_time,
    # OPTIONAL: google.protobuf.duration_pb2.Duration
    "ttl": ttl,
    .. and all the other properties ..
    },
    }
    }
    )

    # Response
    # instance of google.cloud.secretmanager_v1.types.resources.Secret
    {
    name: "name", # REQUIRED: string
    create_time: "create_time", # REQUIRED: google.protobuf.timestamp_pb2.Timestamp
    # REQUIRED: str
    name: "name",
    # REQUIRED: google.protobuf.timestamp_pb2.Timestamp
    create_time: "create_time",

    ... list all the other properties, both optional and required that might occur in a response ...
    }

  2. henriquez revised this gist Apr 30, 2024. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -63,10 +63,11 @@
    # EX 2: In this example, we only put type information into values. Object types are explained in the attributes/parameters
    # section that appears below the sample similar to
    # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager/client/create_secret.html
    # otherwise this sample would be the same as the one above, including responses and errors.
    # otherwise this sample would be the same as the one above, including responses and errors. In this case required/optional
    # information would be put into the parameters section below the sample.
    response = client.create_secret(
    request={
    "parent": 'string',
    "secret_id": 'string',
    "ttl": 'google.protobuf.duration_pb2.Duration'
    "ttl": '{google.protobuf.duration_pb2.Duration}'
    ... all the other properties ...
  3. henriquez revised this gist Apr 30, 2024. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion create_secret.py
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,9 @@
    # protobuf types - since they are not described in the SDK reference docs, we'd create new doc content describing how to
    # convert from native types to protobuf types.

    # EX 1: In this example we put the types as comments, see below for other options
    # EX 1: In this example we put the types as comments, see below for other options. In languages where type information is
    # built into the request syntax, comments don't need to include type information, but may still need required/optional if its
    # not part of the type system.

    # Create Secret Request
    response = client.create_secret(
  4. henriquez revised this gist Apr 30, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -23,10 +23,10 @@
    },
    },
    "labels": { # OPTIONAL: MutableMapping[str, str]
    "keyname": "valuename"
    "keyname": "valuename". # OPTIONAL: str: str
    },
    "topics": [
    "topic-name"
    "topic-name" # OPTIONAL: str
    ], # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "expire_time": expire_time, # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
  5. henriquez revised this gist Apr 30, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -61,6 +61,7 @@
    # EX 2: In this example, we only put type information into values. Object types are explained in the attributes/parameters
    # section that appears below the sample similar to
    # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager/client/create_secret.html
    # otherwise this sample would be the same as the one above, including responses and errors.
    response = client.create_secret(
    request={
    "parent": 'string',
  6. henriquez revised this gist Apr 30, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion create_secret.py
    Original file line number Diff line number Diff line change
    @@ -64,5 +64,6 @@
    response = client.create_secret(
    request={
    "parent": 'string',
    "secret_id": 'string',
    "secret_id": 'string',
    "ttl": 'google.protobuf.duration_pb2.Duration'
    ... all the other properties ...
  7. henriquez revised this gist Apr 30, 2024. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@
    {
    name: "name", # REQUIRED: string
    create_time: "create_time", # REQUIRED: google.protobuf.timestamp_pb2.Timestamp
    ... and all the other properties, both optional and required that might occur in a response ...
    ... list all the other properties, both optional and required that might occur in a response ...
    }

    # Errors
    @@ -58,7 +58,11 @@
    }
    }

    # EX 2: In this example, we only include type information in values. Object types are explained in the attributes/parameters
    # section that appears below the sample similar to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager/client/create_secret.html


    # EX 2: In this example, we only put type information into values. Object types are explained in the attributes/parameters
    # section that appears below the sample similar to
    # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager/client/create_secret.html
    response = client.create_secret(
    request={
    "parent": 'string',
    "secret_id": 'string',
    ... all the other properties ...
  8. henriquez revised this gist Apr 30, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_secret.py
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@
    # Errors
    try:
    ...
    except WhateverTheNameOfTheExceptionIs as e:
    except WhateverTheNameOfTheExceptionIs as e:
    print(e.response)

    # Error Syntax
  9. henriquez revised this gist Apr 30, 2024. 1 changed file with 28 additions and 2 deletions.
    30 changes: 28 additions & 2 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    # Create secret in secret manager: proposed generated samples
    # 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 describing how to
    # convert from native types to protobuf types, and link to them.
    # convert from native types to protobuf types.

    # EX 1: In this example we put the types as comments, see below for other options

    # Create Secret Request
    response = client.create_secret(
    request={
    "parent": parent, # REQUIRED: str
    @@ -33,6 +35,30 @@
    }
    )

    # Response
    # instance of google.cloud.secretmanager_v1.types.resources.Secret
    {
    name: "name", # REQUIRED: string
    create_time: "create_time", # REQUIRED: google.protobuf.timestamp_pb2.Timestamp
    ... and all the other properties, both optional and required that might occur in a response ...
    }

    # Errors
    try:
    ...
    except WhateverTheNameOfTheExceptionIs as e:
    print(e.response)

    # Error Syntax
    {
    'Message': 'str',
    'Error': {
    'Code': 'str',
    'Message': 'str'
    }
    }

    # EX 2: In this example, we only include type information in values. Object types are explained in the attributes/parameters
    # section that appears below the sample similar to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager/client/create_secret.html

    # EX 2: In this example, we

  10. henriquez revised this gist Apr 30, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_secret.py
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@
    ], # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "expire_time": expire_time, # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
    # .. and all the other properties ..
    .. and all the other properties ..
    },
    }
    )
  11. henriquez revised this gist Apr 30, 2024. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -6,28 +6,28 @@
    # 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
    "replication": { # REQUIRED: with user_managed: MutableSequence[google.cloud.secretmanager_v1.types.Replication.UserManaged.Replica]
    "location": location, # REQUIRED: str
    "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
    "replication": { # REQUIRED: with user_managed: MutableSequence[google.cloud.secretmanager_v1.types.Replication.UserManaged.Replica]
    "location": location, # 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": { # OPTIONAL: MutableMapping[str, str]
    "labels": { # OPTIONAL: MutableMapping[str, str]
    "keyname": "valuename"
    },
    "topics": [
    "topic-name"
    ], # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "expire_time": expire_time, # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
    ], # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "expire_time": expire_time, # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
    # .. and all the other properties ..
    },
    }
  12. henriquez revised this gist Apr 30, 2024. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@
    # 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 describing how to
    # convert from native types to protobuf types, and link to them.
    # 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(
    @@ -13,19 +12,27 @@
    "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
    "replication": { # REQUIRED: with user_managed: MutableSequence[google.cloud.secretmanager_v1.types.Replication.UserManaged.Replica]
    "location": location, # 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
    "labels": { # OPTIONAL: MutableMapping[str, str]
    "keyname": "valuename"
    },
    "topics": [
    "topic-name"
    ], # OPTIONAL: MutableSequence[google.cloud.secretmanager_v1.types.Topic]
    "expire_time": expire_time, # OPTIONAL: google.protobuf.timestamp_pb2.Timestamp
    "ttl": ttl, # OPTIONAL: google.protobuf.duration_pb2.Duration
    # .. and all the other properties ..
    },
    }
    )
    )


    # EX 2: In this example, we

  13. henriquez revised this gist Apr 30, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # 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
    # Create secret in secret manager: proposed generated samples
    # 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 describing how to
    # convert from native types to protobuf types, and link to them.
    # Since the existing docs are not clear, take this as an example not nec. as what the API actually requires.
  14. henriquez revised this gist Apr 30, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -21,10 +21,10 @@
    }
    },
    },
    "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
    "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
    # .. and all the other properties ..
    },
    }
  15. henriquez revised this gist Apr 30, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # 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.
    # protobuf types - since they are not described in the SDK reference docs, we'd create new doc content describing how to
    # convert from native types to protobuf types, and link to them.
    # 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
    @@ -10,7 +10,7 @@
    "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
    "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]
  16. henriquez revised this gist Apr 29, 2024. 1 changed file with 23 additions and 27 deletions.
    50 changes: 23 additions & 27 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -6,30 +6,26 @@

    # 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}"
    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
    # .. and all the other properties ..
    },
    }
    )
  17. henriquez revised this gist Apr 29, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_secret.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    "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
    "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]
  18. henriquez revised this gist Apr 29, 2024. No changes.
  19. henriquez revised this gist Apr 29, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_secret.py
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    # 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
    "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
  20. henriquez revised this gist Apr 29, 2024. No changes.
  21. henriquez revised this gist Apr 29, 2024. No changes.
  22. henriquez revised this gist Apr 29, 2024. 1 changed file with 19 additions and 13 deletions.
    32 changes: 19 additions & 13 deletions create_secret.py
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,31 @@
    # 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.
    # 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/*
    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/*
    }
    }
    }.
    },
    "ttl": ttl
    "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,
    },
    }
    )
  23. henriquez revised this gist Apr 29, 2024. No changes.
  24. henriquez renamed this gist Apr 29, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  25. henriquez revised this gist Apr 29, 2024. 2 changed files with 29 additions and 1 deletion.
    29 changes: 29 additions & 0 deletions python create_secret sample
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # 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.
    # 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/*
    }
    }
    }.
    },
    "ttl": ttl
    },
    }
    )


    # 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}"
    1 change: 0 additions & 1 deletion python secret manager sample
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    # Create secret in secret manager: proposed generated sample
  26. henriquez revised this gist Apr 29, 2024. No changes.
  27. henriquez renamed this gist Apr 29, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  28. henriquez created this gist Apr 29, 2024.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Create secret in secret manager: proposed generated sample