Skip to content

Commit 7be3aef

Browse files
committed
Yet another round of fixes
Signed-off-by: Alina Buzachis <abuzachis@redhat.com>
1 parent 86c5a5b commit 7be3aef

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bugfixes:
2-
- "amazon.cloud - Add the original option name as an alias to avoid issues when snake cased option names are not correctly reversed to the original CamelCase."
2+
- "amazon.cloud - Add the original option name as an alias to avoid issues when snake cased option names are not correctly reversed to CamelCase."
33
- "amazon.cloud - Update cleanup documentation function."
44
- "amazon.cloud - Add some temporary workarounds for 'AWS::RDS::DBInstance' resource."

plugins/action/generate_cloud_modules.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ def gen_mutually_exclusive(schema: Dict) -> List:
470470
primary_idenfifier = schema.get("primaryIdentifier", [])
471471
entries: List = []
472472

473-
_primary_idenfifier = [camel_to_snake(id, alias=False) for id in primary_idenfifier]
473+
_primary_idenfifier = [
474+
camel_to_snake(id.split("/")[-1], alias=False) for id in primary_idenfifier
475+
]
474476

475477
if len(_primary_idenfifier) > 1:
476478
entries.append([tuple(_primary_idenfifier), "identifier"])
@@ -480,19 +482,20 @@ def gen_mutually_exclusive(schema: Dict) -> List:
480482

481483
def ensure_all_identifiers_defined(schema: Dict) -> str:
482484
primary_idenfifier = schema.get("primaryIdentifier", [])
485+
_primary_idenfifier = [item.split("/")[-1] for item in primary_idenfifier]
483486
new_content: str = "if state in ('present', 'absent', 'get', 'describe') and module.params.get('identifier') is None:\n"
484487
new_content += 8 * " "
485488
new_content += (
486-
f"if not module.params.get('{camel_to_snake(primary_idenfifier[0], alias=False)}')"
489+
f"if not module.params.get('{camel_to_snake(_primary_idenfifier[0])}')"
487490
+ " ".join(
488491
map(
489-
lambda x: f" or not module.params.get('{camel_to_snake(x, alias=False)}')",
490-
primary_idenfifier[1:],
492+
lambda x: f" or not module.params.get('{camel_to_snake(x)}')",
493+
_primary_idenfifier[1:],
491494
)
492495
)
493496
)
494497
new_content += ":\n" + 12 * " "
495-
new_content += "module.fail_json(f'You must specify all the {*[camel_to_snake(id, alias=False) for id in identifier], } identifiers.')\n"
498+
new_content += f'module.fail_json("You must specify all the {*[camel_to_snake(id) for id in _primary_idenfifier], } identifiers.")\n'
496499
497500
return new_content
498501
@@ -522,7 +525,7 @@ def gen_required_if(schema: Union[List, Dict]) -> List:
522525
states = ["absent", "get"]
523526
524527
_primary_idenfifier = [
525-
camel_to_snake(id, alias=False) for id in primary_idenfifier
528+
camel_to_snake(id.split("/")[-1], alias=False) for id in primary_idenfifier
526529
]
527530
528531
# For compound primary identifiers consisting of multiple resource properties strung together,
@@ -1253,7 +1256,7 @@ def generate_amazon_cloud(args: Iterable, role_path: str):
12531256
meta_dir = pathlib.Path(args.get("target_dir") + "/meta")
12541257
meta_dir.mkdir(parents=True, exist_ok=True)
12551258
yaml_dict = {
1256-
"requires_ansible": """>=2.12.0""",
1259+
"requires_ansible": """>=2.13.0""",
12571260
"action_groups": {"aws": []},
12581261
"plugin_routing": {"modules": {}},
12591262
}

plugins/action/generate_cloud_schema.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,15 @@ class Schema(TypedDict):
2424
definitions: Optional[Dict]
2525
required: Optional[List]
2626
primaryIdentifier: List
27-
# Resource properties that can be returned by a read or list request, but can't be set by the user.
2827
readOnlyProperties: Optional[List]
29-
# Resource properties that can be specified by the user only during resource creation.
3028
createOnlyProperties: Optional[List]
31-
# Resource properties that can be specified by the user, but can't be returned by a read or list request.
32-
# Write-only properties are often used to contain passwords, secrets, or other sensitive data.
33-
writeOnlyProperties: Optional[List]
34-
# Resource properties that have been deprecated by the underlying service provider.
35-
# These properties are still accepted in create and update operations.
36-
# However they may be ignored, or converted to a consistent model on application.
37-
# Deprecated properties are not guaranteed to be returned by read operations.
38-
deprecatedProperties: Optional[List]
3929
taggable: Optional[bool]
4030
handlers: Optional[Dict]
4131

