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: modify clnId column type #3459

Merged
merged 3 commits into from
Jan 2, 2023
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
4 changes: 2 additions & 2 deletions docker-jans-auth-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RUN /opt/jython/bin/pip uninstall -y pip
# ===========

ENV CN_VERSION=1.0.6-SNAPSHOT
ENV CN_BUILD_DATE='2022-12-25 08:14'
ENV CN_BUILD_DATE='2022-12-29 08:15'
ENV CN_SOURCE_URL=https://jenkins.jans.io/maven/io/jans/jans-auth-server/${CN_VERSION}/jans-auth-server-${CN_VERSION}.war

# Install Jans Auth
Expand Down Expand Up @@ -118,7 +118,7 @@ RUN mkdir -p ${JETTY_BASE}/jans-auth/agama/fl \
${JETTY_BASE}/jans-auth/agama/scripts

# janssenproject/jans SHA commit
ENV JANS_SOURCE_VERSION=bd2cdf8501d60959498078bbb31650965c321c73
ENV JANS_SOURCE_VERSION=d95fc492ca00ccee0ecc88132376c128203faefb

# 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 agama code
Expand Down
4 changes: 2 additions & 2 deletions docker-jans-config-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RUN wget -q https://maven.jans.io/maven/io/jans/jython-installer/${JYTHON_VERSIO
# ==========

ENV CN_VERSION=1.0.6-SNAPSHOT
ENV CN_BUILD_DATE='2022-12-25 08:17'
ENV CN_BUILD_DATE='2022-12-29 11:35'
ENV CN_SOURCE_URL=https://jenkins.jans.io/maven/io/jans/jans-config-api-server/${CN_VERSION}/jans-config-api-server-${CN_VERSION}.war

# Install Jans Config API
Expand Down Expand Up @@ -110,7 +110,7 @@ COPY conf/prometheus-config.yaml /opt/prometheus/
# jans-linux-setup sync
# =====================

ENV JANS_SOURCE_VERSION=bd2cdf8501d60959498078bbb31650965c321c73
ENV JANS_SOURCE_VERSION=d95fc492ca00ccee0ecc88132376c128203faefb
ARG JANS_SETUP_DIR=jans-linux-setup/jans_setup
ARG JANS_CONFIG_API_RESOURCES=jans-config-api/server/src/main/resources

Expand Down
4 changes: 2 additions & 2 deletions docker-jans-fido2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ EXPOSE 8080
# =====

ENV CN_VERSION=1.0.6-SNAPSHOT
ENV CN_BUILD_DATE='2022-12-25 08:15'
ENV CN_BUILD_DATE='2022-12-29 08:50'
ENV CN_SOURCE_URL=https://jenkins.jans.io/maven/io/jans/jans-fido2-server/${CN_VERSION}/jans-fido2-server-${CN_VERSION}.war

# Install FIDO2
Expand All @@ -54,7 +54,7 @@ RUN mkdir -p ${JETTY_BASE}/jans-fido2/webapps \
# jans-linux-setup sync
# =====================

ENV JANS_SOURCE_VERSION=bd2cdf8501d60959498078bbb31650965c321c73
ENV JANS_SOURCE_VERSION=d95fc492ca00ccee0ecc88132376c128203faefb
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
2 changes: 1 addition & 1 deletion docker-jans-monolith/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EXPOSE 443 8080 1636
# jans-linux-setup
# =====================

ENV JANS_SOURCE_VERSION=bd2cdf8501d60959498078bbb31650965c321c73
ENV JANS_SOURCE_VERSION=d95fc492ca00ccee0ecc88132376c128203faefb

# cleanup
RUN rm -rf /tmp/jans
Expand Down
2 changes: 1 addition & 1 deletion docker-jans-persistence-loader/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN python3 -m ensurepip \
# =====================

# janssenproject/jans SHA commit
ENV JANS_SOURCE_VERSION=bd2cdf8501d60959498078bbb31650965c321c73
ENV JANS_SOURCE_VERSION=d95fc492ca00ccee0ecc88132376c128203faefb
ARG JANS_SETUP_DIR=jans-linux-setup/jans_setup
ARG JANS_SCRIPT_CATALOG_DIR=docs/script-catalog
ARG JANS_CONFIG_API_RESOURCES=jans-config-api/server/src/main/resources
Expand Down
4 changes: 4 additions & 0 deletions docker-jans-persistence-loader/scripts/spanner_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ def column_int_to_string(table_name, col_name):
for mod in [
("jansPerson", "jansMobileDevices"),
("jansPerson", "jansOTPDevices"),
("jansToken", "clnId"),
("jansUmaRPT", "clnId"),
("jansUmaPCT", "clnId"),
("jansCibaReq", "clnId"),
]:
column_from_array(mod[0], mod[1])

Expand Down
32 changes: 29 additions & 3 deletions docker-jans-persistence-loader/scripts/sql_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from string import Template
from pathlib import Path

from sqlalchemy import text
from sqlalchemy.exc import OperationalError

