Auto-probe backend signature support (#6044)

master
Harshavardhana 7 years ago committed by kannappanr
parent 05a64dee95
commit 2575f4198a
  1. 54
      cmd/gateway/s3/gateway-s3.go

@ -1,5 +1,5 @@
/* /*
* Minio Cloud Storage, (C) 2017 Minio, Inc. * Minio Cloud Storage, (C) 2017, 2018 Minio, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -97,12 +97,16 @@ EXAMPLES:
// Handler for 'minio gateway s3' command line. // Handler for 'minio gateway s3' command line.
func s3GatewayMain(ctx *cli.Context) { func s3GatewayMain(ctx *cli.Context) {
args := ctx.Args()
if !ctx.Args().Present() {
args = cli.Args{"https://s3.amazonaws.com"}
}
// Validate gateway arguments. // Validate gateway arguments.
host := ctx.Args().First() logger.FatalIf(minio.ValidateGatewayArguments(ctx.GlobalString("address"), args.First()), "Invalid argument")
// Validate gateway arguments.
logger.FatalIf(minio.ValidateGatewayArguments(ctx.GlobalString("address"), host), "Invalid argument")
minio.StartGateway(ctx, &S3{host}) // Start the gateway..
minio.StartGateway(ctx, &S3{args.First()})
} }
// S3 implements Gateway. // S3 implements Gateway.
@ -115,34 +119,46 @@ func (g *S3) Name() string {
return s3Backend return s3Backend
} }
// NewGatewayLayer returns s3 ObjectLayer. // newS3 - Initializes a new client by auto probing S3 server signature.
func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) { func newS3(url, accessKey, secretKey string) (*miniogo.Core, error) {
var err error if url == "" {
var endpoint string url = "https://s3.amazonaws.com"
var secure = true }
// Validate host parameters.
if g.host != "" {
// Override default params if the host is provided // Override default params if the host is provided
endpoint, secure, err = minio.ParseGatewayEndpoint(g.host) endpoint, secure, err := minio.ParseGatewayEndpoint(url)
if err != nil { if err != nil {
return nil, err return nil, err
} }
clnt, err := miniogo.NewV4(endpoint, accessKey, secretKey, secure)
if err != nil {
return nil, err
} }
// Default endpoint parameters if _, err = clnt.BucketExists("probe-bucket-sign"); err != nil {
if endpoint == "" { clnt, err = miniogo.NewV2(endpoint, accessKey, secretKey, secure)
endpoint = "s3.amazonaws.com" if err != nil {
return nil, err
}
if _, err = clnt.BucketExists("probe-bucket-sign"); err != nil {
return nil, err
}
} }
// Initialize minio client object. return &miniogo.Core{Client: clnt}, nil
client, err := miniogo.NewCore(endpoint, creds.AccessKey, creds.SecretKey, secure) }
// NewGatewayLayer returns s3 ObjectLayer.
func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) {
// Probe S3 signature with input credentials.
clnt, err := newS3(g.host, creds.AccessKey, creds.SecretKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &s3Objects{ return &s3Objects{
Client: client, Client: clnt,
}, nil }, nil
} }

Loading…
Cancel
Save