當前位置: 首頁>>代碼示例>>Golang>>正文


Golang aws.GetAuth函數代碼示例

本文整理匯總了Golang中github.com/mitchellh/goamz/aws.GetAuth函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetAuth函數的具體用法?Golang GetAuth怎麽用?Golang GetAuth使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetAuth函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Configure

func (p *PostProcessor) Configure(raws ...interface{}) error {
	err := config.Decode(&p.config, &config.DecodeOpts{
		Interpolate:        true,
		InterpolateContext: &p.config.ctx,
		InterpolateFilter: &interpolate.RenderFilter{
			Exclude: []string{},
		},
	}, raws...)
	if err != nil {
		return err
	}

	errs := &packer.MultiError{}

	errs = packer.MultiErrorAppend(errs, p.config.AccessConfig.Prepare(&p.config.ctx)...)

	// required configuration
	templates := map[string]*string{
		"region":   &p.config.Region,
		"bucket":   &p.config.Bucket,
		"manifest": &p.config.ManifestPath,
		"box_name": &p.config.BoxName,
		"box_dir":  &p.config.BoxDir,
		"version":  &p.config.Version,
	}

	// Template process
	for key, ptr := range templates {
		if *ptr == "" {
			errs = packer.MultiErrorAppend(
				errs, fmt.Errorf("%s must be set", key))
		}

		*ptr, err = interpolate.Render(*ptr, &p.config.ctx)
		if err != nil {
			errs = packer.MultiErrorAppend(
				errs, fmt.Errorf("Error processing %s: %s", key, err))
		}
	}

	// setup the s3 bucket
	auth, err := aws.GetAuth(p.config.AccessConfig.AccessKey, p.config.AccessConfig.SecretKey)
	if err != nil {
		errs = packer.MultiErrorAppend(errs, err)
	}

	// determine region
	region, valid := aws.Regions[p.config.Region]
	if valid {
		p.s3 = s3.New(auth, region).Bucket(p.config.Bucket)
	} else {
		errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region))
	}

	if len(errs.Errors) > 0 {
		return errs
	}

	return nil
}
開發者ID:kadaan,項目名稱:packer-post-processor-vagrant-s3,代碼行數:60,代碼來源:post-processor.go

示例2: NewPublishedStorage

// NewPublishedStorage creates new instance of PublishedStorage with specified S3 access
// keys, region and bucket name
func NewPublishedStorage(accessKey, secretKey, region, endpoint, bucket, defaultACL, prefix,
	storageClass, encryptionMethod string, plusWorkaround, disableMultiDel bool) (*PublishedStorage, error) {
	auth, err := aws.GetAuth(accessKey, secretKey)
	if err != nil {
		return nil, err
	}

	var awsRegion aws.Region

	if endpoint == "" {
		var ok bool

		awsRegion, ok = aws.Regions[region]
		if !ok {
			return nil, fmt.Errorf("unknown region: %#v", region)
		}
	} else {
		awsRegion = aws.Region{
			Name:                 region,
			S3Endpoint:           endpoint,
			S3LocationConstraint: true,
			S3LowercaseBucket:    true,
		}
	}

	return NewPublishedStorageRaw(auth, awsRegion, bucket, defaultACL, prefix, storageClass, encryptionMethod,
		plusWorkaround, disableMultiDel)
}
開發者ID:liftup,項目名稱:aptly,代碼行數:30,代碼來源:public.go

示例3: Configure

