26
26
config_file = 'configuration_governance_v1.env'
27
27
28
28
# Variables to hold link values
29
+ account_id = os .getenv ("ACCOUNT_ID" )
30
+ rule_label = os .getenv ("RULE_LABEL" ) or "sdk-it"
31
+ resource_group_id = os .getenv ("RESOURCE_GROUP_ID" )
32
+
29
33
rule_attachment_id_link = None
30
34
rule_id_link = None
31
35
36
+ rule_etag = None
37
+ rule_attachment_etag = None
38
+
32
39
class TestConfigurationGovernanceV1 ():
33
40
"""
34
41
Integration Test Class for ConfigurationGovernanceV1
@@ -56,26 +63,18 @@ def setup_class(cls):
56
63
@needscredentials
57
64
def test_create_rules (self ):
58
65
59
- # Construct a dict representation of a TargetResourceAdditionalTargetAttributesItem model
60
- target_resource_additional_target_attributes_item_model = {
61
- 'name' : 'resource_id' ,
62
- 'value' : '81f3db5e-f9db-4c46-9de3-a4a76e66adbf' ,
63
- 'operator' : 'string_equals' ,
64
- }
65
-
66
66
# Construct a dict representation of a TargetResource model
67
67
target_resource_model = {
68
- 'service_name' : 'iam-groups' ,
69
- 'resource_kind' : 'service' ,
70
- 'additional_target_attributes' : [target_resource_additional_target_attributes_item_model ],
68
+ 'service_name' : 'cloud-object-storage' ,
69
+ 'resource_kind' : 'bucket' ,
71
70
}
72
71
73
72
# Construct a dict representation of a RuleRequiredConfigSingleProperty model
74
73
rule_required_config_model = {
75
74
'description' : 'Public access check' ,
76
- 'property' : 'public_access_enabled ' ,
77
- 'operator' : 'is_true ' ,
78
- 'value' : 'testString ' ,
75
+ 'property' : 'location ' ,
76
+ 'operator' : 'string_equals ' ,
77
+ 'value' : 'us-south ' ,
79
78
}
80
79
81
80
# Construct a dict representation of a EnforcementAction model
@@ -85,20 +84,20 @@ def test_create_rules(self):
85
84
86
85
# Construct a dict representation of a RuleRequest model
87
86
rule_request_model = {
88
- 'account_id' : '531fc3e28bfc43c5a2cea07786d93f5c' ,
87
+ 'account_id' : account_id ,
89
88
'name' : 'Disable public access' ,
90
89
'description' : 'Ensure that public access to account resources is disabled.' ,
91
90
'rule_type' : 'user_defined' ,
92
- 'target' : { 'service_name' : 'iam-groups' , 'resource_kind' : 'service' } ,
93
- 'required_config' : { 'description' : 'Public access check' , 'and' :[{ 'property' : 'public_access_enabled' , 'operator' : 'is_false' }]} ,
91
+ 'target' : target_resource_model ,
92
+ 'required_config' : rule_required_config_model ,
94
93
'enforcement_actions' : [enforcement_action_model ],
95
- 'labels' : ['Access' , 'IAM' ],
94
+ 'labels' : [rule_label ],
96
95
}
97
96
98
97
# Construct a dict representation of a CreateRuleRequest model
99
98
create_rule_request_model = {
100
99
'request_id' : '3cebc877-58e7-44a5-a292-32114fa73558' ,
101
- 'rule' : { 'account_id' : '531fc3e28bfc43c5a2cea07786d93f5c' , 'name' : 'Disable public access' , 'description' : 'Ensure that public access to account resources is disabled.' , 'labels' :[ 'Access' , 'IAM' ], 'target' :{ 'service_name' : 'iam-groups' , 'resource_kind' : 'service' }, 'required_config' :{ 'description' : 'Public access check' , 'and' :[{ 'property' : 'public_access_enabled' , 'operator' : 'is_false' }]}, 'enforcement_actions' :[{ 'action' : 'disallow' },{ 'action' : 'audit_log' }]} ,
100
+ 'rule' : rule_request_model ,
102
101
}
103
102
104
103
create_rules_response = self .configuration_governance_service .create_rules (
@@ -119,16 +118,22 @@ def test_create_rule_attachments(self):
119
118
120
119
# Construct a dict representation of a RuleScope model
121
120
rule_scope_model = {
122
- 'note' : 'My enterprise' ,
123
- 'scope_id' : '282cf433ac91493ba860480d92519990' ,
124
- 'scope_type' : 'enterprise' ,
121
+ 'note' : 'My account' ,
122
+ 'scope_id' : account_id ,
123
+ 'scope_type' : 'account' ,
124
+ }
125
+
126
+ rule_excluded_scope_model = {
127
+ 'note' : 'My account resource group' ,
128
+ 'scope_id' : resource_group_id ,
129
+ 'scope_type' : 'account.resource_group' ,
125
130
}
126
131
127
132
# Construct a dict representation of a RuleAttachmentRequest model
128
133
rule_attachment_request_model = {
129
- 'account_id' : '531fc3e28bfc43c5a2cea07786d93f5c' ,
130
- 'included_scope' : { 'note' : 'My enterprise' , 'scope_id' : '282cf433ac91493ba860480d92519990' , 'scope_type' : 'enterprise' } ,
131
- 'excluded_scopes' : [rule_scope_model ],
134
+ 'account_id' : account_id ,
135
+ 'included_scope' : rule_scope_model ,
136
+ 'excluded_scopes' : [rule_excluded_scope_model ],
132
137
}
133
138
134
139
create_rule_attachments_response = self .configuration_governance_service .create_rule_attachments (
@@ -149,10 +154,10 @@ def test_create_rule_attachments(self):
149
154
def test_list_rules (self ):
150
155
151
156
list_rules_response = self .configuration_governance_service .list_rules (
152
- account_id = '531fc3e28bfc43c5a2cea07786d93f5c' ,
157
+ account_id = account_id ,
153
158
transaction_id = 'testString' ,
154
159
attached = True ,
155
- labels = 'SOC2,ITCS300' ,
160
+ labels = [ rule_label ] ,
156
161
scopes = 'scope_id' ,
157
162
limit = 1000 ,
158
163
offset = 38
@@ -174,47 +179,42 @@ def test_get_rule(self):
174
179
rule = get_rule_response .get_result ()
175
180
assert rule is not None
176
181
182
+ global rule_etag
183
+ rule_etag = get_rule_response .headers ['etag' ]
184
+
177
185
@needscredentials
178
186
def test_update_rule (self ):
179
187
180
- # Construct a dict representation of a TargetResourceAdditionalTargetAttributesItem model
181
- target_resource_additional_target_attributes_item_model = {
182
- 'name' : 'testString' ,
183
- 'value' : 'testString' ,
184
- 'operator' : 'string_equals' ,
185
- }
186
-
187
188
# Construct a dict representation of a TargetResource model
188
189
target_resource_model = {
189
- 'service_name' : 'iam-groups' ,
190
- 'resource_kind' : 'service' ,
191
- 'additional_target_attributes' : [target_resource_additional_target_attributes_item_model ],
190
+ 'service_name' : 'cloud-object-storage' ,
191
+ 'resource_kind' : 'bucket' ,
192
192
}
193
193
194
194
# Construct a dict representation of a RuleRequiredConfigSingleProperty model
195
195
rule_required_config_model = {
196
196
'description' : 'testString' ,
197
- 'property' : 'public_access_enabled ' ,
198
- 'operator' : 'is_false ' ,
199
- 'value' : 'testString ' ,
197
+ 'property' : 'location ' ,
198
+ 'operator' : 'string_equals ' ,
199
+ 'value' : 'us-south ' ,
200
200
}
201
201
202
202
# Construct a dict representation of a EnforcementAction model
203
203
enforcement_action_model = {
204
- 'action' : 'audit_log ' ,
204
+ 'action' : 'disallow ' ,
205
205
}
206
206
207
207
update_rule_response = self .configuration_governance_service .update_rule (
208
208
rule_id = rule_id_link ,
209
- if_match = 'testString' ,
209
+ if_match = rule_etag ,
210
210
name = 'Disable public access' ,
211
211
description = 'Ensure that public access to account resources is disabled.' ,
212
- target = { 'service_name' : 'iam-groups' , 'resource_kind' : 'service' , 'additional_target_attributes' :[]} ,
213
- required_config = { 'property' : 'public_access_enabled' , 'operator' : 'is_false' } ,
212
+ target = target_resource_model ,
213
+ required_config = rule_required_config_model ,
214
214
enforcement_actions = [enforcement_action_model ],
215
- account_id = '531fc3e28bfc43c5a2cea07786d93f5c' ,
215
+ account_id = account_id ,
216
216
rule_type = 'user_defined' ,
217
- labels = ['SOC2' , 'ITCS300' ],
217
+ labels = [rule_label ],
218
218
transaction_id = 'testString'
219
219
)
220
220
@@ -249,23 +249,32 @@ def test_get_rule_attachment(self):
249
249
rule_attachment = get_rule_attachment_response .get_result ()
250
250
assert rule_attachment is not None
251
251
252
+ global rule_attachment_etag
253
+ rule_attachment_etag = get_rule_attachment_response .headers ['etag' ]
254
+
252
255
@needscredentials
253
256
def test_update_rule_attachment (self ):
254
257
255
258
# Construct a dict representation of a RuleScope model
256
259
rule_scope_model = {
257
- 'note' : 'My enterprise' ,
258
- 'scope_id' : '282cf433ac91493ba860480d92519990' ,
259
- 'scope_type' : 'enterprise' ,
260
+ 'note' : 'My account' ,
261
+ 'scope_id' : account_id ,
262
+ 'scope_type' : 'account' ,
263
+ }
264
+
265
+ excluded_scope_model = {
266
+ 'note' : 'My account resource group' ,
267
+ 'scope_id' : resource_group_id ,
268
+ 'scope_type' : 'account.resource_group' ,
260
269
}
261
270
262
271
update_rule_attachment_response = self .configuration_governance_service .update_rule_attachment (
263
272
rule_id = rule_id_link ,
264
273
attachment_id = rule_attachment_id_link ,
265
- if_match = 'testString' ,
266
- account_id = '531fc3e28bfc43c5a2cea07786d93f5c' ,
267
- included_scope = { 'note' : 'My enterprise' , 'scope_id' : '282cf433ac91493ba860480d92519990' , 'scope_type' : 'enterprise' } ,
268
- excluded_scopes = [rule_scope_model ],
274
+ if_match = rule_attachment_etag ,
275
+ account_id = account_id ,
276
+ included_scope = rule_scope_model ,
277
+ excluded_scopes = [excluded_scope_model ],
269
278
transaction_id = 'testString'
270
279
)
271
280
0 commit comments