Skip to content
Open
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
12 changes: 10 additions & 2 deletions build/simple/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


FROM python:3.11.4-slim as base
FROM python:3.11.14-slim as base

ARG ENV
ARG PIP_DISABLE_PIP_VERSION_CHECK=1
Expand All @@ -26,4 +26,12 @@ COPY simple/ .
COPY build/simple/run.sh .

RUN pip3 install -r /workspace/requirements.txt
CMD ./run.sh

RUN pip3 install --upgrade \
pip \
setuptools \
"wheel==0.46.2" \
"urllib3==2.6.3" \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

CMD ./run.sh
4 changes: 2 additions & 2 deletions simple/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ numpy==1.25.2
pandas==2.1.0
parameterized==0.9.0
platformdirs==3.10.0
protobuf==4.25.3
protobuf==6.33.5
PyLD==2.0.4
PyMySQL==1.1.0
PyMySQL==1.1.1
python-dateutil==2.8.2
pytest==7.4.2
PyYAML==6.0.1
Expand Down
28 changes: 27 additions & 1 deletion simple/util/dc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,35 @@ def get_api_root():
return os.environ.get(_API_ROOT_ENV, _DEFAULT_API_ROOT)


def mask_key(key: str, show: int = 5, max_visible_percent: float = 0.3) -> str:
"""Masks a key for logging purposes, showing only parts of it.

Args:
key: The string key to mask.
show: The number of characters to show from each end of the key.
max_visible_percent: The maximum percentage of the key's length that can be
visible from both ends combined.

Returns:
A masked string of the key.
"""
if not key:
return ""

length = len(key)
max_visible = int(length * max_visible_percent)
visible_each_side = min(show, max_visible // 2)

if visible_each_side < 1 or length <= visible_each_side * 2:
return "*" * length

middle = "*" * (length - visible_each_side * 2)
return f"{key[:visible_each_side]}{middle}{key[-visible_each_side:]}"
Comment thread
DevVegeta marked this conversation as resolved.


if _DEBUG:
logging.info("DC API Root: %s", get_api_root())
logging.info("DC API Key: %s", get_api_key())
logging.info("DC API Key: %s", mask_key(get_api_key()))
os.makedirs(_DEBUG_FOLDER, exist_ok=True)


Expand Down