|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 |
|
| 14 | +from datetime import timedelta |
14 | 15 | import os
|
15 | 16 | import time
|
16 | 17 | from typing import Iterator, Tuple, Union
|
17 | 18 | import uuid
|
18 | 19 |
|
19 | 20 | from google.api_core import exceptions, retry
|
20 | 21 | from google.cloud import secretmanager_v1
|
| 22 | +from google.protobuf.duration_pb2 import Duration |
21 | 23 | import pytest
|
22 | 24 |
|
23 | 25 | from regional_samples import access_regional_secret_version
|
24 | 26 | from regional_samples import add_regional_secret_version
|
25 | 27 | from regional_samples import create_regional_secret
|
26 | 28 | from regional_samples import create_regional_secret_with_annotations
|
| 29 | +from regional_samples import create_regional_secret_with_delayed_destroy |
27 | 30 | from regional_samples import create_regional_secret_with_labels
|
28 | 31 | from regional_samples import delete_regional_secret
|
29 | 32 | from regional_samples import delete_regional_secret_label
|
30 | 33 | from regional_samples import delete_regional_secret_with_etag
|
31 | 34 | from regional_samples import destroy_regional_secret_version
|
32 | 35 | from regional_samples import destroy_regional_secret_version_with_etag
|
| 36 | +from regional_samples import disable_regional_secret_delayed_destroy |
33 | 37 | from regional_samples import disable_regional_secret_version
|
34 | 38 | from regional_samples import disable_regional_secret_version_with_etag
|
35 | 39 | from regional_samples import edit_regional_secret_annotations
|
|
46 | 50 | from regional_samples import list_regional_secrets_with_filter
|
47 | 51 | from regional_samples import regional_quickstart
|
48 | 52 | from regional_samples import update_regional_secret
|
| 53 | +from regional_samples import update_regional_secret_with_delayed_destroy |
49 | 54 | from regional_samples import update_regional_secret_with_etag
|
50 | 55 | from regional_samples import view_regional_secret_annotations
|
51 | 56 | from regional_samples import view_regional_secret_labels
|
@@ -99,6 +104,11 @@ def annotation_value() -> str:
|
99 | 104 | return "annotationvalue"
|
100 | 105 |
|
101 | 106 |
|
| 107 | +@pytest.fixture() |
| 108 | +def version_destroy_ttl() -> int: |
| 109 | + return 604800 # 7 days in seconds |
| 110 | + |
| 111 | + |
102 | 112 | @retry.Retry()
|
103 | 113 | def retry_client_create_regional_secret(
|
104 | 114 | regional_client: secretmanager_v1.SecretManagerServiceClient,
|
@@ -201,6 +211,33 @@ def regional_secret(
|
201 | 211 | yield secret_id, regional_secret.etag
|
202 | 212 |
|
203 | 213 |
|
| 214 | +@pytest.fixture() |
| 215 | +def regional_secret_with_delayed_destroy( |
| 216 | + regional_client: secretmanager_v1.SecretManagerServiceClient, |
| 217 | + project_id: str, |
| 218 | + location_id: str, |
| 219 | + secret_id: str, |
| 220 | + version_destroy_ttl: int, |
| 221 | +) -> Iterator[str]: |
| 222 | + print("creating secret with given secret id.") |
| 223 | + |
| 224 | + parent = f"projects/{project_id}/locations/{location_id}" |
| 225 | + time.sleep(5) |
| 226 | + retry_client_create_regional_secret( |
| 227 | + regional_client, |
| 228 | + request={ |
| 229 | + "parent": parent, |
| 230 | + "secret_id": secret_id, |
| 231 | + "secret": { |
| 232 | + "version_destroy_ttl": Duration(seconds=version_destroy_ttl), |
| 233 | + }, |
| 234 | + }, |
| 235 | + ) |
| 236 | + print("debug") |
| 237 | + |
| 238 | + yield secret_id |
| 239 | + |
| 240 | + |
204 | 241 | def test_regional_quickstart(project_id: str, location_id: str, secret_id: str) -> None:
|
205 | 242 | regional_quickstart.regional_quickstart(project_id, location_id, secret_id)
|
206 | 243 |
|
@@ -259,6 +296,18 @@ def test_create_regional_secret_with_annotations(
|
259 | 296 | assert secret_id in secret.name
|
260 | 297 |
|
261 | 298 |
|
| 299 | +def test_create_regional_secret_with_delayed_destroy( |
| 300 | + regional_client: secretmanager_v1.SecretManagerServiceClient, |
| 301 | + project_id: str, |
| 302 | + location_id: str, |
| 303 | + secret_id: str, |
| 304 | + version_destroy_ttl: int, |
| 305 | +) -> None: |
| 306 | + secret = create_regional_secret_with_delayed_destroy.create_regional_secret_with_delayed_destroy(project_id, location_id, secret_id, version_destroy_ttl) |
| 307 | + assert secret_id in secret.name |
| 308 | + assert timedelta(seconds=version_destroy_ttl) == secret.version_destroy_ttl |
| 309 | + |
| 310 | + |
262 | 311 | def test_create_regional_secret_with_label(
|
263 | 312 | regional_client: secretmanager_v1.SecretManagerServiceClient,
|
264 | 313 | project_id: str,
|
@@ -336,6 +385,17 @@ def test_destroy_regional_secret_version_with_etag(
|
336 | 385 | assert version.destroy_time
|
337 | 386 |
|
338 | 387 |
|
| 388 | +def test_disable_regional_secret_delayed_destroy( |
| 389 | + regional_client: secretmanager_v1.SecretManagerServiceClient, |
| 390 | + regional_secret_with_delayed_destroy: str, |
| 391 | + project_id: str, |
| 392 | + location_id: str, |
| 393 | +) -> None: |
| 394 | + secret_id = regional_secret_with_delayed_destroy |
| 395 | + updated_secret = disable_regional_secret_delayed_destroy.disable_regional_secret_delayed_destroy(project_id, location_id, secret_id) |
| 396 | + assert updated_secret.version_destroy_ttl == timedelta(0) |
| 397 | + |
| 398 | + |
339 | 399 | def test_enable_disable_regional_secret_version(
|
340 | 400 | regional_client: secretmanager_v1.SecretManagerServiceClient,
|
341 | 401 | regional_secret_version: Tuple[str, str, str],
|
@@ -612,6 +672,18 @@ def test_update_regional_secret(
|
612 | 672 | assert updated_regional_secret.labels["secretmanager"] == "rocks"
|
613 | 673 |
|
614 | 674 |
|
| 675 | +def test_update_regional_secret_with_delayed_destroy( |
| 676 | + regional_secret_with_delayed_destroy: str, |
| 677 | + project_id: str, |
| 678 | + location_id: str, |
| 679 | + version_destroy_ttl: int |
| 680 | +) -> None: |
| 681 | + secret_id = regional_secret_with_delayed_destroy |
| 682 | + updated_version_delayed_destroy = 118400 |
| 683 | + updated_secret = update_regional_secret_with_delayed_destroy.update_regional_secret_with_delayed_destroy(project_id, location_id, secret_id, updated_version_delayed_destroy) |
| 684 | + assert updated_secret.version_destroy_ttl == timedelta(seconds=updated_version_delayed_destroy) |
| 685 | + |
| 686 | + |
615 | 687 | def test_view_regional_secret_labels(
|
616 | 688 | capsys: pytest.LogCaptureFixture,
|
617 | 689 | project_id: str,
|
|
0 commit comments