MCPcopy
hub / github.com/NVIDIA/aistore / newClient

Function newClient

ais/backend/aws.go:482–529  ·  view source on GitHub ↗

static helpers newClient creates new S3 client on a per-region basis or, more precisely, per (region, endpoint) pair - and note that s3 endpoint is per-bucket configurable. If the client already exists newClient simply returns it. From S3 SDK: "S3 methods are safe to use concurrently. It is not s

(conf sessConf, tag string)

Source from the content-addressed store, hash-verified

480// "S3 methods are safe to use concurrently. It is not safe to
481// modify mutate any of the struct's properties though."
482func newClient(conf sessConf, tag string) (svc *s3.S3, region string, err error) {
483 endpoint := s3Endpoint
484 region = conf.region
485 if conf.bck != nil && conf.bck.Props != nil {
486 if region == "" {
487 region = conf.bck.Props.Extra.AWS.CloudRegion
488 }
489 if conf.bck.Props.Extra.AWS.Endpoint != "" {
490 endpoint = conf.bck.Props.Extra.AWS.Endpoint
491 }
492 }
493
494 // reuse
495 if region != "" {
496 cmu.RLock()
497 svc = clients[region][endpoint]
498 cmu.RUnlock()
499 if svc != nil {
500 return
501 }
502 }
503 // create
504 var (
505 sess = _session(endpoint)
506 awsConf = &aws.Config{}
507 )
508 if region == "" {
509 if tag != "" {
510 err = fmt.Errorf("%s: unknown region for bucket %s -- proceeding with default", tag, conf.bck)
511 }
512 svc = s3.New(sess)
513 return
514 }
515 // ok
516 awsConf.Region = aws.String(region)
517 svc = s3.New(sess, awsConf)
518 debug.Assertf(region == *svc.Config.Region, "%s != %s", region, *svc.Config.Region)
519
520 cmu.Lock()
521 eps := clients[region]
522 if eps == nil {
523 eps = make(map[string]*s3.S3, 1)
524 clients[region] = eps
525 }
526 eps[endpoint] = svc
527 cmu.Unlock()
528 return
529}
530
531// Create session using default creds from ~/.aws/credentials and environment variables.
532func _session(endpoint string) *session.Session {

Callers 7

HeadBucketMethod · 0.85
ListObjectsMethod · 0.85
ListBucketsMethod · 0.85
HeadObjMethod · 0.85
GetObjReaderMethod · 0.85
PutObjMethod · 0.85
DeleteObjMethod · 0.85

Calls 8

AssertfFunction · 0.92
_sessionFunction · 0.85
RLockMethod · 0.65
RUnlockMethod · 0.65
NewMethod · 0.65
StringMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected