本文整理匯總了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
}
示例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)
}
示例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,
}
}
示例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
}
示例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)
}
示例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
}
示例7: SetUp
func (s *AmazonServer) SetUp(c *C) {
auth, err := aws.EnvAuth()
if err != nil {
c.Fatal(err.Error())
}
s.auth = auth
}
示例8: main
func main() {
var regionStr string
flag.StringVar(®ionStr, "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)
}
示例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
}
示例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
}
示例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
}
示例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"})
}
示例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
}
示例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")
}
示例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"})
}