Example #1
0
func (so *s3Options) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	repo := args[0]

	s3 := s3.New(awsAuth, awsRegion)
	buk := s3.Bucket(defBucket)

	data, err := buk.Get("/binary/repos/repositories")

	if err != nil {
		return err
	}

	ts := &env.TagStore{}

	err = json.Unmarshal(data, &ts)

	id, err := ts.Lookup(repo)

	if err != nil {
		return err
	}

	dts, err := env.DefaultTagStore()

	if err != nil {
		return err
	}

	i := &Importer{tags: ts, sysTags: dts}

	if !so.Force {
		if i.alreadyExists(id) {
			return fmt.Errorf("Already have %s, skipping download\n", utils.TruncateID(id))
		}
	}

	fmt.Printf("Downloading %s (%s)\n", repo, utils.TruncateID(id))

	err = i.download(buk, id)

	dts.Flush()

	return err
}
func (u *S3Uploader) Setup(destination string) error {
	u.Destination = destination

	// Setup the AWS authentication
	auth, err := aws.EnvAuth()
	if err != nil {
		return errors.New("Error loading AWS credentials: " + err.Error())
	}

	// Decide what region to use
	// https://github.com/crowdmob/goamz/blob/master/aws/regions.go
	// I think S3 defaults to us-east-1
	regionName := "us-east-1"
	if os.Getenv("AWS_DEFAULT_REGION") != "" {
		regionName = os.Getenv("AWS_DEFAULT_REGION")
	}

	// Check to make sure the region exists
	region, ok := aws.Regions[regionName]
	if ok == false {
		return errors.New("Unknown AWS Region `" + 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
}
Example #3
0
// Bucket returns the default S3 bucket for this application (configured by
// env)
func Bucket() *s3.Bucket {
	// TODO: is this expensive? Should I be making it a singleton?
	s3 := s3.New(auth(), aws.USEast)
	return s3.Bucket(os.Getenv("S3_BUCKET"))
}