wasabi.Client   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nop 0
dl 0
loc 15
rs 9.85
c 0
b 0
f 0
1
/*
2
 * Copyright (c) 2023 Clive Walkden <[email protected]>
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to deal
6
 * in the Software without restriction, including without limitation the rights
7
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
 * copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all
12
 * copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
 * OTHER DEALINGS IN THE SOFTWARE.
22
 */
23
24
package wasabi
25
26
import (
27
	"context"
28
	"github.com/aws/aws-sdk-go-v2/aws"
29
	"github.com/aws/aws-sdk-go-v2/config"
30
	"github.com/aws/aws-sdk-go-v2/service/s3"
31
	"github.com/spf13/viper"
32
	"log"
33
)
34
35
func Client() *s3.Client {
36
	customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { //nolint:all
37
		return aws.Endpoint{ //nolint:all
38
			PartitionID:   "aws",
39
			URL:           viper.GetString("connection.url"),
40
			SigningRegion: viper.GetString("connection.region"),
41
		}, nil
42
	})
43
44
	cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithSharedConfigProfile(viper.GetString("connection.profile")), config.WithEndpointResolverWithOptions(customResolver)) //nolint:all
45
	if err != nil {
46
		log.Fatal(err)
47
	}
48
49
	return s3.NewFromConfig(cfg)
50
}
51