Skip to content

Commit

Permalink
Azure CLI review
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoBraveCoding committed Nov 27, 2023
1 parent a259abd commit 42f37ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pkg/storage/bucket/azure/bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucke
bucketConfig := azure.Config{
StorageAccountName: cfg.StorageAccountName,
StorageAccountKey: cfg.StorageAccountKey.String(),
StorageConnectionString: cfg.ConnectionString.String(),
StorageConnectionString: cfg.StorageConnectionString.String(),
ContainerName: cfg.ContainerName,
Endpoint: cfg.EndpointSuffix,
MaxRetries: cfg.MaxRetries,
UserAssignedID: cfg.UserAssignedID,
PipelineConfig: azure.PipelineConfig{
MaxRetryDelay: model.Duration(cfg.MaxRetryDelay),
},
HTTPConfig: azure.HTTPConfig{
IdleConnTimeout: model.Duration(cfg.HTTP.IdleConnTimeout),
ResponseHeaderTimeout: model.Duration(cfg.HTTP.ResponseHeaderTimeout),
Expand Down
19 changes: 12 additions & 7 deletions pkg/storage/bucket/azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azure

import (
"flag"
"time"

"net/http"

Expand All @@ -19,12 +20,14 @@ type HTTPConfig struct {

// Config holds the config options for an Azure backend
type Config struct {
StorageAccountName string `yaml:"account_name"`
StorageAccountKey flagext.Secret `yaml:"account_key"`
ConnectionString flagext.Secret `yaml:"connection_string"`
ContainerName string `yaml:"container_name"`
EndpointSuffix string `yaml:"endpoint_suffix"`
MaxRetries int `yaml:"max_retries"`
StorageAccountName string `yaml:"account_name"`
StorageAccountKey flagext.Secret `yaml:"account_key"`
StorageConnectionString flagext.Secret `yaml:"connection_string"`
ContainerName string `yaml:"container_name"`
EndpointSuffix string `yaml:"endpoint_suffix"`
UserAssignedID string `yaml:"user_assigned_id"`
MaxRetries int `yaml:"max_retries"`
MaxRetryDelay time.Duration `yaml:"max_retry_delay"`

HTTP HTTPConfig `yaml:"http"`
}
Expand All @@ -38,9 +41,11 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.StringVar(&cfg.StorageAccountName, prefix+"azure.account-name", "", "Azure storage account name")
f.Var(&cfg.StorageAccountKey, prefix+"azure.account-key", "Azure storage account key")
f.Var(&cfg.ConnectionString, prefix+"azure.connection-string", "If `connection-string` is set, the values of `account-name` and `endpoint-suffix` values will not be used. Use this method over `account-key` if you need to authenticate via a SAS token. Or if you use the Azurite emulator.")
f.Var(&cfg.StorageConnectionString, prefix+"azure.connection-string", "If `connection-string` is set, the values of `account-name` and `endpoint-suffix` values will not be used. Use this method over `account-key` if you need to authenticate via a SAS token. Or if you use the Azurite emulator.")
f.StringVar(&cfg.ContainerName, prefix+"azure.container-name", "loki", "Azure storage container name")
f.StringVar(&cfg.EndpointSuffix, prefix+"azure.endpoint-suffix", "", "Azure storage endpoint suffix without schema. The account name will be prefixed to this value to create the FQDN")
f.StringVar(&cfg.UserAssignedID, prefix+"azure.user-assigned-id", "", "User assigned identity ID to authenticate to the Azure storage account.")
f.IntVar(&cfg.MaxRetries, prefix+"azure.max-retries", 20, "Number of retries for recoverable errors")
f.DurationVar(&cfg.MaxRetryDelay, prefix+"azure.max-retry-delay", 500*time.Millisecond, "Maximum time to wait before retrying a request.")
cfg.HTTP.RegisterFlagsWithPrefix(prefix+"azure.http", f)
}
12 changes: 6 additions & 6 deletions pkg/storage/bucket/azure/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ http:
max_connections_per_host: 8
`,
expectedConfig: Config{
StorageAccountName: "test-account-name",
StorageAccountKey: flagext.SecretWithValue("test-account-key"),
ConnectionString: flagext.SecretWithValue("test-connection-string"),
ContainerName: "test-container-name",
EndpointSuffix: "test-endpoint-suffix",
MaxRetries: 1,
StorageAccountName: "test-account-name",
StorageAccountKey: flagext.SecretWithValue("test-account-key"),
StorageConnectionString: flagext.SecretWithValue("test-connection-string"),
ContainerName: "test-container-name",
EndpointSuffix: "test-endpoint-suffix",
MaxRetries: 1,
HTTP: HTTPConfig{
Config: http.Config{
IdleConnTimeout: 2 * time.Second,
Expand Down

0 comments on commit 42f37ba

Please sign in to comment.