Bucket returns the requested blob bucket using the config.
( ctx context.Context, bucket string, httpClientProvider httpclient.Provider, )
| 276 | |
| 277 | // Bucket returns the requested blob bucket using the config. |
| 278 | func (c BlobConfig) Bucket( |
| 279 | ctx context.Context, bucket string, httpClientProvider httpclient.Provider, |
| 280 | ) (*blob.Bucket, error) { |
| 281 | switch c.Provider { |
| 282 | case "local": |
| 283 | return ttnblob.Local(ctx, bucket, c.Local.Directory) |
| 284 | case "aws": |
| 285 | httpClient, err := httpClientProvider.HTTPClient(ctx) |
| 286 | if err != nil { |
| 287 | return nil, err |
| 288 | } |
| 289 | conf := aws.NewConfig().WithHTTPClient(httpClient) |
| 290 | if c.AWS.Endpoint != "" { |
| 291 | conf = conf.WithEndpoint(c.AWS.Endpoint) |
| 292 | } |
| 293 | if c.AWS.S3ForcePathStyle != nil { |
| 294 | conf.WithS3ForcePathStyle(*c.AWS.S3ForcePathStyle) |
| 295 | } |
| 296 | if c.AWS.Region != "" { |
| 297 | conf = conf.WithRegion(c.AWS.Region) |
| 298 | } |
| 299 | if c.AWS.AccessKeyID != "" && c.AWS.SecretAccessKey != "" { |
| 300 | conf = conf.WithCredentials(credentials.NewStaticCredentials( |
| 301 | c.AWS.AccessKeyID, c.AWS.SecretAccessKey, c.AWS.SessionToken, |
| 302 | )) |
| 303 | } |
| 304 | return ttnblob.AWS(ctx, bucket, conf) |
| 305 | case "azure": |
| 306 | if c.Azure.AccountName == "" { |
| 307 | return nil, errMissingBlobConfig.New() |
| 308 | } |
| 309 | return ttnblob.Azure(ctx, c.Azure.AccountName, bucket) |
| 310 | case "gcp": |
| 311 | if c.GCP.Credentials != "" { |
| 312 | return ttnblob.GCP(ctx, bucket, []byte(c.GCP.Credentials)) |
| 313 | } |
| 314 | if c.GCP.CredentialsFile != "" { |
| 315 | jsonCreds, err := os.ReadFile(c.GCP.CredentialsFile) |
| 316 | if err != nil { |
| 317 | return nil, err |
| 318 | } |
| 319 | return ttnblob.GCP(ctx, bucket, jsonCreds) |
| 320 | } |
| 321 | return nil, errMissingBlobConfig.New() |
| 322 | default: |
| 323 | return nil, errUnknownBlobProvider.WithAttributes("provider", c.Provider) |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // BlobPathConfig configures the blob bucket and path. |
| 328 | type BlobPathConfig struct { |