4232

4333
def generate_schema(raw_content) -> Dict:
4434
json_content = json.loads(raw_content)
4535
schema: Dict[str, Schema] = json_content
46-
47-
for key, value in schema.items():
48-
if key not in ("anyOf", "oneOf"):
49-
if isinstance(value, list):
50-
elems = []
51-
for v in value:
52-
if isinstance(v, list):
53-
elems.extend([p.split("/")[-1].strip() for p in v])
54-
else:
55-
elems.append(v.split("/")[-1].strip())
56-
57-
schema[key] = elems
58-
5936
return schema
6037

6138

plugins/plugin_utils/cloud_utils/generator.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,13 @@ def replace_keys(self, options: Iterable, definitions: Iterable):
141141
"""Sanitize module's options and replace $ref with the correspoding parameters"""
142142
dict_copy = copy.copy(options)
143143
for key in dict_copy.keys():
144-
# The 'AWS::RDS::DBInstance' template has a bug for Port option which is classified as
145-
# createOnlyProperties, writeOnlyProperties and a readOnlyProperties, but it can be set
146-
# and it should not be filtered out from the documentation. This is a temporary workaround.
147-
if self.type_name != "AWS::RDS::DBInstance":
148-
if (
149-
key in self.read_only_properties
150-
and key not in self.primary_identifier
151-
):
152-
options.pop(key)
153-
continue
144+
key_path = f"/properties/{key}"
145+
if (
146+
key_path in self.read_only_properties
147+
and key_path not in self.primary_identifier
148+
):
149+
options.pop(key)
150+
continue
154151

155152
item = options[key]
156153

@@ -231,6 +228,31 @@ def cleanup_required(self, a_dict: Iterable):
231228

232229
self.cleanup_required(a_dict[k])
233230

231+
def cleanup_readonly_properties(self):
232+
options = copy.deepcopy(self.options)
233+
234+
def _cleanup_readonly_properties(nested_dict, key_list):
235+
if not key_list:
236+
return nested_dict
237+
key = key_list[0]
238+
if key in nested_dict:
239+
if len(key_list) == 1:
240+
return nested_dict.pop(key, None)
241+
else:
242+
return _cleanup_readonly_properties(
243+
nested_dict[key]["suboptions"], key_list[1:]
244+
)
245+
else:
246+
return None
247+
248+
for item in self.read_only_properties:
249+
opt = item.split("/")
250+
_cleanup_readonly_properties(options, opt[2:])
251+
# Remove option entirely if all the suboptions have been removed
252+
if options.get(opt[2]) and options.pop(opt[2]).get("suboptions", {}) == {}:
253+
options.pop(opt[2])
254+
return options
255+
234256
def preprocess(self) -> Iterable:
235257
list_of_keys_to_remove = [
236258
"additionalProperties",
@@ -252,9 +274,9 @@ def preprocess(self) -> Iterable:
252274
"maxProperties",
253275
"anyOf",
254276
]
255-
256277
self.replace_keys(self.options, self.definitions)
257278
self.cleanup_required(self.options)
279+
self.options = self.cleanup_readonly_properties()
258280
sanitized_options: Iterable = camel_to_snake(
259281
scrub_keys(self.options, list_of_keys_to_remove)
260282
)
@@ -302,8 +324,6 @@ def generate_documentation(
302324
docs.options = module.schema.get("properties", {})
303325
docs.definitions = module.schema.get("definitions", {})
304326

305-
docs.type_name = module.schema.get("typeName")
306-
307327
# Properties defined as required must be specified in the desired state during resource creation
308328
docs.required = module.schema.get("required", [])
309329

roles/module_openapi_cloud/templates/module_directory/amazon_cloud/default_module.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848
module.params["tags"]
4949
)
5050

51-
# Use the alis from argument_spec as key and avoid snake_to_camel conversions
51+
# Use the alias from argument_spec as key and avoid snake_to_camel conversions
5252
params_to_set = map_key_to_alias(_params_to_set, argument_spec)
5353

5454
# Ignore createOnlyProperties that can be set only during resource creation

0 commit comments

Comments
 (0)