14
14
import os
15
15
16
16
import botocore .session
17
+ import pytest
17
18
18
19
from aws_encryption_sdk .key_providers .kms import KMSMasterKeyProvider
20
+ from aws_encryption_sdk .keyrings .aws_kms import KmsKeyring
19
21
20
22
AWS_KMS_KEY_ID = "AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID"
21
23
_KMS_MKP = None
22
24
_KMS_MKP_BOTO = None
25
+ _KMS_KEYRING = None
23
26
24
27
25
28
def get_cmk_arn ():
@@ -37,7 +40,7 @@ def get_cmk_arn():
37
40
38
41
39
42
def setup_kms_master_key_provider (cache = True ):
40
- """Reads the test_values config file and builds the requested KMS Master Key Provider."""
43
+ """Build an AWS KMS Master Key Provider."""
41
44
global _KMS_MKP # pylint: disable=global-statement
42
45
if cache and _KMS_MKP is not None :
43
46
return _KMS_MKP
@@ -53,7 +56,7 @@ def setup_kms_master_key_provider(cache=True):
53
56
54
57
55
58
def setup_kms_master_key_provider_with_botocore_session (cache = True ):
56
- """Reads the test_values config file and builds the requested KMS Master Key Provider with botocore_session."""
59
+ """Build an AWS KMS Master Key Provider with an explicit botocore_session."""
57
60
global _KMS_MKP_BOTO # pylint: disable=global-statement
58
61
if cache and _KMS_MKP_BOTO is not None :
59
62
return _KMS_MKP_BOTO
@@ -66,3 +69,29 @@ def setup_kms_master_key_provider_with_botocore_session(cache=True):
66
69
_KMS_MKP_BOTO = kms_master_key_provider
67
70
68
71
return kms_master_key_provider
72
+
73
+
74
+ def build_aws_kms_keyring (generate = True , cache = True ):
75
+ """Build an AWS KMS keyring."""
76
+ global _KMS_KEYRING # pylint: disable=global-statement
77
+ if cache and _KMS_KEYRING is not None :
78
+ return _KMS_KEYRING
79
+
80
+ cmk_arn = get_cmk_arn ()
81
+
82
+ if generate :
83
+ kwargs = dict (generator_key_id = cmk_arn )
84
+ else :
85
+ kwargs = dict (child_key_ids = [cmk_arn ])
86
+
87
+ keyring = KmsKeyring (** kwargs )
88
+
89
+ if cache :
90
+ _KMS_KEYRING = keyring
91
+
92
+ return keyring
93
+
94
+
95
+ @pytest .fixture
96
+ def aws_kms_keyring ():
97
+ return build_aws_kms_keyring ()
0 commit comments