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

Add the ability to use minio with s3 getter #68

Merged
merged 6 commits into from
Jul 6, 2017
Merged

Add the ability to use minio with s3 getter #68

merged 6 commits into from
Jul 6, 2017

Conversation

lfarnell
Copy link
Contributor

This is an attempt at adding S3 compliant server support for the S3 protocol. I only tested with minio and it seemed to work

C:\go\src\github.com\hashicorp\go-getter\cmd\go-getter>go run main.go "s3::http://127.0.0.1:9000/test-bucket/hello.txt?aws_access_key_id=xxx&aws_access_key_secret=xxx" C:\
minio\

2017/06/17 01:37:26 Success!

I wasn't exactly sure how to add a unit test for it considering i would need to have a minio server running. Any feedback on the code would be great!

Closes #52

get_s3.go Outdated
bucket = pathParts[1]
path = pathParts[2]
version = u.Query().Get("version")
region = "us-east-1"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be parsable as well in case the user has set a non-default region on minio

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 completely overlooked the ability to set the region. I will query the region as well

get_s3.go Outdated
err = fmt.Errorf("URL is not a valid S3 URL")
return
}
if strings.Contains(u.Host, "amazonaws.com") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment explaining the different parsing for supporting blob stores mimicking the AWS S3 API

@@ -204,29 +212,45 @@ func (g *S3Getter) getAWSConfig(region string, creds *credentials.Credentials) *
}

func (g *S3Getter) parseUrl(u *url.URL) (region, bucket, path, version string, creds *credentials.Credentials, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add some unit tests to test parsing both s3 and s3 complaint URLs. Lets us get some test coverage and avoid running the server in tests.

After that we can merge!

@lfarnell
Copy link
Contributor Author

@dadgar let me know if those unit tests are ok! Couldn't think of another way to test it

@lfarnell
Copy link
Contributor Author

Please dont merge yet. I want to clean up the tests a little and i forgot about a failure case. Sorry about this

@lnguyen
Copy link

lnguyen commented Jun 26, 2017

Question @armon are we looking to get this merge and added for 0.6.0 Nomad?

@dadgar
Copy link
Contributor

dadgar commented Jul 1, 2017

@lnguyen It would be great to get it in 0.6.0

@lfarnell Any update?

@lfarnell
Copy link
Contributor Author

lfarnell commented Jul 1, 2017

@dadgar fixed my code and the tests. Ready for another review 👍 Sorry for the delay!

get_s3_test.go Outdated
if creds != nil {
t.Fatal("expected to not be nil")
func TestS3Getter_Url(t *testing.T) {
for i, pt := range s3tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just inline here:

var s3tests = []struct{
    url     string
  ...
  } {
      {
         // test 1
      },
      ...
  }
  for i, pt := range s3tests {
  }

And then you can use the new table driven test using t.Run(..)

Better example here: https://blog.golang.org/subtests

@dadgar
Copy link
Contributor

dadgar commented Jul 1, 2017

@lfarnell Looking good! Small comment on the tests just to clean it up a bit but otherwise 🥇

@lfarnell
Copy link
Contributor Author

lfarnell commented Jul 1, 2017

@dadgar done!

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.

4 participants