func (p *PostProcessor) Configure(raws ...interface{}) error {
	err := config.Decode(&p.config, &config.DecodeOpts{
		Interpolate:        true,
		InterpolateContext: &p.config.ctx,
		InterpolateFilter: &interpolate.RenderFilter{
			Exclude: []string{"output"},
		},
	}, raws...)
	if err != nil {
		return err
	}

	errs := new(packer.MultiError)
	// required configuration
	templates := map[string]*string{
		"region":   &p.config.Region,
		"bucket":   &p.config.Bucket,
		"manifest": &p.config.ManifestPath,
		"box_name": &p.config.BoxName,
		"box_dir":  &p.config.BoxDir,
		"version":  &p.config.Version,
	}

	for key, ptr := range templates {
		if *ptr == "" {
			errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrant-s3 %s must be set", key))
		}
	}

	// Template process
	for key, ptr := range templates {
		if err = interpolate.Validate(*ptr, &p.config.ctx); err != nil {
			errs = packer.MultiErrorAppend(
				errs, fmt.Errorf("Error parsing %s template: %s", key, err))
		}
	}

	auth, err := aws.GetAuth(p.config.AccessKey, p.config.SecretKey)
	if err != nil {
		errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to create Aws Authentication. Try providing keys 'access_key_id' and 'secret_key'"))
	}

	// determine region
	region, valid := aws.Regions[p.config.Region]
	if valid {
		p.s3 = s3.New(auth, region).Bucket(p.config.Bucket)
	} else {
		errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region))
	}

	if p.config.ACL == "" {
		p.config.ACL = "public-read"
	}

	if len(errs.Errors) > 0 {
		return errs
	}

	return nil
}
開發者ID:clofresh,項目名稱:packer-post-processor-vagrant-s3,代碼行數:60,代碼來源:post-processor.go

示例4: buildRemoteStore

func buildRemoteStore(s *stores) (err error) {
	if remoteStore == "" {
		return nil
	}
	var c store.Client
	if strings.HasPrefix(remoteStore, "s3://") {
		path := strings.TrimPrefix(remoteStore, "s3://")
		bucketPathSplit := strings.Split(path, "/")

		if len(bucketPathSplit) == 0 {
			return fmt.Errorf("invalid S3 path: %#v\n", remoteStore)
		}
		bucket := bucketPathSplit[0]
		var auth aws.Auth
		auth, err = aws.GetAuth("", "") // Extract credentials from the current instance.
		if err != nil {
			return fmt.Errorf("error getting AWS credentials: %v", err)
		}
		c = store.NewS3Client(bucket, auth, aws.APSoutheast2)
	} else {
		c = store.NewClient(remoteStore, "")
		s.artwork = store.NewRemoteFileSystem(store.NewClient(remoteStore, "artwork"))
	}

	s.media = store.NewRemoteChunkedFileSystem(c, 32*1024)
	if s.artwork == nil {
		s.artwork = store.Trace(store.ArtworkFileSystem(s.media), "artwork")
	}
	return nil
}
開發者ID:davelondon,項目名稱:tchaik,代碼行數:30,代碼來源:flag.go

示例5: main

func main() {
	flag.Parse()

	// Instantiates the CoreRoller updater to check periodically for version update.
	if updater, err := updater.New(30*time.Second, syscall.SIGTERM); err == nil {
		go updater.Start()
	}

	awsAuth, err := aws.GetAuth(config.awsAccessKey, config.awsSecretKey)
	if err != nil {
		log.Println(err)
	}

	manager := &Manager{
		configPath: config.etcdPath,
		etcdClient: etcd.NewClient(strings.Split(config.etcdHost, ",")),
		awsAuth:    awsAuth,
	}

	log.Println("Running load balancers manager...")
	go manager.Start()

	// Wait for signal to terminate
	signalsCh := make(chan os.Signal, 1)
	signal.Notify(signalsCh, os.Interrupt, syscall.SIGTERM)
	<-signalsCh
}
開發者ID:iPowow,項目名稱:lbManager,代碼行數:27,代碼來源:main.go

示例6: init

func (this *Manager) init(accessKey string, secretKey string) error {
	auth, err := aws.GetAuth(accessKey, secretKey)
	if err == nil {
		this.auth = &auth
	}
	return err
}
開發者ID:Pevika,項目名稱:golang-aws,代碼行數:7,代碼來源:manager.go

示例7: SendImage

func (gozo Gozo) SendImage(filename string) (url string, err error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return
	}

	auth, err := aws.GetAuth(
		gozo.accessKey,
		gozo.secretAccessKey,
	)
	if err != nil {
		return
	}

	s3client := s3.New(auth, gozo.region)
	bucket := s3client.Bucket(gozo.bucketName)

	path := "images/" + hexdigest(fmt.Sprintf("%s-%d", filename, time.Now().Unix())) + ".png"
	err = bucket.Put(path, data, "image/png", s3.PublicRead)
	if err != nil {
		return
	}

	url = gozo.rootURL + path
	return
}
開發者ID:naoya,項目名稱:Gozo,代碼行數:26,代碼來源:gozo.go

