Skip to content

Commit

Permalink
Added SetUserData to run Unit Test of Post Policy (minio#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaashish authored and kannappanr committed Nov 15, 2018
1 parent 7744754 commit 39381cf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions post-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,28 @@ func (p *PostPolicy) SetUserMetadata(key string, value string) error {
return nil
}

// SetUserData - Set user data as a key/value couple.
// Can be retrieved through a HEAD request or an event.
func (p *PostPolicy) SetUserData(key string, value string) error {
if key == "" {
return ErrInvalidArgument("Key is empty")
}
if value == "" {
return ErrInvalidArgument("Value is empty")
}
headerName := fmt.Sprintf("x-amz-%s", key)
policyCond := policyCondition{
matchType: "eq",
condition: fmt.Sprintf("$%s", headerName),
value: value,
}
if err := p.addNewPolicy(policyCond); err != nil {
return err
}
p.formData[headerName] = value
return nil
}

// addNewPolicy - internal helper to validate adding new policies.
func (p *PostPolicy) addNewPolicy(policyCond policyCondition) error {
if policyCond.matchType == "" || policyCond.condition == "" || policyCond.value == "" {
Expand Down

0 comments on commit 39381cf

Please sign in to comment.