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

Switch to google-cloud-storage gem, delegate url(expires:) to #presign #16

Closed
wants to merge 7 commits into from

Conversation

rosskevin
Copy link
Contributor

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:

Notes:

  • Added test/test_env_setup.sh to ease getting started for new contributors
  • Added contribution notes for both the new script, as well as manual setup
  • Added :project option for overriding in main class
  • Added more tests

Fixes #15

All tests are green.

@renchap
Copy link
Owner

renchap commented Oct 12, 2017

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 😄)

@renchap
Copy link
Owner

renchap commented Oct 12, 2017

Also it might be worth it to look at #8 and try to get it working with this new implementation.

@renchap renchap self-requested a review October 12, 2017 21:20
Copy link
Owner

@renchap renchap left a 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
Copy link
Owner

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|
Copy link
Owner

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)
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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


# Download the service account json
mkdir -p $(dirname $GOOGLE_CLOUD_KEYFILE)
rm -f $GOOGLE_CLOUD_KEYFILE
Copy link
Owner

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.

GCS_BUCKET=${GCS_SA}-${GOOGLE_CLOUD_PROJECT}
gsutil mb -p $GOOGLE_CLOUD_PROJECT gs://$GCS_BUCKET/

rm -f ../.env
Copy link
Owner

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

gsutil mb -p $GOOGLE_CLOUD_PROJECT gs://$GCS_BUCKET/

rm -f ../.env
cat >../.env <<EOL
Copy link
Owner

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.

GCS_BUCKET=${GCS_BUCKET}
GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}
GOOGLE_CLOUD_KEYFILE=${GOOGLE_CLOUD_KEYFILE}
EOL
Copy link
Owner

Choose a reason for hiding this comment

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

Missing new line

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
Copy link
Owner

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

@rosskevin
Copy link
Contributor Author

@renchap I'll work on some of these change.

Regarding the test script:
I'm not interested in putting more time into the test script. You are welcome to make all these changes, I just wanted to move the ball forward a bit. This is an improvement on what was there.

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.

@rosskevin
Copy link
Contributor Author

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.

@rosskevin
Copy link
Contributor Author

@renchap is this going to be merged? I want to get on a release for production instead of a fork/commit hash.

@renchap
Copy link
Owner

renchap commented Oct 27, 2017

I am very busy right now with other stuff, but I will do it ASAP.

@renchap
Copy link
Owner

renchap commented Nov 19, 2017

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 master and tell me if everything is good for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants