Skip to content

Commit

Permalink
chore: sync static and templates for mobile attribute (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
iromli committed Mar 16, 2022
1 parent 1bf5a30 commit 8df0478
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docker-jans-persistence-loader/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN pip3 install -U pip wheel \
# jans-linux-setup sync
# =====================

ENV JANS_LINUX_SETUP_VERSION=452ce0fc0132f6ac7fd3be4a20bab560b1586dea
ENV JANS_LINUX_SETUP_VERSION=5b7fd274230c160d470ef76495d333cab1ae3b2a
ARG JANS_SETUP_DIR=jans-linux-setup/jans_setup

# note that as we're pulling from a monorepo (with multiple project in it)
Expand Down
1 change: 1 addition & 0 deletions docker-jans-persistence-loader/scripts/spanner_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def column_from_array(table_name, col_name):
("jansClnt", "jansDefAcrValues"),
("jansClnt", "jansLogoutURI"),
("jansPerson", "role"),
("jansPerson", "mobile"),
]:
column_to_array(mod[0], mod[1])

Expand Down
1 change: 1 addition & 0 deletions docker-jans-persistence-loader/scripts/sql_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def column_from_json(table_name, col_name):
("jansClnt", "jansDefAcrValues"),
("jansClnt", "jansLogoutURI"),
("jansPerson", "role"),
("jansPerson", "mobile"),
]:
column_to_json(mod[0], mod[1])

Expand Down
46 changes: 35 additions & 11 deletions docker-jans-persistence-loader/scripts/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
from collections import namedtuple

from ldif import LDIFParser

from jans.pycloudlib.persistence.couchbase import get_couchbase_user
from jans.pycloudlib.persistence.couchbase import get_couchbase_superuser
from jans.pycloudlib.persistence.couchbase import get_couchbase_password
Expand Down Expand Up @@ -172,8 +174,6 @@ def modify_claims(claims):


def collect_claim_names(ldif_file="/app/templates/attributes.ldif"):
from ldif import LDIFParser

rows = {}
with open("/app/templates/attributes.ldif", "rb") as fd:
parser = LDIFParser(fd)
Expand Down Expand Up @@ -631,11 +631,35 @@ def update_auth_dynamic_config(self):
self.backend.modify_entry(entry.id, entry.attrs, **kwargs)

def update_attributes_entries(self):
# default to ldap persistence
kwargs = {}
rows = collect_claim_names()
def _update_claim_names():
# default to ldap persistence
kwargs = {}
rows = collect_claim_names()

for id_, claim_name in rows.items():
if self.backend.type in ("sql", "spanner"):
id_ = doc_id_from_dn(id_)
kwargs = {"table_name": "jansAttr"}
elif self.backend.type == "couchbase":
id_ = id_from_dn(id_)
kwargs = {"bucket": os.environ.get("CN_COUCHBASE_BUCKET_PREFIX", "jans")}

entry = self.backend.get_entry(id_, **kwargs)

if not entry:
return

# jansClaimName already set
if "jansClaimName" in entry.attrs and entry.attrs["jansClaimName"]:
continue

entry.attrs["jansClaimName"] = claim_name
self.backend.modify_entry(entry.id, entry.attrs, **kwargs)

def _update_mobile_attr():
kwargs = {}
id_ = "inum=6DA6,ou=attributes,o=jans"

for id_, claim_name in rows.items():
if self.backend.type in ("sql", "spanner"):
id_ = doc_id_from_dn(id_)
kwargs = {"table_name": "jansAttr"}
Expand All @@ -648,12 +672,12 @@ def update_attributes_entries(self):
if not entry:
return

# jansClaimName already set
if "jansClaimName" in entry.attrs and entry.attrs["jansClaimName"]:
continue
if not entry.attrs.get("jansMultivaluedAttr"):
entry.attrs["jansMultivaluedAttr"] = True
self.backend.modify_entry(entry.id, entry.attrs, **kwargs)

entry.attrs["jansClaimName"] = claim_name
self.backend.modify_entry(entry.id, entry.attrs, **kwargs)
_update_claim_names()
_update_mobile_attr()

def update_base_entries(self):
# default to ldap persistence
Expand Down

0 comments on commit 8df0478

Please sign in to comment.