// s3Connection makes a connection to s3
s3Connection makes a connection to s3
// s3Connection makes a connection to s3
func s3Connection(opt *Options) (*s3.S3, *session.Session, error) {
	v := credentials.Value{
		AccessKeyID:     opt.AccessKeyID,
		SecretAccessKey: opt.SecretAccessKey,
		SessionToken:    opt.SessionToken,
	}
	lowTimeoutClient := &http.Client{Timeout: 1 * time.Second} 
	def := defaults.Get()
	def.Config.HTTPClient = lowTimeoutClient
	providers := []credentials.Provider{
		&credentials.StaticProvider{Value: v},
		&credentials.EnvProvider{},
		&credentials.SharedCredentialsProvider{},
		defaults.RemoteCredProvider(*def.Config, def.Handlers),
		&ec2rolecreds.EC2RoleProvider{
			Client: ec2metadata.New(session.New(), &aws.Config{
				HTTPClient: lowTimeoutClient,
			}),
			ExpiryWindow: 3,
		},
	}
	cred := credentials.NewChainCredentials(providers)
	switch {
	case opt.EnvAuth:
	case v.AccessKeyID == "" && v.SecretAccessKey == "":
		cred = credentials.AnonymousCredentials
	case v.AccessKeyID == "":
		return nil, nil, errors.New("access_key_id not found")
	case v.SecretAccessKey == "":
		return nil, nil, errors.New("secret_access_key not found")
	}
	if opt.Region == "" && opt.Endpoint == "" {
		opt.Endpoint = "https://s3.amazonaws.com/"
	}
	if opt.Region == "" {
		opt.Region = "us-east-1"
	}
	awsConfig := aws.NewConfig().
		WithRegion(opt.Region).
		WithMaxRetries(maxRetries).
		WithCredentials(cred).
		WithEndpoint(opt.Endpoint).
		WithHTTPClient(fshttp.NewClient(fs.Config)).
		WithS3ForcePathStyle(opt.ForcePathStyle)
	ses := session.New()
	c := s3.New(ses, awsConfig)
	if opt.Region == "other-v2-signature" {
		fs.Debugf(nil, "Using v2 auth")
		signer := func(req *request.Request) {
			if req.Config.Credentials == credentials.AnonymousCredentials {
				return
			}
			sign(v.AccessKeyID, v.SecretAccessKey, req.HTTPRequest)
		}
		c.Handlers.Sign.Clear()
		c.Handlers.Sign.PushBackNamed(corehandlers.BuildContentLengthHandler)
		c.Handlers.Sign.PushBack(signer)
	}
	return c, ses, nil
}
func s3Connection ( opt * Options ) ( * s3 . S3 , * session . Session , error ) { v := credentials . Value { AccessKeyID : opt . AccessKeyID , SecretAccessKey : opt . SecretAccessKey , SessionToken : opt . SessionToken , } lowTimeoutClient := & http . Client { Timeout : 1 * time . Second } def := defaults . Get ( ) def . Config . HTTPClient = lowTimeoutClient providers := [ ] credentials . Provider { & credentials . StaticProvider { Value : v } , & credentials . EnvProvider { } , & credentials . SharedCredentialsProvider { } , defaults . RemoteCredProvider ( * def . Config , def . Handlers ) , & ec2rolecreds . EC2RoleProvider { Client : ec2metadata . New ( session . New ( ) , & aws . Config { HTTPClient : lowTimeoutClient , } ) , ExpiryWindow : 3 , } , } cred := credentials . NewChainCredentials ( providers ) switch { case opt . EnvAuth : case v . AccessKeyID == " " && v . SecretAccessKey == " " : cred = credentials . AnonymousCredentials case v . AccessKeyID == " " : return nil , nil , errors . New ( " " ) case v . SecretAccessKey == " " : return nil , nil , errors . New ( " " ) } if opt . Region == " " && opt . Endpoint == " " { opt . Endpoint = " " } if opt . Region == " " { opt . Region = " " } awsConfig := aws . NewConfig ( ) . WithRegion ( opt . Region ) . WithMaxRetries ( maxRetries ) . WithCredentials ( cred ) . WithEndpoint ( opt . Endpoint ) . WithHTTPClient ( fshttp . NewClient ( fs . Config ) ) . WithS3ForcePathStyle ( opt . ForcePathStyle ) ses := session . New ( ) c := s3 . New ( ses , awsConfig ) if opt . Region == " " { fs . Debugf ( nil , " " ) signer := func ( req * request . Request ) { if req . Config . Credentials == credentials . AnonymousCredentials { return } sign ( v . AccessKeyID , v . SecretAccessKey , req . HTTPRequest ) } c . Handlers . Sign . Clear ( ) c . Handlers . Sign . PushBackNamed ( corehandlers . BuildContentLengthHandler ) c . Handlers . Sign . PushBack ( signer ) } return c , ses , nil }
s3Connection makes a connection to s3
s3Connection makes a connection to s3
// Make the auth // low timeout to ec2 metadata service // first provider to supply a credential set "wins" // use static credentials if they're present (checked by provider) // * Access Key ID:     AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY // * Secret Access Key: AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY // A SharedCredentialsProvider retrieves credentials // from the current user's home directory.  It checks // AWS_SHARED_CREDENTIALS_FILE and AWS_PROFILE too. // Pick up IAM role if we're in an ECS task // Pick up IAM role in case we're on EC2 // No need for empty checks if "env_auth" is true // if no access key/secret and iam is explicitly disabled then fall back to anon interaction // awsConfig.WithLogLevel(aws.LogDebugWithSigning) // Ignore AnonymousCredentials object