Example #1
0
File: s3.go Project: aya/pb
func (s *S3MultipartUploadSession) getS3Bucket() *s3.Bucket {
	auth := s.awsAuth()
	s3 := s3.New(auth, aws.Regions[s.s3Region])

	s3.ConnectTimeout = time.Second * 10
	s3.ReadTimeout = time.Second * 20
	s3.WriteTimeout = time.Second * 20
	s3.RequestTimeout = time.Second * 120

	return s3.Bucket(s.s3Bucket)
}
Example #2
0
// NewS3Client creates a new configured instance of s3Client.
// You can either pass the AWS credentials as arguments to the function or
// pass empty strings. In this case environment variables will be used for
// the credentials. Supported environment variables are AWS_ACCESS_KEY_ID,
// AWS_SECRET_ACCESS_KEY and S3_ENDPOINT.
func NewS3Client(awsAccessKey, awsSecretKey, s3Endpoint, bucket string) (fetchclient.FetchClient, error) {
	if awsAccessKey == "" {
		awsAccessKey = os.Getenv("AWS_ACCESS_KEY_ID")
	}

	if awsSecretKey == "" {
		awsSecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
	}

	if s3Endpoint == "" {
		s3Endpoint = os.Getenv("S3_ENDPOINT")
	}

	if awsAccessKey == "" {
		return nil, errgo.New("AWS_ACCESS_KEY_ID or flag is empty")
	}

	if awsSecretKey == "" {
		return nil, errgo.New("AWS_SECRET_ACCESS_KEY or flag is empty")
	}

	if s3Endpoint == "" {
		return nil, errgo.New("S3_ENDPOINT not found in environment or flag is empty")
	}

	s3 := s3.New(
		aws.Auth{
			AccessKey: awsAccessKey,
			SecretKey: awsSecretKey,
		},
		aws.Region{
			S3Endpoint: "https://" + s3Endpoint,
		},
	)

	s3c := &S3Client{
		bucket: s3.Bucket(bucket),
	}

	return s3c, nil
}