示例8: TestGetAuthEnv

func (s *S) TestGetAuthEnv(c *C) {
	os.Clearenv()
	os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
	os.Setenv("AWS_ACCESS_KEY_ID", "access")
	auth, err := aws.GetAuth("", "")
	c.Assert(err, IsNil)
	c.Assert(auth, Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
開發者ID:hden,項目名稱:goamz,代碼行數:8,代碼來源:aws_test.go

示例9: Instances

func (cache *EC2Cache) Instances() (*ec2.InstancesResp, error) {
	auth, err := aws.GetAuth(cache.accessKey, cache.secretKey)
	if err != nil {
		return nil, err
	}

	return ec2.New(auth, cache.region).Instances(nil, nil)
}
開發者ID:trailbehind,項目名稱:aws-name-server,代碼行數:8,代碼來源:ec2_cache.go

示例10: getAuth

func (s3p *s3Provider) getAuth(accessKey, secretKey string) (aws.Auth, error) {
	if s3p.overrideAuth != nilAuth {
		s3p.log.WithField("auth", s3p.overrideAuth).Debug("using override auth")
		return s3p.overrideAuth, nil
	}

	s3p.log.Debug("creating new auth")
	return aws.GetAuth(accessKey, secretKey)
}
開發者ID:persistent-systems-ltd,項目名稱:artifacts,代碼行數:9,代碼來源:s3_provider.go

示例11: NewS3

func NewS3(key, secret, bucket, prefix string) S3 {
	auth, _ := aws.GetAuth(key, secret)
	region := aws.USEast // haha for life. TODO - configurable?
	client := s3.New(auth, region)
	return &s3client{
		client: client,
		bucket: client.Bucket(bucket),
		prefix: prefix,
	}
}
開發者ID:lstoll,項目名稱:simplevault,代碼行數:10,代碼來源:s3.go

示例12: Open

func (s *S3) Open() (err error) {
	auth, err := aws.GetAuth(s.AccessKey, s.SecretKey)
	if err != nil {
		return
	}

	s.conn = s3.New(auth, aws.USEast) // TODO: hardcoded region..?
	s.bucket = s.conn.Bucket(s.BucketId)
	return nil // TODO: no errors ever..?
}
開發者ID:jsimnz,項目名稱:chainstore,代碼行數:10,代碼來源:s3.go

示例13: AWSAuth

// AWSAuth returns a valid aws.Auth object for access to AWS services, or
// an error if the authentication couldn't be resolved.
//
// TODO(mitchellh): Test in some way.
func (c *Config) AWSAuth() (aws.Auth, error) {
	auth, err := aws.GetAuth(c.AccessKey, c.SecretKey)
	if err == nil {
		// Store the accesskey and secret that we got...
		c.AccessKey = auth.AccessKey
		c.SecretKey = auth.SecretKey
	}

	return auth, err
}
開發者ID:GeorgeErickson,項目名稱:terraform-1,代碼行數:14,代碼來源:config.go

示例14: getBucket

func (s *S3) getBucket() *s3.Bucket {
	auth, err := aws.GetAuth(s.AccessKeyId, s.SecretKey)
	if err != nil {
		log.Printf("Amazon authentication failed", err)
		return nil
	}

	service := s3.New(auth, aws.EUWest)
	return service.Bucket(s.Bucket)
}
開發者ID:peteraba,項目名稱:go-blah,代碼行數:10,代碼來源:s3.go

示例15: NewDriver

// NewDriver creates a driver for S3 paths
func NewDriver(accessKey, secretKey string, region aws.Region) (*Driver, error) {
	// Authenticate -- will fall back to ~/.aws then to environment variables
	auth, err := aws.GetAuth(accessKey, secretKey)
	if err != nil {
		return nil, err
	}

	return &Driver{
		Region: region,
		Auth:   auth,
	}, nil
}
開發者ID:lucmichalski,項目名稱:go-cloudfile,代碼行數:13,代碼來源:s3file.go


注:本文中的github.com/mitchellh/goamz/aws.GetAuth函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。