Exemplo n.º 1
0
func (u *s3upload) uploadToBucket(bucket s3.Bucket, sourcePath string) error {
	logData := lager.Data{
		"source_path": sourcePath,
		"target_path": u.targetPath,
		"bucket":      u.bucketName,
	}

	u.logInfo("upload", "starting", logData)

	err := bucket.Upload(sourcePath, u.targetPath)
	if err != nil {
		u.logError("upload", err, logData)
		return err
	}

	u.logInfo("upload", "done", logData)

	return nil
}
Exemplo n.º 2
0
		logger = lager.NewLogger("logger")
		log = gbytes.NewBuffer()
		logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))

		fakeRegion = aws.Region{
			Name:                 "fake_region",
			S3Endpoint:           fakeS3EndpointURL,
			S3LocationConstraint: true,
		}
		goamzBucketClient = goamz.New(aws.Auth{}, fakeRegion).Bucket(bucketName)
	})

	Describe("GetOrCreateBucket", func() {
		Context("when the bucket already exists", func() {
			var (
				err    error
				bucket s3.Bucket
			)

			BeforeEach(func() {
				err := goamzBucketClient.PutBucket(goamz.BucketOwnerFull)
				Expect(err).NotTo(HaveOccurred())

				client := s3.NewClient(fakeS3EndpointURL, "accessKey", "secretKey", logger)
				bucket, err = client.GetOrCreateBucket(bucketName)
			})

			AfterEach(func() {
				err := goamzBucketClient.DelBucket()
				Expect(err).NotTo(HaveOccurred())
			})
Exemplo n.º 3
0
			bucket := s3.NewBucket("bucket-name", "endpoint", "key", "secret", nil)
			Expect(bucket.Name()).To(Equal("bucket-name"))
		})
	})

	Describe(".Upload", func() {
		var (
			targetPath         = "path/to/target"
			bucketName         = "my-bucket"
			expectedSourcePath = "path/to/source"
			expectedEndpoint   = "http://foo.bar"
			expectedEnvKey     = "FOO"
			expectedEnvVar     = "BAR"
			expectedKey        = "AWS-ACCESS-KEY"
			expectedSecret     = "AWS-SECRET-KEY"
			expectedBucketPath string
			uploadErr          error
			bucket             s3.Bucket
			cmd                *fakeCommand
			cmdEnvironment     []string
			cmdFactory         s3.CommandFactory
			generatedCmd       string
			logger             lager.Logger
			log                *gbytes.Buffer
		)

		BeforeEach(func() {
			expectedBucketPath = fmt.Sprintf("s3://%s/%s", bucketName, targetPath)

			cmd = &fakeCommand{}