mirror of
https://github.com/minio/minio.git
synced 2025-04-12 07:22:18 -04:00
Auto-probe backend signature support (#6044)
This commit is contained in:
parent
05a64dee95
commit
2575f4198a
@ -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) {
|
||||||
// Validate gateway arguments.
|
args := ctx.Args()
|
||||||
host := ctx.Args().First()
|
if !ctx.Args().Present() {
|
||||||
// Validate gateway arguments.
|
args = cli.Args{"https://s3.amazonaws.com"}
|
||||||
logger.FatalIf(minio.ValidateGatewayArguments(ctx.GlobalString("address"), host), "Invalid argument")
|
}
|
||||||
|
|
||||||
minio.StartGateway(ctx, &S3{host})
|
// Validate gateway arguments.
|
||||||
|
logger.FatalIf(minio.ValidateGatewayArguments(ctx.GlobalString("address"), args.First()), "Invalid argument")
|
||||||
|
|
||||||
|
// 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.
|
// Override default params if the host is provided
|
||||||
if g.host != "" {
|
endpoint, secure, err := minio.ParseGatewayEndpoint(url)
|
||||||
// Override default params if the host is provided
|
if err != nil {
|
||||||
endpoint, secure, err = minio.ParseGatewayEndpoint(g.host)
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
clnt, err := miniogo.NewV4(endpoint, accessKey, secretKey, secure)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = clnt.BucketExists("probe-bucket-sign"); err != nil {
|
||||||
|
clnt, err = miniogo.NewV2(endpoint, accessKey, secretKey, secure)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if _, err = clnt.BucketExists("probe-bucket-sign"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default endpoint parameters
|
return &miniogo.Core{Client: clnt}, nil
|
||||||
if endpoint == "" {
|
}
|
||||||
endpoint = "s3.amazonaws.com"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize minio client object.
|
// NewGatewayLayer returns s3 ObjectLayer.
|
||||||
client, err := miniogo.NewCore(endpoint, creds.AccessKey, creds.SecretKey, secure)
|
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…
x
Reference in New Issue
Block a user