Skip to content
Snippets Groups Projects
Commit f8e8599a authored by kosted's avatar kosted
Browse files

version with upload

parent 89da94cc
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,15 @@ def init():
else:
print("[INFO] Personal user info is not found")
refresh()
###########################
# Refresh token and save #
###########################
def refresh():
email = input("Your email: ")
#password
password = input("Your password: ")
......@@ -58,8 +67,6 @@ def init():
generate_token(email, password)
###########################
# Generate token and save #
###########################
......@@ -114,11 +121,37 @@ def upload(sourceFile, destination):
print("[INFO] Destination file is : ", destination)
if sourceFile and destination:
print("[INFO] Get an existing or fresh token")
init()
print("[INFO] Get an existing or fresh token")
#Generate or get a token
init()
with open(USER_INFO_FILE_PATH) as json_file:
userinfo = json.load(json_file)
#Get the info
token=userinfo['token']
print("[INFO] Starting retrieving the presigned url for the creation of the file with token "+ token)
#files = {'upload_file': open(sourceFile,'rb')}
url = "https://gravitee-gateway."+MAAP_ENV_TYPE.lower()+".esa-maap.org/s3/"+destination
response = requests.put(url, headers = {'Authorization': 'Bearer '+token}, allow_redirects=False)
location = response.headers['Location']
print("[INFO] Location is "+ location)
if location:
print("[INFO] Start uploading the file")
files = {'file': open(sourceFile, 'rb')}
r = requests.post(location, files=files)
print(r)
else:
print("[ERROR] Presigned url not generated. Please re run refresh or contact admin if the error persist")
else:
display_help()
# Store argument variable omitting the script name
argv = sys.argv[1:]
......
hello world
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment