Exemplo n.º 1
0
func (store S3) remoteBucket() (*s3.Bucket, error) {
	if conn == nil {
		conn = s3.New(store.auth(), aws.Regions[store.region])
	}

	return conn.Bucket(store.bucket)
}
Exemplo n.º 2
0
func setupS3Backend(t *testing.T) *bes3.S3Backend {
	s.config = &s3test.Config{
		Send409Conflict: true,
	}
	srv, err := s3test.NewServer(s.config)
	OK(t, err)
	s.srv = srv

	s.region = aws.Region{
		Name:                 "faux-region-1",
		S3Endpoint:           srv.URL(),
		S3LocationConstraint: true, // s3test server requires a LocationConstraint
	}

	s.auth = aws.Auth{"abc", "123"}

	service := s3.New(s.auth, s.region)
	bucket, berr := service.Bucket("testbucket")
	OK(t, berr)
	err = bucket.PutBucket("private")
	OK(t, err)

	t.Logf("created s3 backend locally")

	return bes3.OpenS3Bucket(bucket, "testbucket")
}
Exemplo n.º 3
0
Arquivo: s3.go Projeto: polds/storage
func (store S3) remoteBucket() (*s3.Bucket, error) {
	if amazonConnection == nil {
		amazonConnection = s3.New(store.auth(), aws.Regions[store.region])
	}

	return amazonConnection.Bucket(store.bucket)
}
Exemplo n.º 4
0
func (s *AmazonClientSuite) SetUpSuite(c *C) {
	if !testutil.Amazon {
		c.Skip("live tests against AWS disabled (no -amazon)")
	}
	s.srv.SetUp(c)
	s.s3 = s3.New(s.srv.auth, s.Region)
	// In case tests were interrupted in the middle before.
	s.ClientTests.Cleanup()
}
Exemplo n.º 5
0
func (s *AmazonDomainClientSuite) SetUpSuite(c *C) {
	if !testutil.Amazon {
		c.Skip("live tests against AWS disabled (no -amazon)")
	}
	s.srv.SetUp(c)
	region := s.Region
	region.S3BucketEndpoint += "https://s3.amazonaws.com/${bucket}/"
	s.s3 = s3.New(s.srv.auth, region)
	s.ClientTests.Cleanup()
}
Exemplo n.º 6
0
func (s *S) SetUpSuite(c *C) {
	testServer.Start()
	s.s3 = s3.New(
		aws.Auth{"abc", "123"},
		aws.Region{
			Name:       "faux-region-1",
			S3Endpoint: testServer.URL,
		},
	)
}
Exemplo n.º 7
0
Arquivo: s3.go Projeto: marete/restic
// Open opens the S3 backend at bucket and region.
func Open(regionname, bucketname string) (backend.Backend, error) {
	auth, err := aws.EnvAuth()
	if err != nil {
		return nil, err
	}

	client := s3.New(auth, aws.Regions[regionname])

	s3bucket, s3err := client.Bucket(bucketname)
	if s3err != nil {
		return nil, s3err
	}

	return OpenS3Bucket(s3bucket, bucketname), nil
}
Exemplo n.º 8
0
func awsClients(cloud environs.CloudSpec) (*ec2.EC2, *s3.S3, error) {
	if err := validateCloudSpec(cloud); err != nil {
		return nil, nil, errors.Annotate(err, "validating cloud spec")
	}

	credentialAttrs := cloud.Credential.Attributes()
	accessKey := credentialAttrs["access-key"]
	secretKey := credentialAttrs["secret-key"]
	auth := aws.Auth{
		AccessKey: accessKey,
		SecretKey: secretKey,
	}

	// TODO(axw) define region in terms of EC2 and S3 endpoints.
	region := aws.Regions[cloud.Region]
	signer := aws.SignV4Factory(region.Name, "ec2")
	return ec2.New(auth, region, signer), s3.New(auth, region), nil
}
Exemplo n.º 9
0
// Communicate with all endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *C) {
	type result struct {
		aws.Region
		error
	}

	results := make(chan result, len(aws.Regions))
	for _, region := range aws.Regions {
		go func(r aws.Region) {
			s := s3.New(s.s3.Auth, r)
			b, err := s.Bucket("goamz-" + s.Auth.AccessKey)
			if !c.Check(err, IsNil) {
				return
			}

			_, err = b.Get("non-existent")
			if !c.Check(err, NotNil) {
				return
			}

			results <- result{r, err}
		}(region)
	}
	for _ = range aws.Regions {
		result := <-results
		if s3_err, ok := result.error.(*s3.Error); ok {
			if result.Region == aws.CNNorth && s3_err.Code == "InvalidAccessKeyId" {
				c.Log("You must utilize an account specifically for CNNorth.")
				continue
			}
			c.Check(s3_err.Code, Matches, "NoSuchBucket")
		} else if _, ok = result.error.(*net.DNSError); ok {
			// Okay as well.
		} else {
			c.Errorf("Non-S3 error: %s", result.error)
		}
	}
}
Exemplo n.º 10
0
func (s *LocalServerSuite) SetUpSuite(c *C) {
	s.srv.SetUp(c)
	s.clientTests.s3 = s3.New(s.srv.auth, s.srv.region)
	s.clientTests.Cleanup()
}