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

fix: scan docs/script-catalog for custom scripts #2533

Merged
merged 1 commit into from
Oct 3, 2022
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
9 changes: 6 additions & 3 deletions docker-jans-persistence-loader/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ RUN python3 -m ensurepip \
# =====================

# janssenproject/jans SHA commit
ENV JANS_SOURCE_VERSION=8128244d16f212b9c687540ded6cb349abe4aafc
ENV JANS_SOURCE_VERSION=4fa83fcc3f298d91be3cb459bca52417aacd368e
ARG JANS_SETUP_DIR=jans-linux-setup/jans_setup
ARG JANS_SCRIPT_CATALOG_DIR=docs/script-catalog

# note that as we're pulling from a monorepo (with multiple project in it)
# we are using partial-clone and sparse-checkout to get the jans-linux-setup code
RUN git clone --filter blob:none --no-checkout https://github.com/janssenproject/jans /tmp/jans \
&& cd /tmp/jans \
&& git sparse-checkout init --cone \
&& git checkout ${JANS_SOURCE_VERSION} \
&& git sparse-checkout set ${JANS_SETUP_DIR}
&& git sparse-checkout add ${JANS_SETUP_DIR} \
&& git sparse-checkout add ${JANS_SCRIPT_CATALOG_DIR}

RUN mkdir -p /app/static /app/static/couchbase /app/schema /app/openbanking/static /app/static/opendj

Expand All @@ -46,7 +48,8 @@ RUN cd /tmp/jans \
&& cp -R ${JANS_SETUP_DIR}/static/rdbm /app/static/rdbm \
&& cp ${JANS_SETUP_DIR}/schema/jans_schema.json /app/schema/jans_schema.json \
&& cp ${JANS_SETUP_DIR}/schema/custom_schema.json /app/schema/custom_schema.json \
&& cp ${JANS_SETUP_DIR}/static/opendj/index.json /app/static/opendj/index.json
&& cp ${JANS_SETUP_DIR}/static/opendj/index.json /app/static/opendj/index.json \
&& cp -R ${JANS_SCRIPT_CATALOG_DIR} /app/script-catalog

RUN mkdir -p /app/templates/jans-config-api

Expand Down
23 changes: 12 additions & 11 deletions docker-jans-persistence-loader/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,21 @@ def merge_extension_ctx(ctx: dict[str, _t.Any]) -> dict[str, _t.Any]:
:param ctx: A key-value pairs of existing contexts.
:returns: Merged contexts.
"""
basedir = "/app/static/extension"

if os.environ.get("CN_DISTRIBUTION", "default") == "openbanking":
basedir = "/app/openbanking/static/extension"
basedirs = ["/app/openbanking/static/extension"]
else:
basedirs = ["/app/static/extension", "/app/script-catalog"]

filepath = Path(basedir)
for ext_path in filepath.glob("**/*"):
if not ext_path.is_file() or ext_path.suffix.lower() not in (".py", ".java"):
continue
for basedir in basedirs:
filepath = Path(basedir)
for ext_path in filepath.glob("**/*"):
if not ext_path.is_file() or ext_path.suffix.lower() not in (".py", ".java"):
continue

ext_type = ext_path.relative_to(filepath).parent.as_posix().lower().replace(os.path.sep, "_")
ext_name = ext_path.stem.lower()
script_name = f"{ext_type}_{ext_name}"
ctx[script_name] = generate_base64_contents(ext_path.read_text())
ext_type = ext_path.relative_to(filepath).parent.as_posix().lower().replace(os.path.sep, "_").replace("-", "_")
ext_name = ext_path.stem.lower()
script_name = f"{ext_type}_{ext_name}"
ctx[script_name] = generate_base64_contents(ext_path.read_text())
return ctx


Expand Down