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

Figure out projectID for GCS automatically from credentials.json #5029

Merged
merged 1 commit into from Oct 20, 2017

Conversation

krishnasrinivas
Copy link
Contributor

@krishnasrinivas krishnasrinivas commented Oct 7, 2017

fixes #5027

Description

We parse projectID from credentials.json file, hence it need not be passed in the command line if GOOGLE_APPLICATION_CREDENTIALS is set to the path of credentials.json

How Has This Been Tested?

manual, unit testing

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Oct 7, 2017

Codecov Report

Merging #5029 into master will decrease coverage by 0.03%.
The diff coverage is 22.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5029      +/-   ##
==========================================
- Coverage   62.48%   62.44%   -0.04%     
==========================================
  Files         192      192              
  Lines       27756    27781      +25     
==========================================
+ Hits        17342    17348       +6     
- Misses       9180     9197      +17     
- Partials     1234     1236       +2
Impacted Files Coverage Δ
cmd/gateway-main.go 13.51% <0%> (-0.38%) ⬇️
cmd/gateway-gcs.go 6.24% <28.57%> (+0.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8a11c8...30ae003. Read the comment docs.

@codecov
Copy link

codecov bot commented Oct 7, 2017

Codecov Report

Merging #5029 into master will decrease coverage by 0.05%.
The diff coverage is 35.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5029      +/-   ##
==========================================
- Coverage   61.29%   61.23%   -0.06%     
==========================================
  Files         192      192              
  Lines       28368    28391      +23     
==========================================
- Hits        17387    17386       -1     
- Misses       9734     9754      +20     
- Partials     1247     1251       +4
Impacted Files Coverage Δ
cmd/gateway-gcs.go 6.54% <27.27%> (+0.38%) ⬆️
cmd/gateway-main.go 12.56% <50%> (-0.33%) ⬇️
cmd/fs-v1-rwpool.go 64.34% <0%> (-4.35%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d2d63f...e355dc0. Read the comment docs.

@@ -778,12 +777,14 @@ func TestHTTPListenerAcceptParallel(t *testing.T) {
if err != nil {
t.Fatalf("Test %d: accept: expected = <nil>, got = %v", i+1, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't do these changes in your PR @krishnasrinivas - you should send a separate fix.

@@ -248,11 +252,36 @@ type gcsGateway struct {

const googleStorageEndpoint = "storage.googleapis.com"

// Returns projectID from the GOOGLE_APPLICATION_CREDENTIALS file.
func gcsParseProjectID(path string) (projectID string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

credsJSONFile would be more clear than path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have renamed it to credsFile

errorIf(errGCSProjectIDNotFound, "project-id should be provided as argument or GOOGLE_APPLICATION_CREDENTIALS should be set with path to credentials.json")
cli.ShowCommandHelpAndExit(ctx, "gcs", 1)
}
if projectID != "" && !isValidGCSProjectIDFormat(projectID) {
Copy link
Member

Choose a reason for hiding this comment

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

As project ID from command line has higher precedence over env var GOOGLE_APPLICATION_CREDENTIALS. I think below if block would be clear

credsJSONFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
if projectID == "" {
    if credsJSONFIle == "" {
       fatalIf(...)
    }
    if projectID, err = gcsParseProjectID(credsJSONFile); err != nil {
        fatalIf(err, ...)
    }
}

This way newGCSGateway() could use projectID argument without knowing about env var GOOGLE_APPLICATION_CREDENTIALS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to do this @balamurugana but our source code structure does not allow this flow, it needs a refactor to allow it.

i.e I tried to make the flow such that newGCSGateway() does not access GOOGLE_APPLICATION_CREDENTIALS but it was not possible. It needs a separate refactor of the functions in gateway-main.go

Copy link
Member

Choose a reason for hiding this comment

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

OK. Probably we need to open an issue?

@deekoder deekoder merged commit 7e05b82 into minio:master Oct 20, 2017
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.

Figure out projectID for GCS automatically from credentials.json
4 participants