当前位置: 首页>>代码示例>>Golang>>正文


Golang aws.EnvAuth函数代码示例

本文整理汇总了Golang中launchpad/net/goamz/aws.EnvAuth函数的典型用法代码示例。如果您正苦于以下问题:Golang EnvAuth函数的具体用法?Golang EnvAuth怎么用?Golang EnvAuth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EnvAuth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestReadFromSQS

func TestReadFromSQS(t *testing.T) {
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err)
	}

	sqs := New(auth, aws.USWest2)
	queue, err := sqs.GetQueue("tracker-alpha-matt")
	if err != nil {
		panic(err)
	}

	results, err := queue.ReceiveMessage([]string{"All"}, 10, 600)
	count := len(results.Messages)
	deleteMessageBatch := make([]DeleteMessageBatch, count)
	for index, message := range results.Messages {
		fmt.Println(message.Body)
		deleteMessageBatch[index] = DeleteMessageBatch{
			Id:            strconv.Itoa(index),
			ReceiptHandle: message.ReceiptHandle,
		}
	}

	fmt.Println(fmt.Sprintf("%#v", deleteMessageBatch))
	response, err := queue.DeleteMessageBatch(deleteMessageBatch)
	if err != nil {
		panic(err)
	}
	fmt.Println(fmt.Sprintf("%#v", response))
}
开发者ID:savaki,项目名称:sqs,代码行数:30,代码来源:sample_test.go

示例2: Sync

func Sync(localPath, bucketName, awsRegion, acl string) {
	if localPath == "" || bucketName == "" {
		flag.PrintDefaults()
		return
	}
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}
	s3Conn := s3.New(auth, aws.Regions[awsRegion])
	bucket := s3Conn.Bucket(bucketName)
	pathChan := make(chan string)
	doneChan := make(chan int)
	go doTheWalk(localPath, pathChan)
	count := 0
	for path := range pathChan {
		if path == "" {
			break
		}
		go compareAndSync(acl, localPath, path, bucket, doneChan)
		count++
	}
	for i := 0; i < count; i++ {
		<-doneChan
	}
}
开发者ID:rossdylan,项目名称:3sync,代码行数:26,代码来源:3sync.go

示例3: main

func main() {
	flag.Parse()

	cmds := flag.Args()

	if len(cmds) <= 0 {
		fmt.Println("Command required")
		os.Exit(1)
	}

	cmd := Cmd{}
	cmd.name = cmds[0]
	cmd.modifiers = cmds[1:]

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

	cmd.conn = s3.New(auth, getRegion(region))
	s3url, err := url.Parse(cmd.modifiers[0])
	cmd.url = s3url
	cmd.bucket = s3.Bucket{cmd.conn, cmd.url.Host}
	RunCommand(cmd)

}
开发者ID:jawnb,项目名称:s3tool,代码行数:26,代码来源:s3tool.go

示例4: main

func main() {
	flag.Parse()

	if *toHash == "" || *pkgDirs == "" || *cmd == "" || *bucketName == "" {
		log.Print("You are missing one or more mandatory command line arguments.")
		flag.Usage()
		os.Exit(1)
	}

	cred, err := aws.EnvAuth()
	if err != nil {
		log.Fatalf("Couldn't auth into s3. Did you set up ENV? Error: %s", err)
	}
	s3client := s3.New(cred, aws.USWest)
	bucket := s3client.Bucket(*bucketName)

	// extract.
	checksum := fmt.Sprintf("%x", hashFiles(*toHash).Sum(nil))

	filename := *outfile
	// consider bucket.GetReader to pipe directly into gunzip/untar
	file, err := bucket.Get(fmt.Sprintf("%s/%s", checksum, filename))
	if err != nil {
		fmt.Printf("%s\n", err)
		build(*cmd)
		archive(*pkgDirs, filename)
		upload(bucket, checksum, filename)
	} else {
		extract(file)
	}
}
开发者ID:justinabrahms,项目名称:gatherer,代码行数:31,代码来源:main.go

