Skip to content

Commit

Permalink
docs(samples): updated var name to avoid shadowing built-in (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sita04 authored and rsamborski committed Nov 14, 2022
1 parent a0e8ddd commit 221607b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
7 changes: 4 additions & 3 deletions kms/snippets/create_key_asymmetric_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_asymmetric_decrypt]
def create_key_asymmetric_decrypt(project_id, location_id, key_ring_id, id):
def create_key_asymmetric_decrypt(project_id, location_id, key_ring_id, key_id):
"""
Creates a new asymmetric decryption key in Cloud KMS.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-asymmetric-decrypt-key').
key_id (string): ID of the key to create (e.g. 'my-asymmetric-decrypt-key').
Returns:
CryptoKey: Cloud KMS key.
Expand Down Expand Up @@ -54,7 +54,8 @@ def create_key_asymmetric_decrypt(project_id, location_id, key_ring_id, id):
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created asymmetric decrypt key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_asymmetric_decrypt]
7 changes: 4 additions & 3 deletions kms/snippets/create_key_asymmetric_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_asymmetric_sign]
def create_key_asymmetric_sign(project_id, location_id, key_ring_id, id):
def create_key_asymmetric_sign(project_id, location_id, key_ring_id, key_id):
"""
Creates a new asymmetric signing key in Cloud KMS.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-asymmetric-signing-key').
key_id (string): ID of the key to create (e.g. 'my-asymmetric-signing-key').
Returns:
CryptoKey: Cloud KMS key.
Expand Down Expand Up @@ -54,7 +54,8 @@ def create_key_asymmetric_sign(project_id, location_id, key_ring_id, id):
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created asymmetric signing key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_asymmetric_sign]
7 changes: 4 additions & 3 deletions kms/snippets/create_key_hsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_hsm]
def create_key_hsm(project_id, location_id, key_ring_id, id):
def create_key_hsm(project_id, location_id, key_ring_id, key_id):
"""
Creates a new key in Cloud KMS backed by Cloud HSM.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-hsm-key').
key_id (string): ID of the key to create (e.g. 'my-hsm-key').
Returns:
CryptoKey: Cloud KMS key.
Expand Down Expand Up @@ -56,7 +56,8 @@ def create_key_hsm(project_id, location_id, key_ring_id, id):
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created hsm key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_hsm]
7 changes: 4 additions & 3 deletions kms/snippets/create_key_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_labels]
def create_key_labels(project_id, location_id, key_ring_id, id):
def create_key_labels(project_id, location_id, key_ring_id, key_id):
"""
Creates a new key in Cloud KMS with labels.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-labeled-key').
key_id (string): ID of the key to create (e.g. 'my-labeled-key').
Returns:
CryptoKey: Cloud KMS key.
Expand Down Expand Up @@ -52,7 +52,8 @@ def create_key_labels(project_id, location_id, key_ring_id, id):
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created labeled key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_labels]
7 changes: 4 additions & 3 deletions kms/snippets/create_key_mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_mac]
def create_key_mac(project_id, location_id, key_ring_id, id):
def create_key_mac(project_id, location_id, key_ring_id, key_id):
"""
Creates a new key in Cloud KMS for HMAC operations.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-mac-key').
key_id (string): ID of the key to create (e.g. 'my-mac-key').
Returns:
CryptoKey: Cloud KMS key.
Expand Down Expand Up @@ -54,7 +54,8 @@ def create_key_mac(project_id, location_id, key_ring_id, id):
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created mac key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_mac]
7 changes: 4 additions & 3 deletions kms/snippets/create_key_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@


# [START kms_create_key_ring]
def create_key_ring(project_id, location_id, id):
def create_key_ring(project_id, location_id, key_ring_id):
"""
Creates a new key ring in Cloud KMS
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
id (string): ID of the key ring to create (e.g. 'my-key-ring').
key_ring_id (string): ID of the key ring to create (e.g. 'my-key-ring').
Returns:
KeyRing: Cloud KMS key ring.
Expand All @@ -40,7 +40,8 @@ def create_key_ring(project_id, location_id, id):
key_ring = {}

# Call the API.
created_key_ring = client.create_key_ring(request={'parent': location_name, 'key_ring_id': id, 'key_ring': key_ring})
created_key_ring = client.create_key_ring(
request={'parent': location_name, 'key_ring_id': key_ring_id, 'key_ring': key_ring})
print('Created key ring: {}'.format(created_key_ring.name))
return created_key_ring
# [END kms_create_key_ring]
11 changes: 6 additions & 5 deletions kms/snippets/create_key_rotation_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_rotation_schedule]
def create_key_rotation_schedule(project_id, location_id, key_ring_id, id):
def create_key_rotation_schedule(project_id, location_id, key_ring_id, key_id):
"""
Creates a new key in Cloud KMS that automatically rotates.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-rotating-key').
key_id (string): ID of the key to create (e.g. 'my-rotating-key').
Returns:
CryptoKey: Cloud KMS key.
Expand Down Expand Up @@ -51,17 +51,18 @@ def create_key_rotation_schedule(project_id, location_id, key_ring_id, id):

# Rotate the key every 30 days.
'rotation_period': {
'seconds': 60*60*24*30
'seconds': 60 * 60 * 24 * 30
},

# Start the first rotation in 24 hours.
'next_rotation_time': {
'seconds': int(time.time()) + 60*60*24
'seconds': int(time.time()) + 60 * 60 * 24
}
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created labeled key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_rotation_schedule]
9 changes: 5 additions & 4 deletions kms/snippets/create_key_symmetric_encrypt_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@


# [START kms_create_key_symmetric_encrypt_decrypt]
def create_key_symmetric_encrypt_decrypt(project_id, location_id, key_ring_id, id):
def create_key_symmetric_encrypt_decrypt(project_id, location_id, key_ring_id, key_id):
"""
Creates a new symmetric encryption/decryption key in Cloud KMS.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
key_ring_id (string): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
id (string): ID of the key to create (e.g. 'my-symmetric-key').
key_id (string): ID of the key to create (e.g. 'my-symmetric-key').
Returns:
CryptoKey: Cloud KMS key.
Expand All @@ -43,12 +43,13 @@ def create_key_symmetric_encrypt_decrypt(project_id, location_id, key_ring_id, i
key = {
'purpose': purpose,
'version_template': {
'algorithm': algorithm,
'algorithm': algorithm,
}
}

# Call the API.
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
created_key = client.create_crypto_key(
request={'parent': key_ring_name, 'crypto_key_id': key_id, 'crypto_key': key})
print('Created symmetric key: {}'.format(created_key.name))
return created_key
# [END kms_create_key_symmetric_encrypt_decrypt]

0 comments on commit 221607b

Please sign in to comment.