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

Added a new method SetUserMetadata to the PostPolicy #839

Merged
merged 3 commits into from
Oct 17, 2017

Conversation

hnb2
Copy link
Contributor

@hnb2 hnb2 commented Oct 9, 2017

Hi there,

here is a PR for a new feature I need for a project I am working on.

Feature

SetUserSpecifiedMetadata(key string, value string) allows you to add user specified metadata following this guide which mention:

key Explanation
x-amz-meta-* User-specified metadata.This condition supports exact matching and starts-with condition match type.

Contributing

I went through the contributing doc and ran SERVER_ENDPOINT=xxx ACCESS_KEY=xxx SECRET_KEY=xxx go test -race ./... successfuly and ran go fmt.

But I do not have any unit tests though as the file post-policy.go does not have any I am not sure how you guys would like it to be tested, if you could please provide me some pointers.

I tested the feature itself, it is working and being used in staging (the header is set properly and retrieved through the Minio event notification when the upload is completed, and through HEAD as well).

post-policy.go Outdated
@@ -167,6 +167,26 @@ func (p *PostPolicy) SetSuccessStatusAction(status string) error {
return nil
}

func (p *PostPolicy) SetUserSpecifiedMetadata(key string, value string) error {

Choose a reason for hiding this comment

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

exported method PostPolicy.SetUserSpecifiedMetadata should have comment or be unexported

@harshavardhana
Copy link
Member

But I do not have any unit tests though as the file post-policy.go does not have any I am not sure how you guys would like it to be tested, if you could please provide me some pointers.

I tested the feature itself, it is working and being used in staging (the header is set properly and retrieved through the Minio event notification when the upload is completed, and through HEAD as well).

You should add tests in functional_tests.go - these tests will be run on our public server, also you would need to update API.md documenting this feature.

@hnb2
Copy link
Contributor Author

hnb2 commented Oct 9, 2017

Hi @harshavardhana, I am trying to run those functional_tests.go but I can't get paste those errors:

➜  minio-go git:(user_defined_metadata) ✗ SERVER_ENDPOINT=10.200.0.71:9000 ACCESS_KEY=JSP83BZY4II2YQPUL308 SECRET_KEY=ccX75Z8HzN2FOdNoNxgbkK/gOgullxdjapdIJVB6 ENABLE_HTTPS=0 go run functional_tests.go
# command-line-arguments
./functional_tests.go:347:94: cannot use minio.PutObjectOptions literal (type minio.PutObjectOptions) as type *minio.PutObjectOptions in argument to c.PutObject
./functional_tests.go:356:94: cannot use minio.PutObjectOptions literal (type minio.PutObjectOptions) as type *minio.PutObjectOptions in argument to c.PutObject
./functional_tests.go:491:99: cannot use minio.PutObjectOptions literal (type minio.PutObjectOptions) as type *minio.PutObjectOptions in argument to c.PutObject
./functional_tests.go:501:23: too many arguments in call to c.GetObject
./functional_tests.go:501:48: undefined: minio.GetObjectOptions
./functional_tests.go:593:99: cannot use minio.PutObjectOptions literal (type minio.PutObjectOptions) as type *minio.PutObjectOptions in argument to c.PutObject
./functional_tests.go:604:23: too many arguments in call to c.GetObject
./functional_tests.go:604:48: undefined: minio.GetObjectOptions
./functional_tests.go:682:107: cannot use minio.PutObjectOptions literal (type minio.PutObjectOptions) as type *minio.PutObjectOptions in argument
to c.PutObject
./functional_tests.go:760:100: cannot use minio.PutObjectOptions literal (type minio.PutObjectOptions) as type *minio.PutObjectOptions in argument
to c.PutObject
./functional_tests.go:760:100: too many errors

I am on antergos (ArchLinux) running:

➜  minio-go git:(user_defined_metadata) ✗ go version                                                                                              
go version go1.9 linux/amd64

Am I missing something ? (I ran all the go get from the .travis.yml file)

@vadmeste
Copy link
Member

vadmeste commented Oct 9, 2017

Hey @hnb2,

I downloaded your PR locally, function_tests.go compiles fine in my machine. Can you check if your minio-go dir is under $GOPATH/src/github.com/minio/ directory ?

@hnb2
Copy link
Contributor Author

hnb2 commented Oct 9, 2017

Hey @vadmeste , thanks for answering. I made it work by modifying (locally) the minio imports to use "hnb2/" instead of "minio/" because I am using my fork. I guess that your solution is cleaner.

post-policy.go Outdated
@@ -167,6 +167,28 @@ func (p *PostPolicy) SetSuccessStatusAction(status string) error {
return nil
}

// SetUserSpecifiedMetadata - Set user specified metadata as a key/value
// couple. Can be retrieved through a HEAD request or an event.
func (p *PostPolicy) SetUserSpecifiedMetadata(key string, value string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't better to call this SetUserMetadata(), it will be already consistent with other simliar APIs (like SetContentType, etc..)

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will push the changes tomorrow

Copy link
Member

Choose a reason for hiding this comment

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

You might need to squash your changes and update the PR title here. Thanks @hnb2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hnb2 hnb2 changed the title Added a new method SetUserSpecifiedMetadata to the PostPolicy Added a new method SetUserMetadata to the PostPolicy Oct 12, 2017
Copy link
Contributor

@krishnasrinivas krishnasrinivas left a comment

Choose a reason for hiding this comment

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

@hnb2 You can call it SetMetadata instead of SetUserMetadata

@hnb2
Copy link
Contributor Author

hnb2 commented Oct 17, 2017

@krishnasrinivas Ok I will push this change + fix the conflicts

@hnb2
Copy link
Contributor Author

hnb2 commented Oct 17, 2017

@krishnasrinivas regarding the method name, I see that this PR has been merged with the name SetUserMetadata. Do you still want me to rename it ?

@krishnasrinivas
Copy link
Contributor

@krishnasrinivas regarding the method name, I see that this PR has been merged with the name SetUserMetadata. Do you still want me to rename it ?

No, SetUserMetadata is better

Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

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

LGTM

@nitisht nitisht merged commit fe263bf into minio:master Oct 17, 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.

6 participants