Skip to content

Commit

Permalink
feat(jans-pycloudlib): handle rdbm_json_column in schema definitions (#…
Browse files Browse the repository at this point in the history
…8359)

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

Signed-off-by: iromli <[email protected]>

* fix(jans-pycloudlib): handle data type while parsing data from LDIF file

Signed-off-by: iromli <[email protected]>

---------

Signed-off-by: iromli <[email protected]>
  • Loading branch information
iromli authored Apr 22, 2024
1 parent 1b6bb3e commit 19f0deb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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

0 comments on commit 19f0deb

Please sign in to comment.