示例5: PostSignup

func PostSignup(w *rest.ResponseWriter, req *rest.Request) {
	signup := Signup{}
	err := req.DecodeJsonPayload(&signup)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if signup.Email == "" {
		rest.Error(w, "email is required", 400)
		return
	}

	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}

	s := s3.New(auth, aws.EUWest)
	bucket := s.Bucket("seq-signup")
	data := []byte(signup.Email)
	err = bucket.Put(signup.Email, data, "text/plain", s3.BucketOwnerFull)
	if err != nil {
		panic(err.Error())
	}

	fmt.Println(signup)
	w.Header().Set("Access-Control-Allow-Origin", "http://sequenceiq.com")
	w.WriteJson(&signup)
}
开发者ID:sequenceiq,项目名称:go-signup,代码行数:29,代码来源:signup.go

示例6: saver

// Goroutine for saving the state.
func saver(ticker *time.Ticker) {
	for {
		select {
		case <-ticker.C:
			println("Writing state")
			lock.Lock()
			if dirty {
				dirty = false
				state := State{folders}

				bytes, err := json.Marshal(state)
				if err != nil {
					panic(err)
				}

				// write to S3
				auth, err := aws.EnvAuth()
				if err != nil {
					panic(err)
				}
				s := s3.New(auth, aws.USEast)
				bucket := s.Bucket(s3_bucket)
				err = bucket.Put("rss.json", bytes, "application/json", s3.ACL("private"))
				if err != nil {
					panic(err)
				}
			}
			lock.Unlock()
		}
	}
}
开发者ID:swenson,项目名称:littlereader,代码行数:32,代码来源:reader.go

示例7: Load

// Load a brain
func (brain *Brain) Load() {
	// The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are used.
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}

	// Open Bucket
	s := s3.New(auth, aws.USEast)

	// Load the database from an S3 bucket
	bucket := s.Bucket(bucketName)

	// Create a bytes.Buffer
	n, err := bucket.Get(filename)
	if err != nil {
		panic(err)
	}

	p := bytes.NewBuffer(n)
	dec := gob.NewDecoder(p)

	err = dec.Decode(&brain)

	if err != nil {
		log.Print("There was an error loading the brain. Using a blank one.")
	}
}
开发者ID:davideg,项目名称:ginsbrain,代码行数:29,代码来源:brain.go

示例8: Save

// Persist a brain
func (brain *Brain) Save() {
	// Persist the database to file
	var data bytes.Buffer
	contents := gob.NewEncoder(&data)
	err := contents.Encode(brain)
	if err != nil {
		panic(err)
	}

	// The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are used.
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}

	// Open Bucket
	s := s3.New(auth, aws.USEast)

	// Load the database from an S3 bucket
	bucket := s.Bucket(bucketName)

	err = bucket.Put(filename, data.Bytes(), "text/plain", s3.BucketOwnerFull)
	if err != nil {
		panic(err.Error())
	}
}
开发者ID:davideg,项目名称:ginsbrain,代码行数:27,代码来源:brain.go

示例9: main

func main() {
	flag.Parse()
	if flag.Arg(0) == "" {
		errorf("no command")
		os.Exit(2)
	}
	auth, err := aws.EnvAuth()
	if err != nil {
		fatalf("envauth: %v", err)
	}
	conn := ec2.New(auth, aws.USEast)

	if flag.Arg(0) == "help" {
		for _, c := range cmds {
			c.printUsage()
		}
		return
	}

	for _, c := range cmds {
		if flag.Arg(0) == c.name {
			c.run(conn, flag.Args()[1:])
			return
		}
	}
	errorf("unknown command %q", flag.Arg(0))
	os.Exit(2)
}
开发者ID:juanman2,项目名称:dot-emacs,代码行数:28,代码来源:ec2.go

示例10: SetUp

