MCPcopy
hub / github.com/minio/minio-go / PresignedPostPolicy

Method PresignedPostPolicy

api-presigned.go:116–228  ·  api-presigned.go::Client.PresignedPostPolicy

PresignedPostPolicy - Returns POST urlString, form data to upload an object.

(ctx context.Context, p *PostPolicy)

Source from the content-addressed store, hash-verified

114
115// PresignedPostPolicy - Returns POST urlString, form data to upload an object.
116func (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)

Callers 5

PutObjectFanOutMethod · 0.95
testPresignedPostPolicyFunction · 0.95
mainFunction · 0.80

Calls 14

getBucketLocationMethod · 0.95
makeTargetURLMethod · 0.95
CredContextMethod · 0.95
IsGoogleEndpointFunction · 0.92
PostPresignSignatureV2Function · 0.92
GetCredentialFunction · 0.92
PostPresignSignatureV4Function · 0.92
errInvalidArgumentFunction · 0.85
GetWithContextMethod · 0.80
IsAnonymousMethod · 0.80
IsV2Method · 0.80

Tested by

no test coverage detected