Skip to content

Commit 1ec264a

Browse files
committed
Refactor secretmanager tests for global samples
1 parent 07e6e36 commit 1ec264a

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

secretmanager/snippets/create_secret_with_delayed_destroy.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
delayed_destroy.
1818
"""
1919

20+
# [START secretmanager_create_secret_with_delayed_destroy]
2021
import argparse
2122

23+
# Import the Secret Manager client library.
2224
from google.cloud import secretmanager
2325

24-
# [START secretmanager_create_secret_with_delayed_destroy]
26+
# from datetime import timedelta
27+
from google.protobuf.duration_pb2 import Duration
2528

2629

2730
def create_secret_with_delayed_destroy(
@@ -35,12 +38,6 @@ def create_secret_with_delayed_destroy(
3538
Secret versions hold the actual secret material.
3639
"""
3740

38-
# Import the Secret Manager client library.
39-
from google.cloud import secretmanager
40-
41-
# Import the Duration protobuf library.
42-
from google.protobuf.duration_pb2 import Duration
43-
4441
# Create the Secret Manager client.
4542
client = secretmanager.SecretManagerServiceClient()
4643

secretmanager/snippets/disable_secret_with_delayed_destroy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
from google.cloud import secretmanager
1919

20-
# [START secretmanager_disable_secret_with_delayed_destroy]
21-
2220

21+
# [START secretmanager_disable_secret_with_delayed_destroy]
2322
def disable_secret_with_delayed_destroy(
2423
project_id: str, secret_id: str
2524
) -> secretmanager.Secret:
@@ -36,7 +35,7 @@ def disable_secret_with_delayed_destroy(
3635
# Build the resource name of the secret.
3736
name = client.secret_path(project_id, secret_id)
3837

39-
# Disable delayed destroy of the secret.
38+
# Delayed destroy of the secret version.
4039
secret = {"name": name}
4140
update_mask = {"paths": ["version_destroy_ttl"]}
4241
response = client.update_secret(request={"secret": secret, "update_mask": update_mask})

secretmanager/snippets/snippets_test.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def secret(
170170
annotation_value: str,
171171
ttl: Optional[str],
172172
) -> Iterator[Tuple[str, str, str, str]]:
173-
print(f"creating secret with given secret id.")
173+
print(f"creating secret {secret_id}")
174174

175175
parent = f"projects/{project_id}"
176176
time.sleep(5)
@@ -199,7 +199,7 @@ def secret_with_delayed_destroy(
199199
version_destroy_ttl: int,
200200
ttl: Optional[str],
201201
) -> Iterator[Tuple[str, str]]:
202-
print(f"creating secret {secret_id}")
202+
print("creating secret with given secret id.")
203203

204204
parent = f"projects/{project_id}"
205205
time.sleep(5)
@@ -328,9 +328,7 @@ def test_create_secret_with_annotations(
328328

329329
def test_create_secret_with_delayed_destroy(
330330
client: secretmanager.SecretManagerServiceClient,
331-
project_id: str,
332-
secret_id: str,
333-
version_destroy_ttl: int,
331+
project_id: str, secret_id: str, version_destroy_ttl: int
334332
) -> None:
335333
secret = create_secret_with_delayed_destroy(project_id, secret_id, version_destroy_ttl)
336334
assert secret_id in secret.name

secretmanager/snippets/update_secret_with_delayed_destroy.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@
1717

1818
from google.cloud import secretmanager
1919

20-
# [START secretmanager_update_secret_with_delayed_destroy]
20+
# from datetime import timedelta
21+
from google.protobuf.duration_pb2 import Duration
2122

2223

24+
# [START secretmanager_update_secret_with_delayed_destroy]
2325
def update_secret_with_delayed_destroy(
2426
project_id: str, secret_id: str, new_version_destroy_ttl: int
2527
) -> secretmanager.UpdateSecretRequest:
2628
"""
2729
Update the version destroy ttl value on an existing secret.
2830
"""
2931

30-
# Import the Secret Manager client library.
31-
from google.cloud import secretmanager
32-
33-
# from datetime import timedelta
34-
from google.protobuf.duration_pb2 import Duration
35-
3632
# Create the Secret Manager client.
3733
client = secretmanager.SecretManagerServiceClient()
3834

0 commit comments

Comments
 (0)