Beispiel #1
0
func init() {
	log.Println("Initializing AWS infomation...")
	auth, err := aws.EnvAuth() //TODO setenv auths
	if err != nil {
		log.Fatalln(err)
	}
	s3 := s3.New(auth, aws.APNortheast)
	LgtmBucket = s3.Bucket("lgtm-images")
}
Beispiel #2
0
func CreateContext(DB *sqlx.DB, p *redis.Pool, auth aws.Auth, cfg *config.Config) *Context {
	s3 := s3.New(auth, aws.USEast)
	bucket := s3.Bucket(cfg.GalleryBucket)

	return &Context{
		Pool:   p,
		DB:     DB,
		Config: cfg,
		Auth:   auth,
		S3:     s3,
		Bucket: bucket,
	}
}
Beispiel #3
0
func lookupBucket(bucketName string, auth aws.Auth) (*s3.Bucket, error) {
	log.Infof("Looking up region for bucket '%s'.", bucketName)

	var bucket *s3.Bucket = nil

	// Looking in each region for bucket
	// To do, make this less crusty and ghetto

	for region, _ := range aws.Regions {
		// Current does not support gov region or china
		if region == "us-gov-west-1" || region == "cn-north-1" {
			log.Debugf("Skipping %s", region)
			continue
		}

		log.Debugf("Looking for bucket '%s' in '%s'.", bucketName, region)
		s3 := s3.New(auth, aws.Regions[region])
		b := s3.Bucket(bucketName)

		// If list return, bucket is valid in this region.
		_, err := b.List("", "", "", 0)
		if err == nil {
			log.Infof("Found bucket '%s' in '%s'.", bucketName, region)
			bucket = b
			break
		} else if err.Error() == "Get : 301 response missing Location header" {
			log.Debugf("Bucket '%s' not found in '%s'.", bucketName, region)
			continue
		} else {
			return nil, err
		}
	}

	if bucket != nil {
		return bucket, nil
	}

	return nil, fmt.Errorf("Bucket not found.")
}
Beispiel #4
0
// Get implements Client.
func (c *S3Client) Get(ctx context.Context, path string) (*File, error) {
	s3 := s3.New(c.auth, c.region)
	b := s3.Bucket(c.name)

	k, err := b.GetKey(path)
	if err != nil {
		return nil, err
	}

	rc, err := b.GetReader(path)
	if err != nil {
		return nil, err
	}

	modTime, _ := time.Parse(http.TimeFormat, k.LastModified)
	return &File{
		ReadCloser: rc,
		Name:       k.Key,
		ModTime:    modTime,
		Size:       k.Size,
	}, nil
}