Skip to content

Commit

Permalink
azure: Add new storage_create_container configuration property (#116)
Browse files Browse the repository at this point in the history
* azure: Add new storage_create_container configuration property

In some cases account does not have permissions to read container properties or create one but has all permissions to do CRUD operations inside the container, e.g. SAS tokens. To solve such use case the new configuration property was added for the Azure object storage config which creates a new container explicitly by settings `storage_create_container` to `true`. To keep backward compatibility with existing object storage configurations the default value for it is always `true`.

Signed-off-by: Andrey Pleskach <ples@aiven.io>

* Add changelog

Signed-off-by: Andrey Pleskach <ples@aiven.io>

---------

Signed-off-by: Andrey Pleskach <ples@aiven.io>
  • Loading branch information
willyborankin committed Jun 17, 2024
1 parent 39f40b8 commit 124528d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#108](https://github.com/thanos-io/objstore/pull/108) Metrics: Add native histogram definitions to histograms
- [#112](https://github.com/thanos-io/objstore/pull/112) S3: Add `DisableDualstack option.
- [#100](https://github.com/thanos-io/objstore/pull/100) s3: add DisableMultipart option
- [#116](https://github.com/thanos-io/objstore/pull/116) Azure: Add new storage_create_container configuration property

### Changed
- [#38](https://github.com/thanos-io/objstore/pull/38) *: Upgrade minio-go version to `v7.0.45`.
Expand Down
25 changes: 14 additions & 11 deletions providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

// DefaultConfig for Azure objstore client.
var DefaultConfig = Config{
Endpoint: "blob.core.windows.net",
Endpoint: "blob.core.windows.net",
StorageCreateContainer: true,
HTTPConfig: exthttp.HTTPConfig{
IdleConnTimeout: model.Duration(90 * time.Second),
ResponseHeaderTimeout: model.Duration(2 * time.Minute),
Expand All @@ -47,6 +48,7 @@ type Config struct {
StorageAccountName string `yaml:"storage_account"`
StorageAccountKey string `yaml:"storage_account_key"`
StorageConnectionString string `yaml:"storage_connection_string"`
StorageCreateContainer bool `yaml:"storage_create_container"`
ContainerName string `yaml:"container"`
Endpoint string `yaml:"endpoint"`
UserAssignedID string `yaml:"user_assigned_id"`
Expand Down Expand Up @@ -167,19 +169,20 @@ func NewBucketWithConfig(logger log.Logger, conf Config, component string) (*Buc
}

// Check if storage account container already exists, and create one if it does not.
ctx := context.Background()
_, err = containerClient.GetProperties(ctx, &container.GetPropertiesOptions{})
if err != nil {
if !bloberror.HasCode(err, bloberror.ContainerNotFound) {
return nil, err
}
_, err := containerClient.Create(ctx, nil)
if conf.StorageCreateContainer {
ctx := context.Background()
_, err = containerClient.GetProperties(ctx, &container.GetPropertiesOptions{})
if err != nil {
return nil, errors.Wrapf(err, "error creating Azure blob container: %s", conf.ContainerName)
if !bloberror.HasCode(err, bloberror.ContainerNotFound) {
return nil, err
}
_, err := containerClient.Create(ctx, nil)
if err != nil {
return nil, errors.Wrapf(err, "error creating Azure blob container: %s", conf.ContainerName)
}
level.Info(logger).Log("msg", "Azure blob container successfully created", "address", conf.ContainerName)
}
level.Info(logger).Log("msg", "Azure blob container successfully created", "address", conf.ContainerName)
}

bkt := &Bucket{
logger: logger,
containerClient: containerClient,
Expand Down

0 comments on commit 124528d

Please sign in to comment.