func getObjectAcl(c *s3.S3) { putObject(c) key := "aws/config.go" out, err := c.GetObjectACL( &s3.GetObjectACLInput{ Bucket: &bucket, Key: &key, }, ) if err != nil { panic(err) } grants := out.Grants for i := 0; i < len(grants); i++ { grant := grants[i] grantee := grant.Grantee if grantee.DisplayName != nil { fmt.Println(*grantee.DisplayName) } if grantee.ID != nil { fmt.Println(*grantee.ID) } if grantee.Type != nil { fmt.Println(*grantee.Type) } if grantee.URI != nil { fmt.Println(*grantee.URI) } if grant.Permission != nil { fmt.Println(*grant.Permission) } fmt.Println("---------") } }
func runTests(t *testing.T, svc *s3.S3, tests []s3BucketTest) { for _, test := range tests { req, _ := svc.ListObjectsRequest(&s3.ListObjectsInput{Bucket: &test.bucket}) req.Build() assert.Equal(t, test.url, req.HTTPRequest.URL.String()) } }
func putBucket(c *s3.S3) { acl := "public-read" _, err := c.CreateBucket(&s3.CreateBucketInput{ ACL: &acl, Bucket: &bucket, }) checkError("put bucket", err, "BucketAlreadyExists") }
func deleteBucket(c *s3.S3) { putObject(c) _, err := c.DeleteBucket( &s3.DeleteBucketInput{ Bucket: &bucket, }, ) checkError("delete bucket", err, "BucketNotEmpty") }
func getBucketAcl(c *s3.S3) { _, err := c.GetBucketACL( &s3.GetBucketACLInput{ Bucket: &bucket, }, ) if err != nil { panic(err) } }
func putBucketAcl(c *s3.S3) { acl := "public-read" out, err := c.PutBucketACL(&s3.PutBucketACLInput{ ACL: &acl, Bucket: &bucket, }) if err != nil { panic(err) } fmt.Println(out) }
func headBucket(c *s3.S3) { out, err := c.HeadBucket( &s3.HeadBucketInput{ Bucket: &bucket, }, ) if err != nil { panic(err) } fmt.Println(out) }
func getBucketLogging(c *s3.S3) { out, err := c.GetBucketLogging( &s3.GetBucketLoggingInput{ Bucket: &bucket, }, ) if err != nil { panic(err) } fmt.Println(*out.LoggingEnabled.TargetBucket) fmt.Println(*out.LoggingEnabled.TargetPrefix) }
func getObjectPresignedUrl(c *s3.S3) { key := "aws/config.go" content := "text/html" url, _ := c.GetObjectPresignedUrl( &s3.GetObjectInput{ Bucket: &bucket, Key: &key, ResponseContentType: &content, }, 1444370289000000000, ) fmt.Println(url) }
func deleteObject(c *s3.S3) { putObject(c) key := "aws/config.go" _, err := c.DeleteObject( &s3.DeleteObjectInput{ Bucket: &bucket, Key: &key, }, ) if err != nil { panic(err) } }
func getBucketLocation(c *s3.S3) { out, err := c.GetBucketLocation( &s3.GetBucketLocationInput{ Bucket: &bucket, }, ) if err != nil { panic(err) } if *out.LocationConstraint != "HANGZHOU" { panic("location expected HANGZHOU but not") } }
func copyObject(c *s3.S3) { bucket := "aa-go-sdk" source := "aa-go-sdk/aws/config.go" key := "test" out, _ := c.CopyObject( &s3.CopyObjectInput{ Bucket: &bucket, Key: &key, CopySource: &source, }, ) fmt.Println(out) }
func multipart(c *s3.S3) { key := "中文" acl := "public-read" out, _ := c.CreateMultipartUpload( &s3.CreateMultipartUploadInput{ Bucket: &bucket, Key: &key, ACL: &acl, }, ) uploadid := out.UploadID var partnum int64 partnum = 1 s := strings.NewReader("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") uploadRest, _ := c.UploadPart( &s3.UploadPartInput{ Bucket: &bucket, Key: &key, UploadID: uploadid, PartNumber: &partnum, Body: s, }, ) fmt.Println(uploadRest) listRet, _ := c.ListParts( &s3.ListPartsInput{ Bucket: &bucket, Key: &key, UploadID: uploadid, }, ) fmt.Println("123") listP := listRet.Parts for i := 0; i < len(listP); i++ { alistP := listP[i] fmt.Println(*alistP.PartNumber) fmt.Println(*alistP.ETag) } fmt.Println(*listRet.Key) fmt.Println("123") var parts []*s3.CompletedPart apart := &s3.CompletedPart{ ETag: listRet.Parts[0].ETag, PartNumber: listRet.Parts[0].PartNumber, } parts = append(parts, apart) comRet, _ := c.CompleteMultipartUpload( &s3.CompleteMultipartUploadInput{ Bucket: &bucket, Key: &key, UploadID: uploadid, MultipartUpload: &s3.CompletedMultipartUpload{ Parts: parts, }, }, ) fmt.Println(comRet) }
func listObjects(c *s3.S3) { delimiter := "/" out, err := c.ListObjects( &s3.ListObjectsInput{ Bucket: &bucket, Delimiter: &delimiter, }, ) if err != nil { panic(err) } if *out.Delimiter != "/" { panic("list objects delimiter expected / but not") } }
func putObject(c *s3.S3) { key := "aws/config.go" contenttype := "application/ocet-stream" out, err := c.PutObject( &s3.PutObjectInput{ Bucket: &bucket, Key: &key, Body: strings.NewReader("content"), ContentType: &contenttype, }, ) if err != nil { panic(err) } fmt.Println(out) }
func listBuckets(c *s3.S3) { out, err := c.ListBuckets(nil) if err != nil { panic(err) } buckets := out.Buckets found := false for i := 0; i < len(buckets); i++ { if *buckets[i].Name == bucket { found = true } } if !found { panic("list buckets expected found but not") } }
func deleteObjects(c *s3.S3) { key := "test" var objects []*s3.ObjectIdentifier objects = append(objects, &s3.ObjectIdentifier{Key: &key}) out, _ := c.DeleteObjects( &s3.DeleteObjectsInput{ Bucket: &bucket, Delete: &s3.Delete{ Objects: objects, }, }, ) fmt.Println(out) }
func putBucketLogging(c *s3.S3) { prefix := "x-kss-" out, err := c.PutBucketLogging(&s3.PutBucketLoggingInput{ Bucket: &bucket, BucketLoggingStatus: &s3.BucketLoggingStatus{ LoggingEnabled: &s3.LoggingEnabled{ TargetBucket: &bucket, TargetPrefix: &prefix, }, }, }) if err != nil { panic(err) } fmt.Println(out) }
func getObject(c *s3.S3) { putObject(c) key := "aws/config.go" out, err := c.GetObject( &s3.GetObjectInput{ Bucket: &bucket, Key: &key, }, ) if err != nil { panic(err) } fmt.Println(out.Metadata) fmt.Println(*out.ContentLength) fmt.Println(*out.ContentType) b := make([]byte, 20) n, err := out.Body.Read(b) fmt.Printf("%-20s %-2v %v\n", b[:n], n, err) }
func headObject(c *s3.S3) { putObject(c) key := "aws/config.go" out, err := c.HeadObject( &s3.HeadObjectInput{ Bucket: &bucket, Key: &key, }, ) if err != nil { panic(err) } fmt.Println(out.Metadata) fmt.Println(*out.ContentLength) fmt.Println(*out.ContentType) }