Skip to content
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

Merged
merged 9 commits into from
Jun 4, 2020
Merged

Custom s3 endpoint support #28

merged 9 commits into from
Jun 4, 2020

Conversation

pitscher
Copy link
Contributor

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.

Copy link
Contributor

@ryu-sato ryu-sato left a 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
Copy link
Member

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?

Copy link
Contributor Author

@pitscher pitscher May 28, 2020

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"
Copy link
Member

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...

Copy link
Contributor Author

@pitscher pitscher May 28, 2020

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

@pitscher
Copy link
Contributor Author

As mentioned here: #28 (comment)
I updated a few things like the name of the new ENDPOINT env var and renamed "s3" to "S3".
Now all should be fine. 🤓

@pitscher pitscher requested a review from skomma May 28, 2020 14:41
@pitscher
Copy link
Contributor Author

pitscher commented Jun 1, 2020

Hi guys,
could you give me an update regarding my last changes? 😃

Copy link
Contributor

@ryu-sato ryu-sato left a 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...

  1. Change the input example of AWSCLI_ENDPOINT_OPT to "--endpoint-url fra1.digitaloceanspaces.com".
  2. In functions.sh, if AWSCLI_ENDPOINT_OPT exists, pass "--endpoint-url $AWSCLI_ENDPOINT_OPT" to aws options.
  3. 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
  • 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)> \ ]

@pitscher
Copy link
Contributor Author

pitscher commented Jun 2, 2020

Thank you for the feedback 😃
I've implemented what you requested. Hopefully this correspond to your 2. policy.

@pitscher pitscher requested a review from ryu-sato June 2, 2020 20:36
Copy link
Contributor

@ryu-sato ryu-sato left a 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
Comment on lines 22 to 27
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Comment on lines 37 to 42
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Comment on lines 52 to 57
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Comment on lines 75 to 79
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
Copy link
Contributor

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.

Suggested change
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

@pitscher
Copy link
Contributor Author

pitscher commented Jun 3, 2020

Of course. Good point! This should finally be what you expected.
Thank you for this sleek tip. I mean... I created the PR and you invested a bunch of your time so far.
But I appreciate your help. I learned a lot during this PR. 😄

@pitscher pitscher requested a review from ryu-sato June 3, 2020 19:04
Copy link
Contributor

@ryu-sato ryu-sato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ryu-sato ryu-sato merged commit d7e690f into weseek:master Jun 4, 2020
@pitscher pitscher deleted the custom-s3-endpoint-support branch June 4, 2020 16:53
@ryu-sato ryu-sato linked an issue Jun 4, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support for custom s3 endpoints
3 participants