func (s *AmazonServer) SetUp(c *C) {
	auth, err := aws.EnvAuth()
	if err != nil {
		c.Fatal(err)
	}
	s.auth = auth
}
开发者ID:fsouza,项目名称:go-iam,代码行数:7,代码来源:iami_test.go

示例11: readState

// Read the state from S3.
func readState() {
	state := State{}
	wd, err := os.Getwd()
	fmt.Printf("wd: %s\n", wd)

	// read from S3
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}
	s := s3.New(auth, aws.USEast)
	bucket := s.Bucket(s3_bucket)
	data, err := bucket.Get("rss.json")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Data read from S3\n")

	// old way
	/*
		file, err := os.Open("state.json")
		if err != nil {
			panic(err)
		}
		data, err := ioutil.ReadAll(file)
		if err != nil {
			panic(err)
		}
	*/
	err = json.Unmarshal(data, &state)
	if err != nil {
		panic(err)
	}
	folders = state.Folders
}
开发者ID:swenson,项目名称:littlereader,代码行数:36,代码来源:reader.go

示例12: TestRealtimeTrace

func TestRealtimeTrace(t *testing.T) {

	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err)
	}
	s := ec2.New(auth, aws.EUWest)

	m, err := NewEC2Monitor(s, "m1.medium",
		"Linux/UNIX",
		"eu-west-1b", nil)

	to := time.Now()
	from := to.AddDate(0, -3, 0)

	trace, err := m.Trace(from, to)
	if err != nil {
		t.Fatal(err)
	}

	if len(trace) == 0 {
		t.Fatal("trace did not produce any history")
	}

	if len(trace) < 5 {
		for i := 0; i < len(trace); i++ {
			pp := trace[i]
			fmt.Printf("\t%.4f - %v\n", pp.Price(), pp.Time())
		}
	} else {
		fmt.Println("last 5 traces:")
		for i := 0; i < 5; i++ {
			pp := trace[i]
			fmt.Printf("\t%.4f - %v\n", pp.Price(), pp.Time())
		}
	}

	pChan, errChan := m.Start(time.Second * 5)

	ticker := time.NewTicker(time.Minute * 5)

	fmt.Println("Starting EC2 Spot Price Monitor.\n\tTimeout: 5 minutes")

	for {
		select {
		case p := <-pChan:
			fmt.Printf("PriceChange: %v On: %v\n", p.Price(), p.Time())
		case err := <-errChan:
			fmt.Println("error: ", err.Error())
			return
		case <-ticker.C:
			fmt.Println("test shut down after 5 minutes")
			return
		}
	}
	fmt.Println("Stopping ticker, and exiting test..")
	ticker.Stop()
	fmt.Println("Done")
}
开发者ID:paddie,项目名称:statedb,代码行数:59,代码来源:mon_ec2_test.go

示例13: auth

func auth() aws.Auth {
	creds, err := aws.EnvAuth()
	if err != nil {
		log.Println("Error with aws credentials: %v", err)
		os.Exit(1)
	}
	return creds
}
开发者ID:reedobrien,项目名称:wpgo,代码行数:8,代码来源:wpurl.go

示例14: TestEnvAuth

func (s *S) TestEnvAuth(c *C) {
	os.Clearenv()
	os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
	os.Setenv("AWS_ACCESS_KEY_ID", "access")
	auth, err := aws.EnvAuth()
	c.Assert(err, IsNil)
	c.Assert(auth, Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
开发者ID:ragsagar,项目名称:web-blog,代码行数:8,代码来源:aws_test.go

示例15: awsInit

func awsInit(config *ec2Config) (ec2Conn *ec2.EC2, err error) {
	auth, err := aws.EnvAuth()

	if err != nil {
		return nil, err
	}

	return ec2.New(auth, config.region), nil
}
开发者ID:nathanleclaire,项目名称:libswarm,代码行数:9,代码来源:ec2.go


注:本文中的launchpad/net/goamz/aws.EnvAuth函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。