Skip to content
Snippets Groups Projects
Commit f85674fc authored by test@test.test's avatar test@test.test
Browse files

BIOMASS-2785 update the maap s3 script to be able to use the new maap keycloak

parent 30375085
No related branches found
No related tags found
No related merge requests found
# maap-s3-laptop # maap-s3-laptop
This script is used to interact with the esa maap s3. This python script is used to interact with the esa maap s3.
The script is by default in the stack thei and Jupyter. The script is by default in the stack theia and Jupyter and can be used as a shell script.
But there are some differences. From you laptop you shoud prefix the script with the command 'python'.
****Theia**** ## Prerequisite
The shebang of the script must be replace by **#!/usr/local/bin/python** To use the script some env variables must be defined. Execute the command below from an eclipse che workspace to see the values you have to setup.
**Jupyter** ```shell:
The shebang of the script must be replace by **#!/opt/conda/bin/python** echo $MAAP_ENV_TYPE
echo $CLIENT_ID
echo $AUTH_ACCESS_TOKEN_URL
```
Check if you have request library, or install it if missing.
Maap S3 script ins the script used to interact with the bucket S3 to share data with others maap users or to save data when workspace is full. ## Info
Maap S3 script is the script used to interact with the bucket S3 to share data with others maap users or to save data when workspace is full.
Please dont forget the env variable token and maap_env_type Please dont forget the env variable token and maap_env_type
The script provide following features: The script provide following features:
...@@ -21,36 +27,38 @@ To see all options run maap-s3.py help ...@@ -21,36 +27,38 @@ To see all options run maap-s3.py help
param 1: sourceFile param 1: sourceFile
ex: /projects/test/toto.txt ex: /projects/test/toto.txt
param 2: s3 destination path param 2: s3 destination path
ex: bmap-catalogue-data/bmaap_test/tkossoko/obs.jar ex: maap-scientific-data/shared/test/tkossoko/obs.jar
exemple: maap-s3.py upload /projects/test/maap.tiff bmap-catalogue-data/bmaap_test/tkossoko/maap.tiff exemple: maap-s3.py upload /projects/test/maap.tiff maap-scientific-data/shared/test/tkossoko/maap.tiff
resume use to continue a failed multipart previous upload. When your file is more than 5Giga, the python script use multipart upload. During the process, if the upload fails, please run resume without parameter to continue the upload. resume use to continue a failed multipart previous upload. When your file is more than 5Giga, the python script use multipart upload. During the process, if the upload fails, please run resume without parameter to continue the upload.
**download to download a data from S3** **download to download a data from S3**
param 1: s3 path param 1: s3 path
ex: bmap-catalogue-data/bmaap_test/demo/maap.tiff ex: maap-scientific-data/shared/test/demo/maap.tiff
param 2: Workspace destination path param 2: Workspace destination path
ex: /projects/test/maap.tiff ex: /projects/test/maap.tiff
exemple: `maap-s3.py download bmap-catalogue-data/bmaap_test/tkossoko/maap.tiff /projects/test/maap.tiff` exemple: `maap-s3.py download maap-scientific-data/shared/test/tkossoko/maap.tiff /projects/test/maap.tiff`
**list to list a folder from S3** **list to list a folder from S3**
param 1: s3 bucket folder param 1: s3 bucket folder
ex: bmap-catalogue-data/bmaap_test/demo ex: maap-scientific-data/shared/test/demo
exemple: `maap-s3.py list bmap-catalogue-data/bmaap_test/demo` exemple: `maap-s3.py list maap-scientific-data/shared/test/demo`
exemple: `maap-s3.py list bmap-catalogue-data/Campaign_data`
**delete to delete a file from S3** **delete to delete a file from S3**
param 1: s3 file path param 1: s3 file path
ex: bmap-catalogue-data/bmaap_test/demo/maap.tiff ex: maap-scientific-data/shared/test/demo/maap.tiff
exemple: `maap-s3 delete bmap-catalogue-data/bmaap_test/demo/hello-bjorn.txt` exemple: `maap-s3 delete maap-scientific-data/shared/test/demo/hello-bjorn.txt`
**refresh to reset credentials and passwords when init fails because you type wrong password or email.** **refresh to reset credentials and passwords when init fails because you type wrong password or email.**
exemple: `maap-s3.py refresh` exemple: `maap-s3.py refresh`
**1- How to use the script ? **
To call the script, just type` maap-s3.py help` in the console. ## Info for the stacks
Check if you have request library, or install it if missing. ****Theia****
The shebang of the script must be replace by **#!/usr/local/bin/python**
Typing maap-s3.py help will show all options available and parameters or use the prefix 'python'
**Jupyter**
The shebang of the script must be replace by **#!/opt/conda/bin/python**
\ No newline at end of file
maap-s3.py 100644 → 100755
...@@ -14,14 +14,18 @@ import getpass ...@@ -14,14 +14,18 @@ import getpass
MAAP_ENV_TYPE = os.getenv("MAAP_ENV_TYPE") MAAP_ENV_TYPE = os.getenv("MAAP_ENV_TYPE")
CLIENT_ID = os.getenv("CLIENT_ID") CLIENT_ID = os.getenv("CLIENT_ID")
HOME = os.getenv("HOME")
#Url to retrieve the access token with the user credential
AUTH_ACCESS_TOKEN_URL = os.getenv("AUTH_ACCESS_TOKEN_URL")
BEARER="" BEARER=""
#if windows we take the current folder #if windows we take the current folder
if sys.platform == 'win32': if sys.platform == 'win32':
USER_INFO_FILE_PATH=os.getcwd()+"\maap-s3-userinfo.json" USER_INFO_FILE_PATH=os.getcwd()+"\maap-s3-userinfo.json"
USER_LAST_UPLOAD_INFO_FILE_PATH=os.getcwd()+"\maap-s3-multipartinfo.json" USER_LAST_UPLOAD_INFO_FILE_PATH=os.getcwd()+"\maap-s3-multipartinfo.json"
else : else :
USER_INFO_FILE_PATH="/projects/.maap/maap-s3-userinfo.json" USER_INFO_FILE_PATH=HOME+"/.maap/maap-s3-userinfo.json"
USER_LAST_UPLOAD_INFO_FILE_PATH="/projects/.maap/maap-s3-multipartinfo.json" USER_LAST_UPLOAD_INFO_FILE_PATH=HOME+"/.maap/maap-s3-multipartinfo.json"
userinfo = {} userinfo = {}
multipartinfo = {} multipartinfo = {}
...@@ -99,10 +103,10 @@ def generate_token(email, password): ...@@ -99,10 +103,10 @@ def generate_token(email, password):
print("[INFO] Start retrieving token for authent") print("[INFO] Start retrieving token for authent")
#Set the bearer #Set the bearer
url = "https://iam."+MAAP_ENV_TYPE.lower()+".esa-maap.org/oxauth/restv1/token" url = AUTH_ACCESS_TOKEN_URL
print (url) print (url)
print (CLIENT_ID) print (CLIENT_ID)
response = requests.post(url, data={'client_id': CLIENT_ID, 'username': email, 'password': password, "grant_type": "password", "scope": "openid+profile"}) response = requests.post(url, data={'client_id': CLIENT_ID, 'username': email, 'password': password, "grant_type": "password", "scope": "profile"})
print(response) print(response)
#Convert the string to json to fecth access_token #Convert the string to json to fecth access_token
data = json.loads(response.text) data = json.loads(response.text)
...@@ -136,8 +140,8 @@ def get_token(email, password): ...@@ -136,8 +140,8 @@ def get_token(email, password):
#print("[INFO] Start retrieving token for authent") #print("[INFO] Start retrieving token for authent")
#Set the bearer #Set the bearer
url = "https://iam."+MAAP_ENV_TYPE.lower()+".esa-maap.org/oxauth/restv1/token" url = AUTH_ACCESS_TOKEN_URL
response = requests.post(url, data={'client_id': CLIENT_ID, 'username': email, 'password': password, "grant_type": "password", "scope": "openid+profile"}) response = requests.post(url, data={'client_id': CLIENT_ID, 'username': email, 'password': password, "grant_type": "password", "scope": "profile"})
#Convert the string to json to fecth access_token #Convert the string to json to fecth access_token
data = json.loads(response.text) data = json.loads(response.text)
token = data['access_token'] token = data['access_token']
......
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