• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

shogo82148 / s3cli-mini / 11734495721

08 Nov 2024 01:39AM UTC coverage: 17.361% (-47.7%) from 65.069%
11734495721

Pull #585

github

web-flow
Bump golang.org/x/sync from 0.8.0 to 0.9.0

Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.8.0 to 0.9.0.
- [Commits](https://github.com/golang/sync/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sync
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #585: Bump golang.org/x/sync from 0.8.0 to 0.9.0

250 of 1440 relevant lines covered (17.36%)

10.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.43
/cmd/internal/config/config.go
1
package config
2

3
import (
4
        "context"
5
        "sync"
6

7
        "github.com/aws/aws-sdk-go-v2/aws"
8
        "github.com/aws/aws-sdk-go-v2/config"
9
        "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
10
        "github.com/aws/aws-sdk-go-v2/service/s3"
11
        "github.com/shogo82148/s3cli-mini/cmd/internal/interfaces"
12
        "github.com/spf13/cobra"
13
)
14

15
var mu sync.Mutex
16
var debug bool
17
var awsConfigLoaded bool
18
var awsConfig aws.Config
19
var awsRegion string
20
var awsProfile string
21
var endpointURL string
22

23
// InitFlag initializes global configure.
24
func InitFlag(cmd *cobra.Command) {
×
25
        flags := cmd.PersistentFlags()
×
26
        flags.BoolVar(&debug, "debug", false, "Turn on debug logging.")
×
27
        flags.StringVar(&awsRegion, "region", "", "The region to use. Overrides config/env settings.")
×
28
        flags.StringVar(&awsProfile, "profile", "", "Use a specific profile from your credential file.")
×
29
        flags.StringVar(&endpointURL, "endpoint-url", "", "Overrides command's default URL with the given URL.")
×
30
}
×
31

32
// LoadAWSConfig returns aws.Config.
33
func LoadAWSConfig(ctx context.Context) (aws.Config, error) {
6✔
34
        mu.Lock()
6✔
35
        defer mu.Unlock()
6✔
36

6✔
37
        if awsConfigLoaded {
6✔
38
                return awsConfig.Copy(), nil
×
39
        }
×
40

41
        opts := []func(*config.LoadOptions) error{}
6✔
42

6✔
43
        if awsRegion != "" {
6✔
44
                opts = append(opts, config.WithRegion(awsRegion))
×
45
        }
×
46
        if awsProfile != "" {
6✔
47
                opts = append(opts, config.WithSharedConfigProfile(awsProfile))
×
48
        }
×
49

50
        // Load default config
51
        cfg, err := config.LoadDefaultConfig(ctx, opts...)
6✔
52
        if err != nil {
6✔
53
                return aws.Config{}, err
×
54
        }
×
55

56
        if endpointURL != "" {
6✔
57
                cfg.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
×
58
                        return aws.Endpoint{
×
59
                                URL: endpointURL,
×
60
                        }, nil
×
61
                })
×
62
        }
63
        if debug {
6✔
64
                cfg.ClientLogMode |= aws.LogSigning | aws.LogRetries | aws.LogRequest | aws.LogRequestWithBody | aws.LogResponse | aws.LogResponseWithBody
×
65
        }
×
66

67
        awsConfig = cfg
6✔
68
        awsConfigLoaded = true
6✔
69
        return awsConfig.Copy(), nil
6✔
70
}
71

72
// NewS3Client returns new S3 client.
73
func NewS3Client(ctx context.Context) (interfaces.S3Client, error) {
6✔
74
        cfg, err := LoadAWSConfig(ctx)
6✔
75
        if err != nil {
6✔
76
                return nil, err
×
77
        }
×
78
        svc := s3.NewFromConfig(cfg)
6✔
79
        return svc, nil
6✔
80
}
81

82
// NewS3ServiceClient returns new S3 client that is used for getting s3 service level operation, such as ListBucket
83
// https://docs.aws.amazon.com/AmazonS3/latest/API/RESTServiceGET.html
84
func NewS3ServiceClient(ctx context.Context) (interfaces.S3Client, error) {
×
85
        cfg, err := LoadAWSConfig(ctx)
×
86
        if err != nil {
×
87
                return nil, err
×
88
        }
×
89
        if cfg.Region == "" {
×
90
                // fall back to US East (N. Virginia)
×
91
                cfg.Region = "us-east-1"
×
92
        }
×
93
        svc := s3.NewFromConfig(cfg)
×
94
        return svc, nil
×
95
}
96

97
// NewS3BucketClient returns new S3 client that is used for the bucket.
98
func NewS3BucketClient(ctx context.Context, bucket string) (interfaces.S3Client, error) {
×
99
        cfg, err := LoadAWSConfig(ctx)
×
100
        if err != nil {
×
101
                return nil, err
×
102
        }
×
103
        svc := s3.NewFromConfig(cfg)
×
104
        region, err := manager.GetBucketRegion(ctx, svc, bucket)
×
105
        if err != nil {
×
106
                return nil, err
×
107
        }
×
108
        cfg.Region = region
×
109
        svc = s3.NewFromConfig(cfg)
×
110
        return svc, nil
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc