mirror of
https://github.com/minio/mc.git
synced 2025-11-14 23:42:27 +03:00
Add s3pathstyle boolean to check for path v/s subdomain requests
This commit is contained in:
27
configure.go
27
configure.go
@@ -10,32 +10,35 @@ import (
|
|||||||
"github.com/minio-io/mc/pkg/s3"
|
"github.com/minio-io/mc/pkg/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseConfigureInput(c *cli.Context) (accessKey, secretKey, endpoint string, err error) {
|
func parseConfigureInput(c *cli.Context) (auth *s3.Auth, err error) {
|
||||||
accessKey = c.String("accesskey")
|
accessKey := c.String("accesskey")
|
||||||
secretKey = c.String("secretkey")
|
secretKey := c.String("secretkey")
|
||||||
endpoint = c.String("endpoint")
|
endpoint := c.String("endpoint")
|
||||||
|
pathstyle := c.Bool("pathstyle")
|
||||||
|
|
||||||
if accessKey == "" {
|
if accessKey == "" {
|
||||||
return "", "", "", configAccessErr
|
return nil, configAccessErr
|
||||||
}
|
}
|
||||||
if secretKey == "" {
|
if secretKey == "" {
|
||||||
return "", "", "", configSecretErr
|
return nil, configSecretErr
|
||||||
}
|
}
|
||||||
if endpoint == "" {
|
if endpoint == "" {
|
||||||
return "", "", "", configEndpointErr
|
return nil, configEndpointErr
|
||||||
}
|
}
|
||||||
return accessKey, secretKey, endpoint, nil
|
|
||||||
|
auth = s3.NewAuth(accessKey, secretKey, endpoint, pathstyle)
|
||||||
|
return auth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func doConfigure(c *cli.Context) {
|
func doConfigure(c *cli.Context) {
|
||||||
var err error
|
var err error
|
||||||
var jAuth []byte
|
var jAuth []byte
|
||||||
var accessKey, secretKey, endpoint string
|
var auth *s3.Auth
|
||||||
accessKey, secretKey, endpoint, err = parseConfigureInput(c)
|
auth, err = parseConfigureInput(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
auth := s3.NewAuth(accessKey, secretKey, endpoint)
|
|
||||||
jAuth, err = json.Marshal(auth)
|
jAuth, err = json.Marshal(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -43,7 +46,7 @@ func doConfigure(c *cli.Context) {
|
|||||||
|
|
||||||
var s3File *os.File
|
var s3File *os.File
|
||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
s3File, err = os.OpenFile(path.Join(home, AUTH), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
s3File, err = os.OpenFile(path.Join(home, AUTH), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
||||||
defer s3File.Close()
|
defer s3File.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ type Auth struct {
|
|||||||
// Used for SSL transport layer
|
// Used for SSL transport layer
|
||||||
CertPEM string
|
CertPEM string
|
||||||
KeyPEM string
|
KeyPEM string
|
||||||
|
|
||||||
|
// Force path style
|
||||||
|
S3ForcePathStyle bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type TlsConfig struct {
|
type TlsConfig struct {
|
||||||
|
|||||||
@@ -373,11 +373,12 @@ func (c *Client) Delete(bucket, key string) error {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func NewAuth(accessKey, secretKey, hostname string) (auth *Auth) {
|
func NewAuth(accessKey, secretKey, hostname string, style bool) (auth *Auth) {
|
||||||
auth = &Auth{
|
auth = &Auth{
|
||||||
AccessKey: accessKey,
|
AccessKey: accessKey,
|
||||||
SecretAccessKey: secretKey,
|
SecretAccessKey: secretKey,
|
||||||
Endpoint: hostname,
|
Endpoint: hostname,
|
||||||
|
S3ForcePathStyle: style,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ var Configure = cli.Command{
|
|||||||
Value: "s3.amazonaws.com",
|
Value: "s3.amazonaws.com",
|
||||||
Usage: "S3 Endpoint URL default is 's3.amazonaws.com'",
|
Usage: "S3 Endpoint URL default is 's3.amazonaws.com'",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "pathstyle",
|
||||||
|
Usage: "Force path style API requests",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user