Skip to content

Commit

Permalink
Included credentials as validation method, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Shettland committed Oct 18, 2023
1 parent 3d04f77 commit 7d7aaea
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
69 changes: 58 additions & 11 deletions bu_isciii/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def new_service(ctx, resolution, path, no_create_folder, ask_path):
Create new service, it will create folder and copy template depending on selected service.
"""
new_ser = bu_isciii.new_service.NewService(
resolution, path, no_create_folder, ask_path, ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
path,
no_create_folder,
ask_path,
ctx.obj["api_user"],
ctx.obj["api_password"],
)
new_ser.create_new_service()

Expand Down Expand Up @@ -251,7 +256,13 @@ def scratch(ctx, resolution, path, tmp_dir, direction, ask_path):
Copy service folder to scratch directory for execution.
"""
scratch_copy = bu_isciii.scratch.Scratch(
resolution, path, tmp_dir, direction, ask_path, ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
path,
tmp_dir,
direction,
ask_path,
ctx.obj["api_user"],
ctx.obj["api_password"],
)
scratch_copy.handle_scratch()

Expand Down Expand Up @@ -302,7 +313,9 @@ def clean(ctx, resolution, path, ask_path, option):
Service cleaning. It will either remove big files, rename folders before copy, revert this renaming,
show removable files or show folders for no copy.
"""
clean = bu_isciii.clean.CleanUp(resolution, path, ask_path, option, ctx.obj["api_user"], ctx.obj["api_password"])
clean = bu_isciii.clean.CleanUp(
resolution, path, ask_path, option, ctx.obj["api_user"], ctx.obj["api_password"]
)
clean.handle_clean()


Expand Down Expand Up @@ -336,7 +349,12 @@ def copy_sftp(ctx, resolution, path, ask_path, sftp_folder):
Copy resolution FOLDER to sftp, change status of resolution in iskylims and generate md, pdf, html.
"""
new_del = bu_isciii.copy_sftp.CopySftp(
resolution, path, ask_path, sftp_folder, ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
path,
ask_path,
sftp_folder,
ctx.obj["api_user"],
ctx.obj["api_password"],
)
new_del.copy_sftp()

Expand Down Expand Up @@ -379,22 +397,43 @@ def finish(ctx, resolution, path, ask_path, sftp_folder, tmp_dir):
"""
print("Starting cleaning scratch directory: " + tmp_dir)
clean_scratch = bu_isciii.clean.CleanUp(
resolution, tmp_dir, ask_path, "clean", ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
tmp_dir,
ask_path,
"clean",
ctx.obj["api_user"],
ctx.obj["api_password"],
)
clean_scratch.handle_clean()
print("Starting copy from scratch directory: " + tmp_dir + " to service directory.")
copy_scratch2service = bu_isciii.scratch.Scratch(
resolution, path, tmp_dir, "Scratch_to_service", ask_path, ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
path,
tmp_dir,
"Scratch_to_service",
ask_path,
ctx.obj["api_user"],
ctx.obj["api_password"],
)
copy_scratch2service.handle_scratch()
print("Starting renaming of the service directory.")
rename_databi = bu_isciii.clean.CleanUp(
resolution, path, ask_path, "rename_nocopy", ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
path,
ask_path,
"rename_nocopy",
ctx.obj["api_user"],
ctx.obj["api_password"],
)
rename_databi.handle_clean()
print("Starting copy of the service directory to the SFTP folder")
copy_sftp = bu_isciii.copy_sftp.CopySftp(
resolution, path, ask_path, sftp_folder, ctx.obj["api_user"], ctx.obj["api_password"]
resolution,
path,
ask_path,
sftp_folder,
ctx.obj["api_user"],
ctx.obj["api_password"],
)
copy_sftp.copy_sftp()
print("Service correctly in SFTP folder")
Expand Down Expand Up @@ -454,7 +493,15 @@ def finish(ctx, resolution, path, ask_path, sftp_folder, tmp_dir):
)
@click.pass_context
def bioinfo_doc(
ctx, type, resolution, path, ask_path, sftp_folder, report_md, results_md, email_psswd
ctx,
type,
resolution,
path,
ask_path,
sftp_folder,
report_md,
results_md,
email_psswd,
):
"""
Create the folder documentation structure in bioinfo_doc server
Expand All @@ -467,7 +514,7 @@ def bioinfo_doc(
sftp_folder,
report_md,
results_md,
ctx.obj["api_user"],
ctx.obj["api_user"],
ctx.obj["api_password"],
email_psswd,
)
Expand Down Expand Up @@ -535,7 +582,7 @@ def archive(
service_file,
ser_type,
option,
ctx.obj["api_user"],
ctx.obj["api_user"],
ctx.obj["api_password"],
skip_prompts,
date_from,
Expand Down
2 changes: 1 addition & 1 deletion bu_isciii/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def rename(self, to_find, add, verbose=True):
path_content = self.scan_dirs(to_find=to_find)
unfiltered_path_content = [f.path for f in os.scandir(self.full_path)]
for directory_to_rename in path_content:
renamed_directory = str(directory_to_rename+add)
renamed_directory = str(directory_to_rename + add)
if renamed_directory in unfiltered_path_content:
stderr.print(
"[orange]WARNING: Directory %s already renamed to %s Omitting..."
Expand Down
12 changes: 8 additions & 4 deletions bu_isciii/drylab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, server, url, user, password):
self.request_url = server + url
self.headers = {
"accept": "application/json",
"Content-Type": "application/json"
"Content-Type": "application/json",
}
if not user:
stderr.print("[red]Missing user for api request")
Expand Down Expand Up @@ -87,7 +87,9 @@ def put_request(
def post_request(self, request_info, data, safe=True):
url_http = self.request_url + request_info
try:
req = requests.post(url_http, data=data, headers=self.headers, auth=self.auth)
req = requests.post(
url_http, data=data, headers=self.headers, auth=self.auth
)
if req.status_code > 201:
if safe:
log.error(
Expand All @@ -103,19 +105,21 @@ def post_request(self, request_info, data, safe=True):
log.error("Unable to open connection towards iSkyLIMS, aborting")
sys.exit(1)
return False

def basic_authentication(self):
# Pseudo-code for credentials validation, returns error 404 right now
from requests.auth import HTTPBasicAuth

user, password = self.auth[0], self.auth[1]
url_http = (self.request_url)
url_http = self.request_url
response = requests.get(url_http, auth=HTTPBasicAuth(user, password))
print("Response status code", response.status_code)
if response.status_code <= 200:
return True
else:
return False


""" Example usage
rest_api = RestServiceApi("http://localhost:8000/", "drylab/api/")
services_queue = rest_api.get_request("service/", "state", "queued")
Expand Down

0 comments on commit 7d7aaea

Please sign in to comment.