-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom s3 endpoint support #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your contributions.
Could you use the word "S3" instead of "s3" in README.md?
functions.sh LGTM.
bin/functions.sh
Outdated
@@ -19,7 +20,7 @@ DATE_CMD="/bin/date" | |||
# arguments: 1. s3 url (s3://.../...) | |||
s3_exists() { | |||
if [ $# -ne 1 ]; then return 255; fi | |||
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null | |||
${AWSCLI} ${AWSCLI_ENDPOINT_URL_OPTION} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWSCLI_ENDPOINT_URL_OPTION
will be set like fra1.digitaloceanspaces.com
, so --endpoint-url
is needed here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's important to set the whole aws cli parameter "--endpoint-url https://domain.tld".
It is easier to implement this way because if a user wanna use the default S3 endpoint the only thing he must ensure is to not set the AWSCLI_ENDPOINT_OPT var. That's it. 😃
@@ -1,5 +1,6 @@ | |||
# default settings | |||
AWSCLI="/usr/bin/aws" | |||
#AWSCLI_ENDPOINT_URL_OPTION="--endpoint-url <YourEndpointUrl>" | |||
AWSCLI_COPY_OPT="s3 cp" | |||
AWSCLI_LIST_OPT="s3 ls" | |||
AWSCLI_DEL_OPT="s3 rm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since AWSCLIOPT
is already provided, I think you can do the same thing by using this environment variable without adding AWSCLI_ENDPOINT_URL_OPTION
.
Unfortunately, currently AWSCLIOPT
is not documented...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To provide the ability to use the default endpoint or a custom one and not over engineer the code we should use a new env var. Therefore I introduced AWSCLI_ENDPOINT_OPT
As mentioned here: #28 (comment) |
Hi guys, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing the usage and implementation of AWSCLI_ENDPOINT_OPT, README.md lists "fra1.digitaloceanspaces.com" in the input example, but functions.sh expects user to specify "--endpoint-url" as in "--endpoint-url fra1.digitaloceanspaces.com", so you need to match two.
How to modify it...
- Change the input example of AWSCLI_ENDPOINT_OPT to "--endpoint-url fra1.digitaloceanspaces.com".
- In functions.sh, if AWSCLI_ENDPOINT_OPT exists, pass "--endpoint-url $AWSCLI_ENDPOINT_OPT" to
aws
options. - Delete AWSCLI_ENDPOINT_OPT from README.md and functions.sh, and describe "--endpoint-url fra1.digitaloceanspaces.com" as an example of AWSCLIOPT input.
1 is unacceptable because the name AWSCLI_ENDPOINT_OPT is different from the actual behavior because it allows user to specify an AWS option other than "--endpoint-url".
2 is closer to the current implementation than 3, so can you modify it with this policy?
Also, please modify the following points in the README (If you chose policy 2)
- Make the input example of AWSCLI_ENDPOINT_OPT into a URL
- ex. "AWSCLI_ENDPOINT_OPT="https://fra1.digitaloceanspaces.com"
- Add AWSCLI_ENDPOINT_OPT to the three docker run command execution examples in Usage
- ex.
[ -e AWSCLI_ENDPOINT_OPT=<S3 endpoint URL (ex. https://fra1.digitaloceanspaces.com)> \ ]
- ex.
Thank you for the feedback 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want the code to be DRY.
It is better not to use if
many times according to the value of AWSCLI_ENDPOINT_OPT.
If you set it to a variable beforehand, you don't have to repeat using if
.
In addition to the suggestions I commented on, please add the following to line 6 of "bin/functions.sh"
AWSCLI_ENDPOINT_OPT=${AWSCLI_ENDPOINT_OPT:+"--endpoint-url ${AWSCLI_ENDPOINT_OPT}"}
bin/functions.sh
Outdated
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | ||
then | ||
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null | ||
else | ||
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | |
then | |
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null | |
else | |
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null | |
fi | |
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null |
bin/functions.sh
Outdated
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | ||
then | ||
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 | ||
else | ||
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | |
then | |
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 | |
else | |
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 | |
fi | |
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 |
bin/functions.sh
Outdated
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | ||
then | ||
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1 | ||
else | ||
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | |
then | |
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1 | |
else | |
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1 | |
fi | |
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1 |
bin/functions.sh
Outdated
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | ||
then | ||
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2 | ||
else | ||
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no "fi" on line 80 and it is a syntax error.
if [ -z "$AWSCLI_ENDPOINT_OPT" ] | |
then | |
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2 | |
else | |
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2 | |
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2 |
Of course. Good point! This should finally be what you expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
As mentioned in #27 this is the PR for supporting custom s3 endpoints.
I successfully ran the e2e script for AWS (because noting GCP related was changed).
If you don't set the new env var AWSCLI_ENDPOINT_URL_OPTION the default s3 endpoint will be used.
If you set the var, the provided endpoint will be used. That's it. No rocket science. 😄
BTW: I updated the README as well.