Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maap-s3-laptop
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esa-common
maap-s3-laptop
Commits
f8e8599a
Commit
f8e8599a
authored
4 years ago
by
kosted
Browse files
Options
Downloads
Patches
Plain Diff
version with upload
parent
89da94cc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
maap-s3.py
+37
-4
37 additions, 4 deletions
maap-s3.py
toto.txt
+1
-0
1 addition, 0 deletions
toto.txt
with
38 additions
and
4 deletions
maap-s3.py
+
37
−
4
View file @
f8e8599a
...
...
@@ -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
:]
...
...
This diff is collapsed.
Click to expand it.
toto.txt
0 → 100644
+
1
−
0
View file @
f8e8599a
hello world
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment