-
Notifications
You must be signed in to change notification settings - Fork 25
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
Switch to google-cloud-storage gem, delegate url(expires:)
to #presign
#16
Conversation
13d7b0b
to
d255155
Compare
Thanks 👍 I glanced over it and it looks great. I will do a deeper review later. Bumping to 0.3.0 is fine regarding to semver, as a major version of 0 means that anything can break I any time. I bump the minor version for changes breaking the API until we reach 1.0.0. And for this I would like to have more eyes / users on the code before declaring it stable (which may come soon, as it looks like this gems is starting to be used 😄) |
Also it might be worth it to look at #8 and try to get it working with this new implementation. |
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.
Here is my first pass.
As projects are easy to create on GCP, what would you think of creating a new project in your test setup script?
This would allow to namespace everything and not mess up with any already-existing project the user has configured. It also allows to easily cleanup everything by deleting the project.
The script can check if the project, SA and bucket exists and tell the user to either change the project name or delete it before running the script again.
It would also be a good idea to display what the script will do at the start (create project $project
, create bucket $bucket
, create $sa
service account, and ask the user if he is fine for this.
I may be paranoid, but my experience shows that it is a good idea to check everything before executing anything on a cloud console/API
@@ -1,2 +1,4 @@ | |||
.env | |||
pkg/ | |||
.ruby-gemset | |||
.ruby-version |
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.
Missing new line
acl: @default_acl | ||
) do |f| | ||
# update the additional options | ||
@object_options.merge(_options).each_pair do |key, value| |
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.
Rename to options
. The _
is a convention to indicate the argument is not used.
) | ||
end | ||
end | ||
|
||
# URL to the remote file, accepts options for customizing the URL | ||
def url(id, **_options) |
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.
Same for _options
end | ||
|
||
prefix = "#{@prefix}/" if @prefix | ||
all_objects = get_bucket.files prefix: prefix |
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.
It will not work if the bucket contains a lot of objects.
See https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/v0.44.0/google/cloud/storage/file/list
It might be a good idea to use next
and call batch_delete
for each page, compared to use all
which could create a very big array.
test/gcs_test.rb
Outdated
end | ||
end | ||
|
||
describe "#url" do |
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.
A test for url()
calls without expires could be great here too for completeness
test/test_env_setup.sh
Outdated
|
||
# Download the service account json | ||
mkdir -p $(dirname $GOOGLE_CLOUD_KEYFILE) | ||
rm -f $GOOGLE_CLOUD_KEYFILE |
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.
I would prefer to fail if $GOOGLE_CLOUD_KEYFILE
exists rather than deleting it. If it exists and is a private key for a SA, I would not like it to be deleted.
test/test_env_setup.sh
Outdated
GCS_BUCKET=${GCS_SA}-${GOOGLE_CLOUD_PROJECT} | ||
gsutil mb -p $GOOGLE_CLOUD_PROJECT gs://$GCS_BUCKET/ | ||
|
||
rm -f ../.env |
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.
You do not need to remove the file if you override it on the next line (using >
)
test/test_env_setup.sh
Outdated
gsutil mb -p $GOOGLE_CLOUD_PROJECT gs://$GCS_BUCKET/ | ||
|
||
rm -f ../.env | ||
cat >../.env <<EOL |
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.
I would prefer to not use a relative path here, as the script may be invoked from the root of the project, like this: test/test_env_setup.sh
.
Getting the script directory is tricky to do properly in shell. I would prefer to output the variables and ask the user to put them in .env
. This also gives the user the ability to put them elsewhere if needed.
test/test_env_setup.sh
Outdated
GCS_BUCKET=${GCS_BUCKET} | ||
GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT} | ||
GOOGLE_CLOUD_KEYFILE=${GOOGLE_CLOUD_KEYFILE} | ||
EOL |
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.
Missing new line
test/test_env_setup.sh
Outdated
@@ -0,0 +1,39 @@ | |||
#!/usr/bin/env bash |
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.
Please rename the script to something clearer, like create_test_environment.sh
@renchap I'll work on some of these change. Regarding the test script: Everything you mention is a good idea, and I welcome you or others to take it on. I just have spent my allotted time and need to move on. I'll get the code review changes done now. |
I have completed all the code review changes above where I added the 👍 The only thing I did not expand on was the test script changes as I mentioned above. I also re-ran the tests - all green. |
@renchap is this going to be merged? I want to get on a release for production instead of a fork/commit hash. |
I am very busy right now with other stuff, but I will do it ASAP. |
Thanks again @rosskevin, I just rebased your commits, improved the test environment creation script and fixed a few things. It would be amazing if you could review the changes on |
This is a fairly major change, it might make sense given semver guidelines to bump this to 1.0.0, though I see no reason why backwards compatibility is not maintained.
Motivation:
google-cloud-storage
url(expires:)
to delegate to#presign
- matching S3 usage (but with GCS options)Notes:
test/test_env_setup.sh
to ease getting started for new contributors:project
option for overriding in main classFixes #15
All tests are green.