import requests import os import sys arg_b = None arg_a = None action = None def load_env(): global auth_username, auth_password, arg_a, arg_b, action auth_username = os.environ.get('REGISTRY_AUTH_USERNAME') auth_password = os.environ.get('REGISTRY_AUTH_PASSWORD') args = sys.argv[1:] action = args[0] if len(args) > 0 else None arg_a = args[1] if len(args) > 1 else None arg_b = args[2] if len(args) > 2 else None print (action) def validate_args(missing_a_example, missing_b_example): if not arg_a: print (missing_a_example) exit if not missing_b_example and not arg_b: print (missing_b_example) exit def upload(): validate_args("./file-to-upload", "https://git.limbosolutions.com/api/packages/generic///") files = {"file": open(arg_a, "rb")} with open(arg_a, "rb") as f: r = requests.put(arg_b, data=f, auth=(auth_username, auth_password)) r.raise_for_status() print("file uploaded!!") def download(): validate_args("https://git.limbosolutions.com/api/packages/generic///", "./target-download-file") file = requests.get(arg_a, auth = (auth_username, auth_password)) file.raise_for_status() open(arg_b, 'wb').write(file.content) print("file downloaded!!") def delete(): validate_args("https://git.limbosolutions.com/api/packages/generic///") response = requests.delete(arg_a, auth = (auth_username, auth_password)) response.raise_for_status() print("file deleted!!") load_env() if action == "upload": upload() elif action == "download": download() elif action == "delete": delete() else : print ("invalid option upload|download|delete")