PresignedPostPolicy - Returns POST urlString, form data to upload an object.
(ctx context.Context, p *PostPolicy)
| 114 | |
| 115 | // PresignedPostPolicy - Returns POST urlString, form data to upload an object. |
| 116 | func (c *Client) PresignedPostPolicy(ctx context.Context, p *PostPolicy) (u *url.URL, formData map[string]string, err error) { |
| 117 | // Validate input arguments. |
| 118 | if p.expiration.IsZero() { |
| 119 | return nil, nil, errors.New("Expiration time must be specified") |
| 120 | } |
| 121 | if _, ok := p.formData["key"]; !ok { |
| 122 | return nil, nil, errors.New("object key must be specified") |
| 123 | } |
| 124 | if _, ok := p.formData["bucket"]; !ok { |
| 125 | return nil, nil, errors.New("bucket name must be specified") |
| 126 | } |
| 127 | |
| 128 | bucketName := p.formData["bucket"] |
| 129 | // Fetch the bucket location. |
| 130 | location, err := c.getBucketLocation(ctx, bucketName) |
| 131 | if err != nil { |
| 132 | return nil, nil, err |
| 133 | } |
| 134 | |
| 135 | isVirtualHost := c.isVirtualHostStyleRequest(*c.endpointURL, bucketName) |
| 136 | |
| 137 | u, err = c.makeTargetURL(bucketName, "", location, isVirtualHost, nil) |
| 138 | if err != nil { |
| 139 | return nil, nil, err |
| 140 | } |
| 141 | |
| 142 | // Get credentials from the configured credentials provider. |
| 143 | credValues, err := c.credsProvider.GetWithContext(c.CredContext()) |
| 144 | if err != nil { |
| 145 | return nil, nil, err |
| 146 | } |
| 147 | |
| 148 | var ( |
| 149 | signerType = credValues.SignerType |
| 150 | sessionToken = credValues.SessionToken |
| 151 | accessKeyID = credValues.AccessKeyID |
| 152 | secretAccessKey = credValues.SecretAccessKey |
| 153 | ) |
| 154 | |
| 155 | if signerType.IsAnonymous() { |
| 156 | return nil, nil, errInvalidArgument("Presigned operations are not supported for anonymous credentials") |
| 157 | } |
| 158 | |
| 159 | // Keep time. |
| 160 | t := time.Now().UTC() |
| 161 | // For signature version '2' handle here. |
| 162 | if signerType.IsV2() { |
| 163 | policyBase64 := p.base64() |
| 164 | p.formData["policy"] = policyBase64 |
| 165 | // For Google endpoint set this value to be 'GoogleAccessId'. |
| 166 | if s3utils.IsGoogleEndpoint(*c.endpointURL) { |
| 167 | p.formData["GoogleAccessId"] = accessKeyID |
| 168 | } else { |
| 169 | // For all other endpoints set this value to be 'AWSAccessKeyId'. |
| 170 | p.formData["AWSAccessKeyId"] = accessKeyID |
| 171 | } |
| 172 | // Sign the policy. |
| 173 | p.formData["signature"] = signer.PostPresignSignatureV2(policyBase64, secretAccessKey) |
no test coverage detected