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

chore: log all HTTP requests, get rid of --dump flag (DEV-3171) #731

Merged
merged 10 commits into from
Jan 12, 2024
6 changes: 1 addition & 5 deletions src/dsp_tools/cli/call_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def _call_ingest_xmlupload(args: argparse.Namespace) -> bool:
password=args.password,
dsp_url=args.server,
sipi_url=args.sipi_url,
dump=args.dump,
)
return True

Expand Down Expand Up @@ -202,7 +201,7 @@ def _call_xmlupload(args: argparse.Namespace) -> bool:
password=args.password,
imgdir=args.imgdir,
sipi=args.sipi_url,
config=UploadConfig(diagnostics=DiagnosticsConfig(verbose=args.verbose, dump=args.dump)),
config=UploadConfig(diagnostics=DiagnosticsConfig(verbose=args.verbose)),
)


Expand All @@ -214,7 +213,6 @@ def _call_get(args: argparse.Namespace) -> bool:
user=args.user,
password=args.password,
verbose=args.verbose,
dump=args.dump,
)


Expand All @@ -230,7 +228,6 @@ def _call_create(args: argparse.Namespace) -> bool:
server=args.server,
user=args.user,
password=args.password,
dump=args.dump,
)
case False, True:
success = validate_project(args.project_definition)
Expand All @@ -242,6 +239,5 @@ def _call_create(args: argparse.Namespace) -> bool:
user_mail=args.user,
password=args.password,
verbose=args.verbose,
dump=args.dump,
)
return success
4 changes: 0 additions & 4 deletions src/dsp_tools/cli/create_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ def _add_ingest_xmlupload(
subparser.add_argument("-s", "--server", default=default_dsp_api_url, help=dsp_server_text)
subparser.add_argument("-u", "--user", default=root_user_email, help=username_text)
subparser.add_argument("-p", "--password", default=root_user_pw, help=password_text)
subparser.add_argument("-d", "--dump", action="store_true", help="write every request to DSP-API/SIPI into a file")
subparser.add_argument("xml_file", help="path to XML file containing the data")


Expand Down Expand Up @@ -267,7 +266,6 @@ def _add_xmlupload(
"-V", "--validate-only", action="store_true", help="validate the XML file without uploading it"
)
subparser.add_argument("-v", "--verbose", action="store_true", help=verbose_text)
subparser.add_argument("-d", "--dump", action="store_true", help="write every request to DSP-API/SIPI into a file")
subparser.add_argument("xmlfile", help="path to the XML file containing the data")


Expand All @@ -287,7 +285,6 @@ def _add_get(
subparser.add_argument("-p", "--password", default=root_user_pw, help=password_text)
subparser.add_argument("-P", "--project", help="shortcode, shortname or IRI of the project", required=True)
subparser.add_argument("-v", "--verbose", action="store_true", help=verbose_text)
subparser.add_argument("-d", "--dump", action="store_true", help="write every request to DSP-API into a file")
subparser.add_argument("project_definition", help="path to the file the project should be written to")


Expand Down Expand Up @@ -319,5 +316,4 @@ def _add_create(
help="create only the lists (prerequisite: the project exists on the server)",
)
subparser.add_argument("-v", "--verbose", action="store_true", help=verbose_text)
subparser.add_argument("-d", "--dump", action="store_true", help="write every request to DSP-API into a file")
subparser.add_argument("project_definition", help="path to the JSON project file")
6 changes: 2 additions & 4 deletions src/dsp_tools/commands/ingest_xmlupload/upload_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
get_mapping_dict_from_file,
replace_filepath_with_sipi_id,
)
from dsp_tools.commands.xmlupload.upload_config import DiagnosticsConfig, UploadConfig
from dsp_tools.commands.xmlupload.upload_config import UploadConfig
from dsp_tools.commands.xmlupload.xmlupload import xmlupload
from dsp_tools.models.exceptions import InputError
from dsp_tools.utils.create_logger import get_logger
Expand All @@ -23,7 +23,6 @@ def ingest_xmlupload(
password: str,
dsp_url: str,
sipi_url: str,
dump: bool = False,
) -> None:
"""
This function reads an XML file
Expand All @@ -39,7 +38,6 @@ def ingest_xmlupload(
password: the user's password for login into DSP
dsp_url: URL to the DSP server
sipi_url: URL to the Sipi server
dump: if True, write every request to DSP-API/SIPI into a file

Raises:
InputError: if any media was not uploaded or uploaded media was not referenced.
Expand Down Expand Up @@ -68,5 +66,5 @@ def ingest_xmlupload(
password=password,
imgdir=".",
sipi=sipi_url,
config=UploadConfig(media_previously_uploaded=True, diagnostics=DiagnosticsConfig(dump=dump)),
config=UploadConfig(media_previously_uploaded=True),
)
4 changes: 1 addition & 3 deletions src/dsp_tools/commands/project/create/project_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,6 @@ def create_project(
user_mail: str,
password: str,
verbose: bool = False,
dump: bool = False,
) -> bool:
"""
Creates a project from a JSON project file on a DSP server.
Expand All @@ -1006,7 +1005,6 @@ def create_project(
user_mail: a username (e-mail) who has the permission to create a project
password: the user's password
verbose: prints more information if set to True
dump: if True, write every request to DSP-API into a file

Raises:
UserError:
Expand Down Expand Up @@ -1049,7 +1047,7 @@ def create_project(
)

# establish connection to DSP server
con = ConnectionLive(server, dump=dump)
con = ConnectionLive(server)
con.login(user_mail, password)

# create project on DSP server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def create_lists(
server: str,
user: str,
password: str,
dump: bool = False,
) -> tuple[dict[str, Any], bool]:
"""
This method accepts a JSON project definition,
Expand All @@ -151,7 +150,6 @@ def create_lists(
server: URL of the DSP server
user: Username (e-mail) for the DSP server, must have the permissions to create a project
password: Password of the user
dump: if True, write every request to DSP-API into a file

Raises:
UserError:
Expand Down Expand Up @@ -184,7 +182,7 @@ def create_lists(
print("JSON project file is syntactically correct and passed validation.")

# connect to the DSP server
con = ConnectionLive(server, dump=dump)
con = ConnectionLive(server)
con.login(user, password)

# retrieve the project
Expand Down
4 changes: 1 addition & 3 deletions src/dsp_tools/commands/project/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def get_project(
user: str | None = None,
password: str | None = None,
verbose: bool = False,
dump: bool = False,
) -> bool:
"""
This function writes a project from a DSP server into a JSON file.
Expand All @@ -32,15 +31,14 @@ def get_project(
user: the user (e-mail) who sends the request
password: the password of the user who sends the request
verbose: verbose option for the command, if used more output is given to the user
dump: if True, write every request to DSP-API into a file

Raises:
BaseError: if something went wrong

Returns:
True if the process finishes without errors
"""
con = ConnectionLive(server=server, dump=dump)
con = ConnectionLive(server)
if user and password:
try:
con.login(user, password)
Expand Down
1 change: 0 additions & 1 deletion src/dsp_tools/commands/rosetta.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def _create_json(rosetta_folder: Path) -> bool:
user_mail="root@example.com",
password="test",
verbose=False,
dump=False,
)


Expand Down
1 change: 0 additions & 1 deletion src/dsp_tools/commands/xmlupload/upload_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class DiagnosticsConfig:
"""Configures all diagnostics for a given upload."""

verbose: bool = False
dump: bool = False
server_as_foldername: str = "unknown"
save_location: Path = field(default=Path.home() / ".dsp-tools" / "xmluploads")
timestamp_str: str = field(default=datetime.now().strftime("%Y-%m-%d_%H%M%S"))
Expand Down
4 changes: 2 additions & 2 deletions src/dsp_tools/commands/xmlupload/xmlupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def xmlupload(
)

# establish connection to DSP server
con = ConnectionLive(server, dump=config.diagnostics.dump)
con = ConnectionLive(server)
con.login(user, password)
sipi_con = ConnectionLive(sipi, dump=config.diagnostics.dump, token=con.get_token())
sipi_con = ConnectionLive(sipi, token=con.get_token())
sipi_server = Sipi(sipi_con)

ontology_client = OntologyClientLive(
Expand Down