Skip to content

Commit

Permalink
client: handle references in user config schema
Browse files Browse the repository at this point in the history
Currently the client is not able to deal with references in the user
config schema, but will throw key errors. This will improve the
situation by traversing the original object until the actual definition
is found
  • Loading branch information
alxric committed Aug 18, 2023
1 parent 698933d commit 959283d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aiven/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,28 @@ def add_args(self, parser: ArgumentParser) -> None:
help="Wait for up to N seconds for a response to a request (default: infinite)",
)

def _find_reference(self, obj_def: Mapping[str, Any], spec: Mapping[str, Any]) -> Optional[Mapping[str, Any]]:
ref_prefix = "#/definitions/"

if "definitions" not in obj_def:
return None
ref = spec["$ref"][len(ref_prefix) :]
return obj_def["definitions"][ref]

def collect_user_config_options(self, obj_def: Mapping[str, Any], prefixes: list[str] | None = None) -> dict[str, Any]:
opts = {}
for prop, spec in sorted(obj_def.get("properties", {}).items()):
full_prop = prefixes + [prop] if prefixes else [prop]
full_name = ".".join(full_prop)
if "type" not in spec:
# It is possible this is a reference, and if so we need to find the actual entry
if "$ref" in spec:
spec = self._find_reference(obj_def, spec)
elif "allOf" in spec:
for entry in spec["allOf"]:
spec = self._find_reference(obj_def, entry)
if not spec:
continue
types = spec["type"]
if not isinstance(types, list):
types = [types]
Expand Down

0 comments on commit 959283d

Please sign in to comment.