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


Golang aws.EnvAuth函數代碼示例

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


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

示例1: uploadToS3

func uploadToS3(file string, s3_bucket string, awsRegion aws.Region) error {
	log.Println("Uploading to S3...")
	auth, err := aws.EnvAuth()
	if err != nil {
		return err
	}
	client := s3.New(auth, awsRegion)
	bucket := client.Bucket(s3_bucket)

	r, errF := os.Open(file)
	fi, _ := r.Stat()
	length := fi.Size()

	if errF != nil {
		return errF
	}

	path := file
	perm := s3.ACL("private")
	contType := "application/x-compressed"

	err = bucket.PutReader(path, r, length, contType, perm)
	if err != nil {
		return err
	}

	log.Println("Upload successful")
	return nil
}
開發者ID:hybris,項目名稱:zk-backup,代碼行數:29,代碼來源:zk-backup.go

示例2: main

func main() {
	kingpin.Version("0.0.1")
	kingpin.CommandLine.Help = "AWS deployment tools."
	kingpin.Parse()

	auth, err := aws.EnvAuth()
	Check(err)

	state := new(multistep.BasicStateBag)

	// This allows us to share our client connections while in each of the steps.
	state.Put("client_elb", elb.New(auth, aws.USWest2))
	state.Put("client_ec2", ec2.New(auth, aws.USWest2))

	// Standard configuration that has been passed in via the CLI.
	state.Put("elb", *elbId)
	state.Put("ami", *amiId)
	state.Put("key", *key)
	state.Put("size", *size)
	state.Put("region", aws.Regions[*region])
	state.Put("security", *security)
	state.Put("tags", *tags)

	steps := []multistep.Step{
		&StepDestroy{}, // Remove the existing hosts from the Load balancer.
		&StepCreate{},  // Create some EC2 instances and ensure they are ready to be deployed.
	}
	runner := &multistep.BasicRunner{Steps: steps}
	runner.Run(state)
}
開發者ID:marji,項目名稱:aws_deploy,代碼行數:30,代碼來源:main.go

示例3: NewEc2Discoverer

func NewEc2Discoverer(c *cli.Context) Ec2Discoverer {
	auth, err := aws.EnvAuth()
	if err != nil {
		log.Fatal(err)
	}

	tag := c.String("ec2-tag")
	if tag == "" {
		log.Fatal(errors.New("You must specify --ec2-tag option"))
	}

	t := strings.Split(tag, ":")
	tagKey, tagValue := t[0], t[1]

	regionStr := c.String("ec2-region")
	region, ok := aws.Regions[regionStr]
	if !ok {
		log.Fatal(fmt.Errorf("%s region is not valid", regionStr))
	}

	client := ec2.New(auth, region)
	return Ec2Discoverer{
		Client:   client,
		TagKey:   tagKey,
		TagValue: tagValue,
	}
}
開發者ID:ryotarai,項目名稱:dockertie,代碼行數:27,代碼來源:discoverer.go

示例4: CreateBucket

func CreateBucket() *s3.Bucket {
	auth, err := aws.EnvAuth()
	if err != nil {
		println("store -- error connecting to AWS\n")
		panic(err)
	}

	fmt.Printf("store -- connected to AWS\n")

	awsRegion := os.Getenv("STORE_AWSREGION")
	if awsRegion == "" {
		println("store -- error: environment variable STORE_AWSREGION not set")
		panic("store -- STORE_AWSREGION not set")
	}

	region := aws.Regions[awsRegion]
	if region.Name == "" {
		panic("store -- region '" + awsRegion + "' is invalid")
	}
	println("store -- AWS region: " + region.Name)

	S3 := s3.New(auth, aws.Regions["eu-west-1"])

	bucketName := os.Getenv("STORE_BUCKETNAME")
	if bucketName == "" {
		println("store -- error: environment variable STORE_BUCKETNAME not set")
		panic("store -- STORE_BUCKETNAME not set")
	}

	bucket := S3.Bucket(bucketName)
	println("store -- Bucket name: " + bucket.Name)
	return bucket
}
開發者ID:erlendr,項目名稱:store,代碼行數:33,代碼來源:store.go

示例5: awsConnectForTest

