package app import ( "context" "log" "clapclap/internal/env" "clapclap/internal/vault" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/s3" ) func S3Connection(sec *vault.UserPassSecret) *s3.Client { endpoint := env.C.AWS_ENDPOINT_URL_S3 awsRegion := env.C.AWS_REGION if endpoint == "" { log.Fatal("AWS_ENDPOINT_URL_S3 env variable is not set") } if awsRegion == "" { awsRegion = "us-east-1" } cfg, err := config.LoadDefaultConfig( context.Background(), config.WithRegion(awsRegion), config.WithCredentialsProvider( credentials.NewStaticCredentialsProvider( sec.Username, sec.Password, "", ), ), ) if err != nil { log.Fatal(err) } s3Client := s3.NewFromConfig(cfg, func(o *s3.Options) { o.UsePathStyle = true o.BaseEndpoint = &endpoint }) log.Println("Connected to S3 object storage successfully") return s3Client } func S3InternalConnection(sec *vault.UserPassSecret) *s3.Client { endpoint := env.C.INTERNAL_ENDPOINT_URL_S3 awsRegion := env.C.AWS_REGION cfg, err := config.LoadDefaultConfig( context.Background(), config.WithRegion(awsRegion), config.WithCredentialsProvider( credentials.NewStaticCredentialsProvider( sec.Username, sec.Password, "", ), ), ) if err != nil { log.Fatal(err) } s3Client := s3.NewFromConfig(cfg, func(o *s3.Options) { o.UsePathStyle = true o.BaseEndpoint = &endpoint }) log.Println("Connected internally to S3 object storage successfully") return s3Client }