Skip to content

Commit 63b16d6

Browse files
committed
main sync develop
2 parents fc0208e + c49b4aa commit 63b16d6

5 files changed

Lines changed: 113 additions & 37 deletions

File tree

ci-runner/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FROM docker:20.10.24-dind
1818
RUN apk update && apk add --no-cache --virtual .build-deps && apk add bash && apk add make && apk add curl && apk add git && apk add zip && apk add jq && \
1919
ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
2020
apk -Uuv add groff less python3 py3-pip && \
21-
pip3 install awscli && \
21+
pip3 install awscli==1.38.11 && \
2222
apk --purge -v del py-pip && \
2323
rm /var/cache/apk/*
2424

ci-runner/vendor/github.com/devtron-labs/common-lib/blob-storage/AwsS3Blob.go

Lines changed: 41 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci-runner/vendor/github.com/devtron-labs/common-lib/blob-storage/BlobUtils.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common-lib/blob-storage/AwsS3Blob.go

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,31 +203,55 @@ func (r *Resolver) ResolveEndpoint(_ context.Context, params s3v2.EndpointParame
203203
return transport.Endpoint{URI: u}, nil
204204
}
205205

206-
func GetS3BucketBasicsClient(ctx context.Context, region string, accessKey, secretKey string, endpointUrl string) (BucketBasics, error) {
207-
cfg, err := config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(credentialsv2.NewStaticCredentialsProvider(accessKey, secretKey, "")))
208-
if err != nil {
209-
return BucketBasics{}, err
206+
func getS3DefaultSDKConfig(ctx context.Context, region, accessKey, secretKey, endpointUrl string) (s3Cfg awsv2.Config, err error) {
207+
if len(endpointUrl) != 0 && len(region) == 0 {
208+
// case handled for minio
209+
region = "us-east-1"
210+
s3Cfg = awsv2.Config{Region: region}
211+
return s3Cfg, nil
210212
}
211-
sdkConfig := awsv2.Config{Region: region}
212-
sdkConfig.Credentials = cfg.Credentials
213-
var s3Client *s3v2.Client
214-
if len(endpointUrl) > 0 {
215-
if len(region) == 0 {
216-
region = "us-east-1" //for minio
217-
sdkConfig = awsv2.Config{Region: region}
213+
var cfg awsv2.Config
214+
if len(accessKey) == 0 || len(secretKey) == 0 {
215+
// case handled for S3 IAM role
216+
cfg, err = config.LoadDefaultConfig(ctx, config.WithRegion(region))
217+
if err != nil {
218+
return awsv2.Config{}, err
218219
}
219-
endpointURL, err := url.Parse(endpointUrl)
220+
} else {
221+
// case handled for S3 with access key and secret key
222+
cfg, err = config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(credentialsv2.NewStaticCredentialsProvider(accessKey, secretKey, "")))
223+
if err != nil {
224+
return awsv2.Config{}, err
225+
}
226+
}
227+
s3Cfg = awsv2.Config{Region: region, Credentials: cfg.Credentials}
228+
return s3Cfg, nil
229+
}
230+
231+
func getS3Client(s3Cfg awsv2.Config, endpointUrl string) (s3Client *s3v2.Client, err error) {
232+
if len(endpointUrl) > 0 {
233+
parsedEndpointUrl, err := url.Parse(endpointUrl)
220234
if err != nil {
221-
return BucketBasics{}, err
235+
return s3Client, err
222236
}
223-
s3Client = s3v2.NewFromConfig(sdkConfig, func(o *s3v2.Options) {
237+
return s3v2.NewFromConfig(s3Cfg, func(o *s3v2.Options) {
224238
o.UsePathStyle = true
225-
o.EndpointResolverV2 = &Resolver{URL: endpointURL}
226-
})
239+
o.EndpointResolverV2 = &Resolver{URL: parsedEndpointUrl}
240+
}), nil
227241
} else {
228-
s3Client = s3v2.NewFromConfig(sdkConfig)
242+
return s3v2.NewFromConfig(s3Cfg), nil
229243
}
244+
}
230245

246+
func GetS3BucketBasicsClient(ctx context.Context, region, accessKey, secretKey, endpointUrl string) (BucketBasics, error) {
247+
s3Cfg, err := getS3DefaultSDKConfig(ctx, region, accessKey, secretKey, endpointUrl)
248+
if err != nil {
249+
return BucketBasics{}, err
250+
}
251+
s3Client, err := getS3Client(s3Cfg, endpointUrl)
252+
if err != nil {
253+
return BucketBasics{}, err
254+
}
231255
bucketBasics := BucketBasics{S3Client: s3Client}
232256
return bucketBasics, nil
233257
}

common-lib/blob-storage/BlobUtils.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@ import (
2222
"os/exec"
2323
)
2424

25+
const (
26+
WhenSupported = "when_supported"
27+
WhenRequired = "when_required"
28+
)
29+
2530
func setAWSEnvironmentVariables(s3Config *AwsS3BaseConfig, command *exec.Cmd) {
2631
if s3Config.AccessKey != "" && s3Config.Passkey != "" {
27-
command.Env = append(os.Environ(),
32+
command.Env = os.Environ()
33+
command.Env = append(command.Env,
2834
fmt.Sprintf("AWS_ACCESS_KEY_ID=%s", s3Config.AccessKey),
2935
fmt.Sprintf("AWS_SECRET_ACCESS_KEY=%s", s3Config.Passkey),
3036
)
3137
}
38+
if s3Config.EndpointUrl != "" {
39+
command.Env = append(command.Env,
40+
// The below is required for https://github.com/aws/aws-cli/issues/9214
41+
// This is only required for secure endpoints only https://github.com/boto/boto3/issues/4398#issuecomment-2712259341
42+
fmt.Sprintf("AWS_REQUEST_CHECKSUM_CALCULATION=%s", WhenRequired),
43+
fmt.Sprintf("AWS_RESPONSE_CHECKSUM_VALIDATION=%s", WhenRequired),
44+
)
45+
}
3246
}

0 commit comments

Comments
 (0)