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

feat(jans-pycloudlib): handle rdbm_json_column in schema definitions #8359

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions jans-pycloudlib/jans/pycloudlib/persistence/spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def _transform_value(self, key: str, values: _t.Any) -> _t.Any:
"""
type_ = self.sql_data_types.get(key, {})

if not type_:
type_ = self.sql_json_types.get(key, {})

if not type_:
attr_syntax = self.get_attr_syntax(key)
type_ = self.sql_data_types_mapping[attr_syntax]
Expand Down
22 changes: 19 additions & 3 deletions jans-pycloudlib/jans/pycloudlib/persistence/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def doc_id_from_dn(dn: str) -> str:

if doc_id == "jans":
doc_id = "_"
return doc_id
return doc_id # noqa: R504


class SqlSchemaMixin:
Expand All @@ -180,11 +180,10 @@ class SqlSchemaMixin:
@property
def schema_files(self) -> list[str]:
"""Get list of schema files."""
files = [
return [
"/app/schema/jans_schema.json",
"/app/schema/custom_schema.json",
]
return files

@cached_property
def sql_data_types(self) -> dict[str, dict[str, _t.Any]]:
Expand Down Expand Up @@ -221,6 +220,20 @@ def opendj_attr_types(self) -> dict[str, str]:
with open("/app/static/rdbm/opendj_attributes_syntax.json") as f:
return json.loads(f.read()) # type: ignore

@cached_property
def sql_json_types(self):
json_types = {}
for attr_type in self.attr_types:
for attr in attr_type["names"]:
if not attr_type.get("rdbm_json_column"):
continue
json_types[attr] = {
"mysql": {"type": "JSON"},
"pgsql": {"type": "JSONB"},
"spanner": {"type": "ARRAY<STRING(MAX)>"},
}
return json_types

def get_attr_syntax(self, attr: str) -> str:
"""Get attribute syntax.

Expand Down Expand Up @@ -460,6 +473,9 @@ def _transform_value(self, key: str, values: _t.Any) -> _t.Any:
"""
type_ = self.sql_data_types.get(key, {})

if not type_:
type_ = self.sql_json_types.get(key, {})

if not type_:
attr_syntax = self.get_attr_syntax(key)
type_ = self.sql_data_types_mapping[attr_syntax]
Expand Down