func awsConnectForTest() *s3.Bucket {
	os.Setenv("AWS_ACCESS_KEY_ID", Config.Aws.AccessKeyId)
	os.Setenv("AWS_SECRET_ACCESS_KEY", Config.Aws.SecretAccessKey)
	auth, err := aws.EnvAuth()
	perror(err)
	return s3.New(auth, aws.Regions[Config.Aws.Region]).Bucket(Config.Aws.BucketName)
}
開發者ID:memikequinn,項目名稱:lfs-server-go,代碼行數:7,代碼來源:aws_content_store_test.go

示例6: UploadToS3

func UploadToS3(file multipart.File, s3Key string) (err error) {

	auth, err := aws.EnvAuth()
	if err != nil {
		log.Fatal("Incorrect AWS Auth Details ", err)
	}

	connection := s3.New(auth, region)
	bucket := connection.Bucket(os.Getenv("S3_BUCKET"))

	buffer := new(bytes.Buffer)
	_, err = io.Copy(buffer, file)
	if err != nil {
		log.Fatal("Cannot create file ", err)
	}

	filetype := http.DetectContentType(buffer.Bytes())
	err = bucket.Put(
		s3Key,
		buffer.Bytes(),
		filetype,
		s3.ACL("public-read"),
	)
	return err
}
開發者ID:eddturtle,項目名稱:imagio,代碼行數:25,代碼來源:aws.go

示例7: SetUp

func (s *AmazonServer) SetUp(c *C) {
	auth, err := aws.EnvAuth()
	if err != nil {
		c.Fatal(err.Error())
	}
	s.auth = auth
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:7,代碼來源:ec2i_test.go

示例8: main

func main() {
	var regionStr string
	flag.StringVar(&regionStr, "r", "us-east-1", "Region")
	flag.Parse()

	region, err := strToRegion(regionStr)
	if err == nil {
		log.Fatal(err)
	}

	auth, err := aws.EnvAuth()
	if err != nil {
		log.Fatal(err)
	}

	client := ec2.New(auth, *region)

	resp, err := client.Instances(nil, nil)
	if err != nil {
		log.Fatal(err)
	}

	instances := []ec2.Instance{}
	for _, reservation := range resp.Reservations {
		instances = append(instances, reservation.Instances...)
	}

	b, err := json.Marshal(instances)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s\n", b)
}
開發者ID:hotchpotch,項目名稱:ec2-describe-instances-go,代碼行數:34,代碼來源:ec2-describe-instances-go.go

示例9: Init

func (pl *Plugin) Init() error {
	auth, err := aws.EnvAuth()
	if err != nil {
		return err
	}
	pl.s3 = s3.New(auth, aws.APNortheast)
	return nil
}
開發者ID:bluele,項目名稱:stream,代碼行數:8,代碼來源:s3.go

示例10: S3Bucket

func S3Bucket() *s3.Bucket {
	auth, err := aws.EnvAuth()
	ErrorHandler(err)

	client := s3.New(auth, aws.USEast)
	b := client.Bucket("cc-gifgroup-api")
	return b
}
開發者ID:elvingm,項目名稱:cc-gif-group-api,代碼行數:8,代碼來源:main.go

示例11: GetS3Bucket

func GetS3Bucket() (bucket *s3.Bucket) {
	auth, err := aws.EnvAuth()
	ErrorHandler(err)

	client := s3.New(auth, aws.USEast)
	bucket = client.Bucket(os.Getenv("AWS_STORAGE_BUCKET_NAME"))
	return
}
開發者ID:DonatoM,項目名稱:GoUpload,代碼行數:8,代碼來源:main.go

示例12: TestEnvAuthAlt

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

示例13: getBucket

func (h *FileHandler) getBucket() (*s3.Bucket, error) {
	auth, err := aws.EnvAuth()
	if err != nil {
		return nil, err
	}
	client := s3.New(auth, aws.APSoutheast2)
	bucket := client.Bucket(h.BucketName)
	return bucket, nil
}
開發者ID:ciasia,項目名稱:go_gsd,代碼行數:9,代碼來源:file.go

示例14: init

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")
}
開發者ID:ciela,項目名稱:playground_golang,代碼行數:9,代碼來源:aws.go

示例15: TestEnvAuthWithToken

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


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