Skip to content

Commit

Permalink
Drop /statement/ from login and api1 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
raulikak committed Apr 30, 2024
1 parent 5a79dd1 commit 5f2ce9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
17 changes: 6 additions & 11 deletions tcsfw/client_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run_get_key(self, args: argparse.Namespace):
base_url = f"{u.scheme}://{u.netloc}"
path = urlunparse(('', '', u.path, u.params, u.query, u.fragment))

login_url = f"{base_url}/login/statement{path}"
login_url = f"{base_url}/login/{path}"
self.logger.info("Getting API key from %s", login_url)
headers = {"X-User": user_name} # Only in development, when missing authenticator from between
resp = requests.get(login_url, timeout=self.timeout, auth=(user_name, user_password), headers=headers,
Expand Down Expand Up @@ -144,11 +144,6 @@ def run_upload(self, args: argparse.Namespace):
if not url:
raise ValueError("Missing server URL")

u = urlparse(url)
base_url = f"{u.scheme}://{u.netloc}"
path = urlunparse(('', '', u.path, u.params, u.query, u.fragment))
use_url = f"{base_url}/statement{path}"

self.force_upload = args.force_upload or False
if self.dry_run:
self.logger.warning("DRY RUN, no files will be uploaded")
Expand All @@ -160,23 +155,23 @@ def run_upload(self, args: argparse.Namespace):
read_file = pathlib.Path(args.read)
if read_file.is_dir():
# uploading data from directory with meta-files in place
self.upload_directory(use_url, read_file)
self.upload_directory(url, read_file)
else:
# uploading single file
if not meta_json:
raise ValueError("Missing upload meta-data")
self.logger.info("Uploading %s to %s...", read_file.as_posix(), use_url)
self.logger.info("Uploading %s to %s...", read_file.as_posix(), url)
with read_file.open('rb') as f:
self.upload_file(use_url, f, meta_json)
self.upload_file(url, f, meta_json)

else:
# uploading from stdin
if not meta_json:
raise ValueError("Missing upload meta-data")
if "from_pipe" not in meta_json:
meta_json["from_pipe"] = True # tell server that file name carries no meaning
self.logger.info("Uploading to %s...", use_url)
self.upload_file(use_url, sys.stdin.buffer, meta_json)
self.logger.info("Uploading to %s...", url)
self.upload_file(url, sys.stdin.buffer, meta_json)
self.logger.info("upload complete")

def upload_file(self, url: str, file_data: BinaryIO, meta_json: Dict):
Expand Down
8 changes: 2 additions & 6 deletions tcsfw/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ async def handle_login(self, request: web.Request):
if request.method != "GET":
raise NotImplementedError("Unexpected method")
use_api_key = False
if request.path.startswith("/login/statement/"):
app = request.path[17:]
elif request.path.startswith("/api1/proxy/statement/"):
# NOTE: Remove /statement/ parts at some point
app = request.path[22:]
use_api_key = True
if request.path.startswith("/login/"):
app = request.path[7:]
elif request.path.startswith("/api1/proxy/"):
app = request.path[12:]
use_api_key = True
Expand Down

0 comments on commit 5f2ce9b

Please sign in to comment.