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

annofab visualize_statistics : コマンドライン引数で渡されたAnnofabの認証情報をマスクしてログに出力する #213

Merged
merged 4 commits into from
May 30, 2024
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
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ format:
poetry run ruff check ${SOURCE_FILES} ${TEST_FILES} --fix-only --exit-zero

lint:
poetry run ruff check ${SOURCE_FILES}
# テストコードはチェックを緩和する
# pygrep-hooks, flake8-datetimez, line-too-long, flake8-annotations, unused-noqa
poetry run ruff check ${TEST_FILES} --ignore PGH,DTZ,E501,ANN,RUF100
poetry run ruff check ${SOURCE_FILES} ${TEST_FILES}
# テストコードはチェックを緩和するためmypy, pylintは実行しない
poetry run mypy ${SOURCE_FILES}
poetry run pylint --jobs=0 ${SOURCE_FILES}
Expand Down
22 changes: 21 additions & 1 deletion annoworkcli/annofab/visualize_statistics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import copy
import datetime
import logging
import subprocess
Expand Down Expand Up @@ -129,6 +130,8 @@ def get_annofab_labor_list(
end_date=end_date,
is_set_additional_info=True,
)
else:
raise RuntimeError("`job_id_list`と`annofab_project_id_list`の両方がNoneです。")

if len(actual_working_time_list) == 0:
return []
Expand Down Expand Up @@ -160,6 +163,23 @@ def get_annofab_labor_list(
return result


def mask_credential_in_command(command: list[str]) -> list[str]:
"""
コマンドのリストに含まれている認証情報を、`***`に置き換えてマスクします。

Args:
command: 実行するコマンドのリスト(変更されません)
"""
tmp_command = copy.deepcopy(command)
for masked_option in ["--annofab_user_id", "--annofab_password", "--mfa_code"]:
try:
index = tmp_command.index(masked_option)
tmp_command[index + 1] = "***"
except ValueError:
continue
return tmp_command


def visualize_statistics(temp_dir: Path, args): # noqa: ANN001, ANN201
annowork_service = build_annoworkapi(args)
job_id_list = get_list_from_args(args.job_id)
Expand Down Expand Up @@ -217,7 +237,7 @@ def visualize_statistics(temp_dir: Path, args): # noqa: ANN001, ANN201
if args.annofabcli_options is not None:
command.extend(args.annofabcli_options)

str_command = " ".join(command)
str_command = " ".join(mask_credential_in_command(command))
logger.debug(f"run command: {str_command}")
subprocess.run(command, check=True)

Expand Down
2 changes: 1 addition & 1 deletion annoworkcli/schedule/delete_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(

self.all_yes = all_yes

def delete_schedule( # noqa: PLR0912
def delete_schedule(
self, schedule_ids: Collection[str], *, target_user_ids: Optional[Collection[str]] = None, target_job_ids: Optional[Collection[str]] = None
) -> None:
all_jobs = self.annowork_service.api.get_jobs(self.workspace_id)
Expand Down
Loading