1
0
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:
Harshavardhana
2015-02-24 14:13:28 -08:00
parent d5b6a07674
commit f3ed11a363
4 changed files with 27 additions and 16 deletions

View File

@@ -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)

View File

@@ -46,6 +46,9 @@ type Auth struct {
// Used for SSL transport layer
CertPEM string
KeyPEM string
// Force path style
S3ForcePathStyle bool
}
type TlsConfig struct {

View File

@@ -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
}

View File

@@ -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",
},
},
}