func (u *S3Uploader) Setup(destination string, debugHTTP bool) error { u.Destination = destination u.DebugHTTP = debugHTTP // Try to auth with S3 auth, err := awsS3Auth() if err != nil { return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error())) } // Try and get the region region, err := awsS3Region() if err != nil { return err } logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", u.BucketName(), region.Name) // Find the bucket s3 := s3.New(auth, region) bucket := s3.Bucket(u.BucketName()) // If the list doesn't return an error, then we've got our bucket _, err = bucket.List("", "", "", 0) if err != nil { return errors.New("Could not find bucket `" + u.BucketName() + "` in region `" + region.Name + "` (" + err.Error() + ")") } u.Bucket = bucket return nil }
func InitBucket(name string) error { auth, err := aws.EnvAuth() if err != nil { return err } s3 := s3.New(auth, aws.GetRegion("ap-southeast-1")) Bucket = s3.Bucket(name) return nil }
func (d S3Downloader) Start() error { // Try to auth with S3 auth, err := awsS3Auth() if err != nil { return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error())) } // Try and get the region region, err := awsS3Region() if err != nil { return err } // Split apart the bucket bucketParts := strings.Split(strings.TrimLeft(d.Bucket, "s3://"), "/") bucketName := bucketParts[0] bucketPath := strings.Join(bucketParts[1:len(bucketParts)], "/") logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", bucketName, region.Name) // Find the bucket s3 := s3.New(auth, region) bucket := s3.Bucket(bucketName) // If the list doesn't return an error, then we've got our bucket _, err = bucket.List("", "", "", 0) if err != nil { return errors.New("Could not find bucket `" + bucketName + "` in region `" + region.Name + "` (" + err.Error() + ")") } // Create the location of the file var s3Location string if bucketPath != "" { s3Location = strings.TrimRight(bucketPath, "/") + "/" + strings.TrimLeft(d.Path, "/") } else { s3Location = d.Path } // Generate a Signed URL signedURL := bucket.SignedURL(s3Location, time.Now().Add(time.Hour)) // We can now cheat and pass the URL onto our regular downloader return Download{ URL: signedURL, Path: d.Path, Destination: d.Destination, Retries: d.Retries, DebugHTTP: d.DebugHTTP, }.Start() }
func (u *S3Uploader) Setup(destination string) error { u.Destination = destination // Try to auth with S3 auth, err := awsS3Auth() if err != nil { return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error())) } regionName := "us-east-1" if os.Getenv("BUILDKITE_S3_DEFAULT_REGION") != "" { regionName = os.Getenv("BUILDKITE_S3_DEFAULT_REGION") } else if os.Getenv("AWS_DEFAULT_REGION") != "" { regionName = os.Getenv("AWS_DEFAULT_REGION") } // Check to make sure the region exists. There is a GetRegion API, but // there doesn't seem to be a way to make it error out if the region // doesn't exist. region, ok := aws.Regions[regionName] if ok == false { return errors.New("Unknown AWS S3 Region `" + regionName + "`") } logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", u.bucketName(), regionName) // Find the bucket s3 := s3.New(auth, region) bucket := s3.Bucket(u.bucketName()) // If the list doesn't return an error, then we've got our bucket _, err = bucket.List("", "", "", 0) if err != nil { return errors.New("Could not find bucket `" + u.bucketName() + "` in region `" + region.Name + "` (" + err.Error() + ")") } u.Bucket = bucket return nil }
func (d S3Downloader) Start() error { // Try to auth with S3 auth, err := awsS3Auth() if err != nil { return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error())) } // Try and get the region region, err := awsS3Region() if err != nil { return err } logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", d.BucketName(), region.Name) // Find the bucket s3 := s3.New(auth, region) bucket := s3.Bucket(d.BucketName()) // If the list doesn't return an error, then we've got our bucket _, err = bucket.List("", "", "", 0) if err != nil { return errors.New("Could not find bucket `" + d.BucketName() + "` in region `" + region.Name + "` (" + err.Error() + ")") } // Generate a Signed URL signedURL := bucket.SignedURL(d.BucketFileLocation(), time.Now().Add(time.Hour)) // We can now cheat and pass the URL onto our regular downloader return Download{ Client: *http.DefaultClient, URL: signedURL, Path: d.Path, Destination: d.Destination, Retries: d.Retries, DebugHTTP: d.DebugHTTP, }.Start() }