From f3ed11a363596f7a201b61d3ed2adb4e6de9cfbf Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 24 Feb 2015 14:13:28 -0800 Subject: [PATCH] Add s3pathstyle boolean to check for path v/s subdomain requests --- configure.go | 27 +++++++++++++++------------ pkg/s3/auth.go | 3 +++ pkg/s3/client.go | 9 +++++---- s3-fs-options.go | 4 ++++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/configure.go b/configure.go index 638c8341..6a0f3957 100644 --- a/configure.go +++ b/configure.go @@ -10,32 +10,35 @@ import ( "github.com/minio-io/mc/pkg/s3" ) -func parseConfigureInput(c *cli.Context) (accessKey, secretKey, endpoint string, err error) { - accessKey = c.String("accesskey") - secretKey = c.String("secretkey") - endpoint = c.String("endpoint") +func parseConfigureInput(c *cli.Context) (auth *s3.Auth, err error) { + accessKey := c.String("accesskey") + secretKey := c.String("secretkey") + endpoint := c.String("endpoint") + pathstyle := c.Bool("pathstyle") + if accessKey == "" { - return "", "", "", configAccessErr + return nil, configAccessErr } if secretKey == "" { - return "", "", "", configSecretErr + return nil, configSecretErr } 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) { var err error var jAuth []byte - var accessKey, secretKey, endpoint string - accessKey, secretKey, endpoint, err = parseConfigureInput(c) + var auth *s3.Auth + auth, err = parseConfigureInput(c) if err != nil { log.Fatal(err) } - auth := s3.NewAuth(accessKey, secretKey, endpoint) jAuth, err = json.Marshal(auth) if err != nil { log.Fatal(err) @@ -43,7 +46,7 @@ func doConfigure(c *cli.Context) { var s3File *os.File 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() if err != nil { log.Fatal(err) diff --git a/pkg/s3/auth.go b/pkg/s3/auth.go index 7474c88a..bda68733 100644 --- a/pkg/s3/auth.go +++ b/pkg/s3/auth.go @@ -46,6 +46,9 @@ type Auth struct { // Used for SSL transport layer CertPEM string KeyPEM string + + // Force path style + S3ForcePathStyle bool } type TlsConfig struct { diff --git a/pkg/s3/client.go b/pkg/s3/client.go index a5fbc4ed..98aba25a 100644 --- a/pkg/s3/client.go +++ b/pkg/s3/client.go @@ -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{ - AccessKey: accessKey, - SecretAccessKey: secretKey, - Endpoint: hostname, + AccessKey: accessKey, + SecretAccessKey: secretKey, + Endpoint: hostname, + S3ForcePathStyle: style, } return } diff --git a/s3-fs-options.go b/s3-fs-options.go index 568cabd7..e46d5e95 100644 --- a/s3-fs-options.go +++ b/s3-fs-options.go @@ -73,6 +73,10 @@ var Configure = cli.Command{ Value: "s3.amazonaws.com", Usage: "S3 Endpoint URL default is 's3.amazonaws.com'", }, + cli.BoolFlag{ + Name: "pathstyle", + Usage: "Force path style API requests", + }, }, }