Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed composite primaryIdentifier validation #604

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/rpdk/core/data_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def get_file_base_uri(file):


def _is_in(schema, key):
def contains(values):
return set(values).issubset(set(schema.get(key, [])))
def contains(value):
return value in schema.get(key, [])

return contains
Comment on lines 94 to 98
Copy link
Contributor

@PatMyron PatMyron Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a weird layer of misdirection to have this function returning functions rather than just a function that takes all 3 parameters or ideally just directly checking:

primary_id in resource_spec.get("readOnlyProperties", [])
primary_id in resource_spec.get("createOnlyProperties", [])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is closure, i'd keep it in case we need to reuse or enhance the logic

Copy link
Contributor

@PatMyron PatMyron Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just seems unnecessary when the check is a one-liner with or without that function and more straightforward without


Expand All @@ -116,12 +116,15 @@ def load_resource_spec(resource_spec_file): # noqa: C901
in_readonly = _is_in(resource_spec, "readOnlyProperties")
in_createonly = _is_in(resource_spec, "createOnlyProperties")

primary_id = resource_spec["primaryIdentifier"]
if not in_readonly(primary_id) and not in_createonly(primary_id):
LOG.warning(
"Property 'primaryIdentifier' must be specified \
as either readOnly or createOnly"
)
primary_ids = resource_spec["primaryIdentifier"]

for primary_id in primary_ids:
if not in_readonly(primary_id) and not in_createonly(primary_id):
LOG.warning(
"Property 'primaryIdentifier' - %s must be specified \
as either readOnly or createOnly",
primary_id,
)

# TODO: more general validation framework
if "remote" in resource_spec:
Expand Down