Skip to content

Commit 667f749

Browse files
busunkim96rsamborski
authored andcommitted
feat!: migrate to microgenerator. (#16)
1 parent eb9da75 commit 667f749

35 files changed

+180
-162
lines changed

kms/attestations/README.rst

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Install Dependencies
3232
.. _Python Development Environment Setup Guide:
3333
https://cloud.google.com/python/setup
3434

35-
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
35+
#. Create a virtualenv. Samples are compatible with Python 3.6+.
3636

3737
.. code-block:: bash
3838
@@ -48,9 +48,15 @@ Install Dependencies
4848
.. _pip: https://pip.pypa.io/
4949
.. _virtualenv: https://virtualenv.pypa.io/
5050

51+
52+
53+
54+
55+
5156
Samples
5257
-------------------------------------------------------------------------------
5358

59+
5460
Verify attestations for keys generated by Cloud HSM
5561
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5662

@@ -66,9 +72,26 @@ To run this sample:
6672
6773
$ python verify_attestation.py
6874
69-
75+
76+
usage: verify_attestation.py [-h] attestation_file bundle_file
77+
78+
This application verifies HSM attestations using certificate bundles obtained
79+
from Cloud HSM. For more information, visit
80+
https://cloud.google.com/kms/docs/attest-key.
81+
82+
positional arguments:
83+
attestation_file Name of attestation file.
84+
bundle_file Name of certificate bundle file.
85+
86+
optional arguments:
87+
-h, --help show this help message and exit
88+
89+
90+
91+
92+
7093
7194
7295
7396
74-
.. _Google Cloud SDK: https://cloud.google.com/sdk/
97+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

kms/attestations/noxfile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
4444
# build specific Cloud project. You can also use your own string
4545
# to use your own Cloud project.
46-
'gcloud_project_env': 'GCLOUD_PROJECT',
46+
'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
4747
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
4848

4949
# A dictionary you want to inject into your test. Don't put any
@@ -72,7 +72,6 @@ def get_pytest_env_vars():
7272
env_key = TEST_CONFIG['gcloud_project_env']
7373
# This should error out if not set.
7474
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
75-
ret['GCLOUD_PROJECT'] = os.environ[env_key]
7675

7776
# Apply user supplied envs.
7877
ret.update(TEST_CONFIG['envs'])

kms/snippets/create_key_asymmetric_decrypt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def create_key_asymmetric_decrypt(project_id, location_id, key_ring_id, id):
3838
key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)
3939

4040
# Build the key.
41-
purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_DECRYPT
42-
algorithm = kms.enums.CryptoKeyVersion.CryptoKeyVersionAlgorithm.RSA_DECRYPT_OAEP_2048_SHA256
41+
purpose = kms.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_DECRYPT
42+
algorithm = kms.CryptoKeyVersion.CryptoKeyVersionAlgorithm.RSA_DECRYPT_OAEP_2048_SHA256
4343
key = {
4444
'purpose': purpose,
4545
'version_template': {
@@ -48,7 +48,7 @@ def create_key_asymmetric_decrypt(project_id, location_id, key_ring_id, id):
4848
}
4949

5050
# Call the API.
51-
created_key = client.create_crypto_key(key_ring_name, id, key)
51+
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
5252
print('Created asymmetric decrypt key: {}'.format(created_key.name))
5353
return created_key
5454
# [END kms_create_key_asymmetric_decrypt]

kms/snippets/create_key_asymmetric_sign.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def create_key_asymmetric_sign(project_id, location_id, key_ring_id, id):
3838
key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)
3939

4040
# Build the key.
41-
purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_SIGN
42-
algorithm = kms.enums.CryptoKeyVersion.CryptoKeyVersionAlgorithm.RSA_SIGN_PKCS1_2048_SHA256
41+
purpose = kms.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_SIGN
42+
algorithm = kms.CryptoKeyVersion.CryptoKeyVersionAlgorithm.RSA_SIGN_PKCS1_2048_SHA256
4343
key = {
4444
'purpose': purpose,
4545
'version_template': {
@@ -48,7 +48,7 @@ def create_key_asymmetric_sign(project_id, location_id, key_ring_id, id):
4848
}
4949

5050
# Call the API.
51-
created_key = client.create_crypto_key(key_ring_name, id, key)
51+
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
5252
print('Created asymmetric signing key: {}'.format(created_key.name))
5353
return created_key
5454
# [END kms_create_key_asymmetric_sign]

kms/snippets/create_key_hsm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def create_key_hsm(project_id, location_id, key_ring_id, id):
3838
key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)
3939