from jans.pycloudlib.persistence.sql import SqlClient
Expand Down Expand Up @@ -322,9 +323,28 @@ def column_from_json(table_name, col_name):
for row in self.client.search(table_name, ["doc_id", col_name])
}

# to change the storage format of a JSON column, drop the column and
# add the column back specifying the new storage format
with self.client.engine.connect() as conn:
# mysql will raise error if dropping column which has functional index,
# hence the associated index must be dropped first
if self.client.dialect == "mysql":
for idx in conn.execute(
text(
"SELECT index_name "
"FROM information_schema.statistics "
"WHERE table_name = :table_name "
"AND index_name LIKE :index_name '%' "
"AND expression LIKE '%' :col_name '%';"
),
{
"table_name": table_name,
"index_name": f"{table_name}_json_",
"col_name": col_name
},
):
conn.execute(f"ALTER TABLE {table_name} DROP INDEX {idx[0]}")

# to change the storage format of a JSON column, drop the column and
# add the column back specifying the new storage format
conn.execute(f"ALTER TABLE {self.client.quoted_id(table_name)} DROP COLUMN {self.client.quoted_id(col_name)}")
conn.execute(f"ALTER TABLE {self.client.quoted_id(table_name)} ADD COLUMN {self.client.quoted_id(col_name)} {data_type}")

Expand All @@ -333,8 +353,10 @@ def column_from_json(table_name, col_name):

# pre-populate the modified column
for doc_id, value in values.items():
if value and "v" in value and value["v"]:
if self.client.dialect == "mysql" and value and value.get("v", []):
new_value = value["v"][0]
elif self.client.dialect == "pgsql" and value:
new_value = value[0]
else:
new_value = ""
self.client.update(table_name, doc_id, {col_name: new_value})
Expand Down Expand Up @@ -427,6 +449,10 @@ def column_from_json(table_name, col_name):
for mod in [
("jansPerson", "jansMobileDevices"),
("jansPerson", "jansOTPDevices"),
("jansToken", "clnId"),
("jansUmaRPT", "clnId"),
("jansUmaPCT", "clnId"),
("jansCibaReq", "clnId"),
]:
column_from_json(mod[0], mod[1])

Expand Down
4 changes: 2 additions & 2 deletions docker-jans-scim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN wget -q https://maven.jans.io/maven/io/jans/jython-installer/${JYTHON_VERSIO
# ====

ENV CN_VERSION=1.0.6-SNAPSHOT
ENV CN_BUILD_DATE='2022-12-25 08:16'
ENV CN_BUILD_DATE='2022-12-29 11:33'
ENV CN_SOURCE_URL=https://jenkins.jans.io/maven/io/jans/jans-scim-server/${CN_VERSION}/jans-scim-server-${CN_VERSION}.war

# Install SCIM
Expand Down Expand Up @@ -80,7 +80,7 @@ COPY conf/prometheus-config.yaml /opt/prometheus/
# jans-linux-setup sync
# =====================

ENV JANS_SOURCE_VERSION=bd2cdf8501d60959498078bbb31650965c321c73
ENV JANS_SOURCE_VERSION=d95fc492ca00ccee0ecc88132376c128203faefb
ARG JANS_SETUP_DIR=jans-linux-setup/jans_setup
ARG JANS_SCIM_RESOURCE_DIR=jans-scim/server/src/main/resources

Expand Down
34 changes: 18 additions & 16 deletions jans-pycloudlib/jans/pycloudlib/persistence/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def __init__(self, manager: Manager, *args: _t.Any, **kwargs: _t.Any) -> None:
self.adapter = MysqlAdapter()

self.dialect = self.adapter.dialect
self._metadata: _t.Optional[MetaData] = None

@cached_property
def engine(self) -> Engine:
Expand All @@ -274,24 +275,25 @@ def engine_url(self) -> str:
password = get_sql_password(self.manager)
return f"{self.adapter.connector}://{user}:{password}@{host}:{port}/{database}"

@cached_property
@property
def metadata(self) -> MetaData:
"""Lazy init of metadata."""
with warnings.catch_warnings():
# postgresql driver will show warnings about unsupported reflection
# on expression-based index, i.e. `lower(uid::text)`; but we don't
# want to clutter the logs with these warnings, hence we suppress the
# warnings
warnings.filterwarnings(
"ignore",
message="Skipped unsupported reflection of expression-based index",
category=SAWarning,
)

# do reflection on database table
metadata = MetaData(bind=self.engine)
metadata.reflect()
return metadata
if not self._metadata:
with warnings.catch_warnings():
# postgresql driver will show warnings about unsupported reflection
# on expression-based index, i.e. `lower(uid::text)`; but we don't
# want to clutter the logs with these warnings, hence we suppress the
# warnings
warnings.filterwarnings(
"ignore",
message="Skipped unsupported reflection of expression-based index",
category=SAWarning,
)

# do reflection on database table
self._metadata = MetaData(bind=self.engine)
self._metadata.reflect()
return self._metadata

def connected(self) -> bool:
"""Check whether connection is alive by executing simple query."""
Expand Down