github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/storage/bucket/swift/bucket_client.go (about)

     1  package swift
     2  
     3  import (
     4  	"github.com/go-kit/log"
     5  	"github.com/prometheus/common/model"
     6  	"github.com/thanos-io/thanos/pkg/objstore"
     7  	"github.com/thanos-io/thanos/pkg/objstore/swift"
     8  	yaml "gopkg.in/yaml.v2"
     9  )
    10  
    11  // NewBucketClient creates a new Swift bucket client
    12  func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucket, error) {
    13  	bucketConfig := swift.Config{
    14  		AuthVersion:       cfg.AuthVersion,
    15  		AuthUrl:           cfg.AuthURL,
    16  		Username:          cfg.Username,
    17  		UserDomainName:    cfg.UserDomainName,
    18  		UserDomainID:      cfg.UserDomainID,
    19  		UserId:            cfg.UserID,
    20  		Password:          cfg.Password,
    21  		DomainId:          cfg.DomainID,
    22  		DomainName:        cfg.DomainName,
    23  		ProjectID:         cfg.ProjectID,
    24  		ProjectName:       cfg.ProjectName,
    25  		ProjectDomainID:   cfg.ProjectDomainID,
    26  		ProjectDomainName: cfg.ProjectDomainName,
    27  		RegionName:        cfg.RegionName,
    28  		ContainerName:     cfg.ContainerName,
    29  		Retries:           cfg.MaxRetries,
    30  		ConnectTimeout:    model.Duration(cfg.ConnectTimeout),
    31  		Timeout:           model.Duration(cfg.RequestTimeout),
    32  
    33  		// Hard-coded defaults.
    34  		ChunkSize:              swift.DefaultConfig.ChunkSize,
    35  		UseDynamicLargeObjects: false,
    36  	}
    37  
    38  	// Thanos currently doesn't support passing the config as is, but expects a YAML,
    39  	// so we're going to serialize it.
    40  	serialized, err := yaml.Marshal(bucketConfig)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  
    45  	return swift.NewContainer(logger, serialized)
    46  }