4040
# Build the key.
41-
purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
42-
algorithm = kms.enums.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
43-
protection_level = kms.enums.ProtectionLevel.HSM
41+
purpose = kms.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
42+
algorithm = kms.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
43+
protection_level = kms.ProtectionLevel.HSM
4444
key = {
4545
'purpose': purpose,
4646
'version_template': {
@@ -50,7 +50,7 @@ def create_key_hsm(project_id, location_id, key_ring_id, id):
5050
}
5151

5252
# Call the API.
53-
created_key = client.create_crypto_key(key_ring_name, id, key)
53+
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
5454
print('Created hsm key: {}'.format(created_key.name))
5555
return created_key
5656
# [END kms_create_key_hsm]

kms/snippets/create_key_labels.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def create_key_labels(project_id, location_id, key_ring_id, id):
3838
key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)
3939

4040
# Build the key.
41-
purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
42-
algorithm = kms.enums.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
41+
purpose = kms.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
42+
algorithm = kms.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
4343
key = {
4444
'purpose': purpose,
4545
'version_template': {
@@ -52,7 +52,7 @@ def create_key_labels(project_id, location_id, key_ring_id, id):
5252
}
5353

5454
# Call the API.
55-
created_key = client.create_crypto_key(key_ring_name, id, key)
55+
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
5656
print('Created labeled key: {}'.format(created_key.name))
5757
return created_key
5858
# [END kms_create_key_labels]

kms/snippets/create_key_ring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def create_key_ring(project_id, location_id, id):
3434
client = kms.KeyManagementServiceClient()
3535

3636
# Build the parent location name.
37-
location_name = client.location_path(project_id, location_id)
37+
location_name = f'projects/{project_id}/locations/{location_id}'
3838

3939
# Build the key ring.
4040
key_ring = {}
4141

4242
# Call the API.
43-
created_key_ring = client.create_key_ring(location_name, id, key_ring)
43+
created_key_ring = client.create_key_ring(request={'parent': location_name, 'key_ring_id': id, 'key_ring': key_ring})
4444
print('Created key ring: {}'.format(created_key_ring.name))
4545
return created_key_ring
4646
# [END kms_create_key_ring]

kms/snippets/create_key_rotation_schedule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def create_key_rotation_schedule(project_id, location_id, key_ring_id, id):
4141
key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)
4242

4343
# Build the key.
44-
purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
45-
algorithm = kms.enums.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
44+
purpose = kms.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
45+
algorithm = kms.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
4646
key = {
4747
'purpose': purpose,
4848
'version_template': {
@@ -61,7 +61,7 @@ def create_key_rotation_schedule(project_id, location_id, key_ring_id, id):
6161
}
6262

6363
# Call the API.
64-
created_key = client.create_crypto_key(key_ring_name, id, key)
64+
created_key = client.create_crypto_key(request={'parent': key_ring_name, 'crypto_key_id': id, 'crypto_key': key})
6565
print('Created labeled key: {}'.format(created_key.name))
6666
return created_key
6767
# [END kms_create_key_rotation_schedule]

kms/snippets/create_key_symmetric_encrypt_decrypt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def create_key_symmetric_encrypt_decrypt(project_id, location_id, key_ring_id, i
3838
key_ring_name = client.key_ring_path(project_id, location_id, key_ring_id)
3939

4040
# Build the key.
41-
purpose = kms.enums.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
42-
algorithm = kms.enums.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
41+
purpose = kms.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT
42+
algorithm = kms.CryptoKeyVersion.CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION
4343
key = {
4444
'purpose': purpose,
4545
'version_template': {
@@ -48,7 +48,7 @@ def create_key_symmetric_encrypt_decrypt(project_id, location_id, key_ring_id, i
4848
}
4949

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

kms/snippets/create_key_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create_key_version(project_id, location_id, key_ring_id, key_id):
4141
version = {}
4242

4343
# Call the API.
44-
created_version = client.create_crypto_key_version(key_name, version)
44+
created_version = client.create_crypto_key_version(request={'parent': key_name, 'crypto_key_version': version})
4545
print('Created key version: {}'.format(created_version.name))
4646
return created_version
4747
# [END kms_create_key_version]

0 commit comments

Comments
 (0)