Exemple #1
0
func listObjectsInBuckets(client *s3.S3, buckets []string, match string) error {
	for _, b := range buckets {
		bucket := client.Bucket(b)

		contents, err := bucket.GetBucketContents()
		if err != nil {
			return err
		}

		matches := []string{}
		for key, value := range *contents {
			if len(match) > 0 {
				if strings.HasPrefix(key, match) {
					matches = append(matches, key)
				}
			} else {
				fmt.Printf("%s (%d)\n", key, value.Size)
			}
		}

		if len(match) > 0 {
			sort.Strings(matches)
			fmt.Printf("%s\n", matches[len(matches)-1])
		}

		return nil
	}

	return nil
}
Exemple #2
0
func testBucket(s *s3.S3) *s3.Bucket {
	// Watch out! If this function is corrupted and made to match with something
	// people own, killBucket will happily remove *everything* inside the bucket.
	key := s.Auth.AccessKey
	if len(key) >= 8 {
		key = s.Auth.AccessKey[:8]
	}
	return s.Bucket(fmt.Sprintf("goamz-%s-%s", s.Region.Name, key))
}
Exemple #3
0
func (s *S3Config) Bucket(client *s3.S3) (*s3.Bucket, error) {
	b := client.Bucket(s.BucketName)
	resp, err := client.ListBuckets()
	if err != nil {
		return b, err
	}
	if bucketOfName(resp.Buckets, s.BucketName) == nil {
		err = b.PutBucket(s3.ACL(s.Acl))
		if err != nil {
			return b, err
		}
	}
	return b, nil
}