1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/sdk/go/arvadostest"
13 "github.com/aws/aws-sdk-go-v2/aws"
14 "github.com/aws/aws-sdk-go-v2/aws/defaults"
15 "github.com/aws/aws-sdk-go-v2/aws/ec2metadata"
16 "github.com/aws/aws-sdk-go-v2/aws/ec2rolecreds"
17 "github.com/aws/aws-sdk-go-v2/aws/endpoints"
18 "github.com/aws/aws-sdk-go-v2/service/s3"
19 check "gopkg.in/check.v1"
22 func (s *IntegrationSuite) TestS3AWSSDK(c *check.C) {
24 defer stage.teardown(c)
26 cfg := defaults.Config()
27 cfg.Credentials = aws.NewChainProvider([]aws.CredentialsProvider{
28 aws.NewStaticCredentialsProvider(arvadostest.ActiveTokenUUID, arvadostest.ActiveToken, ""),
29 ec2rolecreds.New(ec2metadata.New(cfg)),
31 cfg.EndpointResolver = aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
34 URL: s.testServer.URL,
35 SigningRegion: "custom-signing-region",
38 return endpoints.NewDefaultResolver().ResolveEndpoint(service, region)
41 client.ForcePathStyle = true
42 listreq := client.ListObjectsV2Request(&s3.ListObjectsV2Input{
43 Bucket: aws.String(arvadostest.FooCollection),
44 MaxKeys: aws.Int64(100),
45 Prefix: aws.String(""),
46 ContinuationToken: nil,
48 resp, err := listreq.Send(context.Background())
49 c.Assert(err, check.IsNil)
50 c.Check(resp.Contents, check.HasLen, 1)
51 for _, key := range resp.Contents {
52 c.Check(*key.Key, check.Equals, "foo")
55 p := make([]byte, 100000000)
59 putreq := client.PutObjectRequest(&s3.PutObjectInput{
60 Body: bytes.NewReader(p),
61 Bucket: aws.String(stage.collbucket.Name),
62 ContentType: aws.String("application/octet-stream"),
63 Key: aws.String("aaaa"),
65 _, err = putreq.Send(context.Background())
66 c.Assert(err, check.IsNil)
68 getreq := client.GetObjectRequest(&s3.GetObjectInput{
69 Bucket: aws.String(stage.collbucket.Name),
70 Key: aws.String("aaaa"),
72 getresp, err := getreq.Send(context.Background())
73 c.Assert(err, check.IsNil)
74 getdata, err := ioutil.ReadAll(getresp.Body)
75 c.Assert(err, check.IsNil)
76 c.Check(bytes.Equal(getdata, p), check.Equals, true)