Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christian Salzmann-Jaeckel
boto
Commits
054af246
Commit
054af246
authored
Aug 28, 2020
by
Christian Salzmann-Jaeckel
Browse files
add s3-public-download.py
parent
25623a09
Changes
2
Show whitespace changes
Inline
Side-by-side
s3-public-download.py
0 → 100755
View file @
054af246
#!/usr/bin/python3
import
os
import
logging
import
boto3
radosgw_access_key
=
os
.
environ
[
'AWS_ACCESS_KEY_ID'
]
radosgw_secret_key
=
os
.
environ
[
'AWS_SECRET_ACCESS_KEY'
]
radosgw_endpoint_url
=
'https://rise-s3.zib.de'
radosgw_bucket_name
=
'k8s-doc-bucket'
radosgw_key_name
=
'Using_Kubernetes_Secrets.pdf'
radosgw_file_name
=
'talk.pdf'
# generate s3 client
s3_client
=
boto3
.
client
(
's3'
,
endpoint_url
=
radosgw_endpoint_url
,
aws_access_key_id
=
radosgw_access_key
,
aws_secret_access_key
=
radosgw_secret_key
)
################################################################################
# check if bucket exists
bucket_exists
=
False
# Retrieve the list of existing buckets
response
=
s3_client
.
list_buckets
()
for
bucket
in
response
[
'Buckets'
]:
bucket_name
=
bucket
[
"Name"
]
if
(
bucket_name
==
radosgw_bucket_name
):
bucket_exists
=
True
# create bucket if not found
if
bucket_exists
==
False
:
print
(
f
"creating bucket '
{
radosgw_bucket_name
}
' …"
)
response
=
s3_client
.
create_bucket
(
Bucket
=
radosgw_bucket_name
,
ACL
=
'public-read'
)
# upload file
response
=
s3_client
.
upload_file
(
radosgw_file_name
,
radosgw_bucket_name
,
radosgw_key_name
,
ExtraArgs
=
{
'ACL'
:
'public-read'
}
)
print
(
f
"uploaded file to '
{
radosgw_endpoint_url
}
/
{
radosgw_bucket_name
}
/
{
radosgw_key_name
}
'."
)
talk.pdf
0 → 100644
View file @
054af246
File added
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment