예제 #1
0
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())
	}
}
예제 #2
0
func putFile(svc *s3.S3, bucket, object string, reader io.ReadSeeker) error {
	_, err := svc.PutObject(&s3.PutObjectInput{
		Bucket: &bucket,
		Key:    &object,
		Body:   reader,
	})

	return err
}
예제 #3
0
func putFile(svc *s3.S3, bucket, object string, reader io.ReadSeeker) error {
	_, err := svc.PutObject(&s3.PutObjectInput{
		Bucket:      &bucket,
		Key:         &object,
		Body:        reader,
		ContentType: aws.String("application/tar"),
	})

	return err
}
예제 #4
0
func getOrCreateBucket(svc *s3.S3, bucketName string) error {
	_, err := svc.HeadBucket(&s3.HeadBucketInput{
		Bucket: &bucketName,
	})

	if reqErr, ok := err.(awserr.RequestFailure); ok && reqErr.StatusCode() == 404 {
		logrus.Infof("Creating bucket %s", bucketName)
		_, err = svc.CreateBucket(&s3.CreateBucketInput{
			Bucket: &bucketName,
		})
	}

	return err
}
예제 #5
0
func Do(db *bolt.DB, s3Bucket *s3.S3, bucketname string) error {
	err := db.View(func(tx *bolt.Tx) error {
		var b bytes.Buffer
		buffInMem := bufio.NewWriter(&b)
		_, err := tx.WriteTo(buffInMem)
		backupdate := time.Now()
		params := &s3.PutObjectInput{
			Bucket:               aws.String(bucketname),
			Key:                  aws.String(backupdate.Format("2006_01_02_15-04-05")),
			Body:                 bytes.NewReader(b.Bytes()),
			ACL:                  aws.String("authenticated-read"),
			ServerSideEncryption: aws.String("AES256"),
			Metadata: &map[string]*string{
				"bolt-backup": aws.String(backupdate.Format("2006/01/02/15:04:05")),
			},
		}
		_, err = s3Bucket.PutObject(params)
		return err
	})
	return err
}