Skip to content

Commit

Permalink
Merge pull request #37 from GreenmaskIO/s3_storage_region_env_fix
Browse files Browse the repository at this point in the history
Fixed s3 storage region env variable usage
  • Loading branch information
wwoytenko authored Apr 1, 2024
2 parents 38ddf61 + 51b47e5 commit 7ea7185
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ two storage options are supported: `directory` and `s3`.
* `prefix` — a prefix for objects in the bucket, specified in path format
* `region` — the S3 service region
* `storage_class` — the storage class for performing object requests
* `disable_ssl` — disable SSL for interactions (default is `false`)
* `no_verify_ssl` — disable SSL certificate verification
* `access_key_id` — access key for authentication
* `secret_access_key` — secret access key for authentication
* `session_token` — session token for authentication
Expand Down
1 change: 1 addition & 0 deletions internal/storages/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
UseListObjectsV1 bool `mapstructure:"use_list_objects_v1,omitempty"`
ForcePathStyle bool `mapstructure:"force_path_style,omitempty"`
UseAccelerate bool `mapstructure:"use_accelerate,omitempty"`
NoVerifySsl bool `mapstructure:"no_verify_ssl,omitempty"`
}

func NewConfig() *Config {
Expand Down
19 changes: 18 additions & 1 deletion internal/storages/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package s3

import (
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"net/http"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -122,10 +124,20 @@ func NewStorage(ctx context.Context, cfg *Config, logLevel string) (*Storage, er
awsCfg.WithLogger(LogWrapper{logger: &log.Logger})
awsCfg.WithLogLevel(lv)

if cfg.NoVerifySsl {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
awsCfg.WithHTTPClient(&http.Client{Transport: tr})
}

if cfg.Endpoint != "" {
awsCfg.WithEndpoint(cfg.Endpoint)
}
awsCfg.WithRegion(cfg.Region)

if cfg.Region != "" {
awsCfg.WithRegion(cfg.Region)
}

if cfg.CertFile != "" {
file, err := os.Open(cfg.CertFile)
Expand All @@ -147,6 +159,11 @@ func NewStorage(ctx context.Context, cfg *Config, logLevel string) (*Storage, er
},
)

log.Debug().
Str("region", *service.Config.Region).
Str("bucket", cfg.Bucket).
Msg("s3 storage bucket")

return &Storage{
prefix: fixPrefix(path.Join(cfg.Bucket, cfg.Prefix)),
session: ses,
Expand Down

0 comments on commit 7ea7185

Please sign in to comment.