2021-05-23 00:46:15 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* types */
|
|
|
|
|
|
|
|
type credential struct {
|
|
|
|
AccessKey string
|
|
|
|
SecretKey string
|
|
|
|
// Region is critical when signing requests.
|
|
|
|
Region string
|
2021-05-23 11:54:30 +08:00
|
|
|
// Endpoint is the base URL of the bucket, including the bucket name (in
|
|
|
|
// either the domain or path).
|
2021-05-23 00:46:15 +08:00
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
// https://bucketname.s3.us-west-2.amazonaws.com
|
|
|
|
// http://my-minio.example.com/bucket-name
|
|
|
|
Endpoint string
|
|
|
|
// ACL is an optional canned ACL to set on objects
|
|
|
|
ACL string
|
|
|
|
// Prefix is a string to prepend to object keys
|
|
|
|
Prefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cred credential) validate() error {
|
|
|
|
if strings.HasSuffix(cred.Endpoint, "/") {
|
|
|
|
return fmt.Errorf("%w: endpoint should not end with slash", errBadRequest)
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(cred.Prefix, "/") {
|
|
|
|
return fmt.Errorf("%w: prefix should not start with slash", errBadRequest)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|