func New(config *config_package.Config) BlobStore { switch config.ActiveBlobStore() { case config_package.DAVBlobStore: return dav_blob_store.New(config.BlobStore()) case config_package.S3BlobStore: return s3_blob_store.New(config.S3BlobStore()) } return dav_blob_store.New(config.BlobStore()) }
func (v Verifier) Verify(config *config_package.Config) (authorized bool, err error) { blobStoreConfig := config.S3BlobStore() client := s3.New(session.New(&aws.Config{ Credentials: credentials.NewStaticCredentials(blobStoreConfig.AccessKey, blobStoreConfig.SecretKey, ""), Region: aws.String(blobStoreConfig.Region), S3ForcePathStyle: aws.Bool(true), })) if v.Endpoint != "" { client.Endpoint = v.Endpoint } _, err = client.ListObjects(&s3.ListObjectsInput{ Bucket: aws.String(blobStoreConfig.BucketName), }) if err != nil { if awsErr, ok := err.(awserr.RequestFailure); ok && awsErr.StatusCode() == 403 { return false, nil } return false, err } return true, nil }
fakePasswordReader.PromptForPasswordReturns("some-secret") doneChan := test_helpers.AsyncExecuteCommandWithArgs(targetCommand, []string{"myapi.com", "--s3"}) Eventually(outputBuffer).Should(test_helpers.Say("S3 Access Key: ")) stdinWriter.Write([]byte("some-access\n")) Eventually(outputBuffer).Should(test_helpers.Say("S3 Bucket: ")) stdinWriter.Write([]byte("some-bucket\n")) Eventually(outputBuffer).Should(test_helpers.Say("S3 Region: ")) stdinWriter.Write([]byte("some-region\n")) Eventually(doneChan, 3).Should(BeClosed()) Expect(fakeBlobStoreVerifier.VerifyCallCount()).To(Equal(1)) config := fakeBlobStoreVerifier.VerifyArgsForCall(0) s3BlobTargetInfo := config.S3BlobStore() Expect(s3BlobTargetInfo.AccessKey).To(Equal("some-access")) Expect(s3BlobTargetInfo.SecretKey).To(Equal("some-secret")) Expect(s3BlobTargetInfo.BucketName).To(Equal("some-bucket")) Expect(s3BlobTargetInfo.Region).To(Equal("some-region")) newConfig := config_package.New(configPersister) Expect(newConfig.Load()).To(Succeed()) newS3BlobTargetInfo := newConfig.S3BlobStore() Expect(newS3BlobTargetInfo.AccessKey).To(Equal("some-access")) Expect(newS3BlobTargetInfo.SecretKey).To(Equal("some-secret")) Expect(newS3BlobTargetInfo.BucketName).To(Equal("some-bucket")) Expect(newS3BlobTargetInfo.Region).To(Equal("some-region")) }) })
Password: "******", })) }) It("sets the activeBlobStore to 'dav'", func() { testConfig.SetS3BlobStore("some-access-key", "some-secret-key", "some-bucket-name", "some-region") testConfig.SetBlobStore("some-host", "7474", "some-username", "some-password") Expect(testConfig.ActiveBlobStore().String()).To(Equal("dav")) }) }) Describe("TargetS3Blob", func() { It("sets the s3 blob target", func() { testConfig.SetS3BlobStore("some-access-key", "some-secret-key", "some-bucket-name", "some-region") Expect(testConfig.S3BlobStore()).To(Equal(config.S3BlobStoreConfig{ Region: "some-region", AccessKey: "some-access-key", SecretKey: "some-secret-key", BucketName: "some-bucket-name", })) }) It("sets the activeBlobStore to 's3'", func() { testConfig.SetS3BlobStore("some-access-key", "some-secret-key", "some-bucket-name", "some-region") Expect(testConfig.ActiveBlobStore().String()).To(Equal("s3")) }) }) }) type fakePersister struct {