本文整理汇总了Golang中github.com/crowdmob/goamz/aws.GetAuth函数的典型用法代码示例。如果您正苦于以下问题:Golang GetAuth函数的具体用法?Golang GetAuth怎么用?Golang GetAuth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetAuth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateAuth
func (r53 *Route53) updateAuth() {
r53.authLock.Lock()
// update auth
auth, err := aws.GetAuth("", "", "", time.Time{})
for ; err != nil; auth, err = aws.GetAuth("", "", "", time.Time{}) {
if debug {
log.Printf("[Route53] Error getting auth (sleeping 5s before retry): %v", err)
}
time.Sleep(5 * time.Second)
}
r53.auth = auth
if debug {
log.Printf("[Route53] auth updated. expires at %v.", auth.Expiration())
}
r53.authLock.Unlock()
}
示例2: FetchMetrics
// FetchMetrics fetch elasticache values
func (p ECachePlugin) FetchMetrics() (map[string]float64, error) {
auth, err := aws.GetAuth(p.AccessKeyID, p.SecretAccessKey, "", time.Now())
if err != nil {
return nil, err
}
cloudWatch, err := cloudwatch.NewCloudWatch(auth, aws.Regions[p.Region].CloudWatchServicepoint)
if err != nil {
return nil, err
}
stat := make(map[string]float64)
perInstances := &[]cloudwatch.Dimension{
cloudwatch.Dimension{
Name: "CacheClusterId",
Value: p.CacheClusterID,
},
cloudwatch.Dimension{
Name: "CacheNodeId",
Value: p.CacheNodeID,
},
}
for _, met := range p.CacheMetrics {
v, err := getLastPoint(cloudWatch, perInstances, met)
if err == nil {
stat[met] = v
} else {
log.Printf("%s: %s", met, err)
}
}
return stat, nil
}
示例3: main
func main() {
kingpin.Version("1.2.1")
kingpin.Parse()
sl, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, "[varnish-purge-proxy]")
defer sl.Close()
if err != nil {
log.Println("Error writing to syslog")
} else {
log.SetFlags(0)
log.SetOutput(sl)
}
if len(*tags) == 0 {
fmt.Println("No tags specified")
return
}
// Set up access to ec2
auth, err := aws.GetAuth("", "", "", time.Now().Add(time.Duration(24*365*time.Hour)))
if err != nil {
log.Println(err)
return
}
ec2region := ec2.New(auth, region)
go serveHTTP(*port, ec2region)
select {}
}
示例4: FetchMetrics
// FetchMetrics fetch the metrics
func (p CPUCreditPlugin) FetchMetrics() (map[string]float64, error) {
region := aws.Regions[p.Region]
dimension := &cloudwatch.Dimension{
Name: "InstanceId",
Value: p.InstanceID,
}
auth, err := aws.GetAuth(p.AccessKeyID, p.SecretAccessKey, "", time.Now())
if err != nil {
return nil, err
}
cw, err := cloudwatch.NewCloudWatch(auth, region.CloudWatchServicepoint)
stat := make(map[string]float64)
stat["usage"], err = getLastPointAverage(cw, dimension, "CPUCreditUsage")
if err != nil {
return nil, err
}
stat["balance"], err = getLastPointAverage(cw, dimension, "CPUCreditBalance")
if err != nil {
return nil, err
}
return stat, nil
}
示例5: FetchMetrics
func (p RDSPlugin) FetchMetrics() (map[string]float64, error) {
auth, err := aws.GetAuth(p.AccessKeyId, p.SecretAccessKey, "", time.Now())
if err != nil {
return nil, err
}
cloudWatch, err := cloudwatch.NewCloudWatch(auth, aws.Regions[p.Region].CloudWatchServicepoint)
if err != nil {
return nil, err
}
stat := make(map[string]float64)
perInstance := &cloudwatch.Dimension{
Name: "DBInstanceIdentifier",
Value: p.Identifier,
}
for _, met := range [...]string{
"BinLogDiskUsage", "CPUUtilization", "DatabaseConnections", "DiskQueueDepth", "FreeableMemory",
"FreeStorageSpace", "ReplicaLag", "SwapUsage", "ReadIOPS", "WriteIOPS", "ReadLatency",
"WriteLatency", "ReadThroughput", "WriteThroughput", "NetworkTransmitThroughput", "NetworkReceiveThroughput",
} {
v, err := GetLastPoint(cloudWatch, perInstance, met)
if err == nil {
stat[met] = v
} else {
log.Printf("%s: %s", met, err)
}
}
return stat, nil
}
示例6: GetAuthFromEnv
func GetAuthFromEnv() aws.Auth {
auth, err := aws.GetAuth("", "", "", time.Now())
if err != nil && os.Getenv("CLOUD_ENVIRONMENT") == "PRODUCTION" {
log.Fatalln("Failed to recieve auth from env")
}
return auth
}
示例7: getAuth
func (s *S3) getAuth() (err error) {
s.auth, err = aws.GetAuth(s.AccessKey, s.SecretKey, "", time.Time{})
if s.s3 != nil {
s.s3.Auth = s.auth
}
return
}
示例8: FetchMetrics
// FetchMetrics interface for mackerel-plugin
func (p RDSPlugin) FetchMetrics() (map[string]float64, error) {
auth, err := aws.GetAuth(p.AccessKeyID, p.SecretAccessKey, "", time.Now())
if err != nil {
return nil, err
}
cloudWatch, err := cloudwatch.NewCloudWatch(auth, aws.Regions[p.Region].CloudWatchServicepoint)
if err != nil {
return nil, err
}
stat := make(map[string]float64)
perInstance := &cloudwatch.Dimension{
Name: "DBInstanceIdentifier",
Value: p.Identifier,
}
for _, met := range p.rdsMetrics() {
v, err := getLastPoint(cloudWatch, perInstance, met)
if err == nil {
stat[met] = v
} else {
log.Printf("%s: %s", met, err)
}
}
return stat, nil
}
示例9: setupS3Logger
func (app *AppContext) setupS3Logger() (err error) {
auth, err := aws.GetAuth("", "", "", time.Now())
if err != nil {
log.Fatalln("Failed to find AWS credentials in env")
}
awsConnection := s3.New(
auth,
getAWSRegion(app.config.aws_region),
)
bucket := awsConnection.Bucket(app.config.bucket)
instanceInfo := keygen.BuildInstanceInfo(
&keygen.EnvInstanceFetcher{},
serviceName,
app.config.logging_dir,
)
rotateCoordinator := gologging.NewRotateCoordinator(
app.config.max_log_lines,
app.config.max_log_age,
)
metricsLogger := MetricsLogger{app.metrics}
app.s3log, err = gologging.StartS3Logger(
rotateCoordinator,
instanceInfo,
&metricsLogger,
&uploader.S3UploaderBuilder{
Bucket: bucket,
KeyNameGenerator: &KeyNameGenerator{
Info: instanceInfo,
Prefix: app.config.key_prefix,
},
},
&metricsLogger,
app.config.num_workers,
)
if err != nil {
return
}
// Make sure logger is flushed when shutdown signal is received
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sigc
log.Println("interrupted, closing logger...")
app.s3log.Close()
os.Exit(0)
}()
return nil
}
示例10: s3Setup
func s3Setup(bucketName string, path string, opts sequinsOptions) *sequins {
auth, err := aws.GetAuth(*s3AccessKey, *s3SecretKey, "", time.Time{})
if err != nil {
log.Fatal(err)
}
regionName := *s3Region
if regionName == "" {
regionName = aws.InstanceRegion()
if regionName == "" {
log.Fatal("Unspecified --s3-region, and no instance region found.")
}
}
region, exists := aws.Regions[regionName]
if !exists {
log.Fatalf("Invalid AWS region: %s", regionName)
}
bucket := s3.New(auth, region).Bucket(bucketName)
backend := backend.NewS3Backend(bucket, path)
if opts.LocalPath == "" {
tmpDir, err := ioutil.TempDir("", "sequins-")
if err != nil {
log.Fatal(err)
}
opts.LocalPath = tmpDir
}
return newSequins(backend, opts)
}
示例11: setupS3
func setupS3() *backend.S3Backend {
fakeS3, _ := s3test.NewServer(&s3test.Config{})
// cargo-culted from s3test
fakeRegion := aws.Region{
Name: "faux-region-1",
S3Endpoint: fakeS3.URL(),
S3LocationConstraint: true,
}
auth, _ := aws.GetAuth("foo", "bar", "", time.Time{})
bucket := s3.New(auth, fakeRegion).Bucket("sequinstest")
bucket.PutBucket("")
putFile(bucket, "test_data/0/part-00000")
putFile(bucket, "test_data/0/part-00001")
putFile(bucket, "test_data/0/_SUCCESS")
putFile(bucket, "test_data/1/part-00000")
putFile(bucket, "test_data/1/part-00001")
bucket.Put("test_data/foo", []byte("nothing"), "", "", s3.Options{})
return backend.NewS3Backend(bucket, "test_data")
}
示例12: main
func main() {
flag.Parse()
log.SetOutput(os.Stdout)
auth, err := aws.GetAuth("", "", "", time.Time{})
if err != nil {
log.Fatalln("Failed to recieve auth")
}
stats, err := lib.InitStats(statsPrefix)
if err != nil {
log.Fatalln("Error initializing stats:", err)
}
postgresBackend, err := metadata.NewPostgresStorer(&pgConfig)
listener := StartWorker(&listener.SQSAddr{
Region: aws.USWest2,
QueueName: "spade-compactor-" + env,
Auth: auth,
}, stats, postgresBackend)
wait := make(chan struct{})
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGINT)
go func() {
<-sigc
// Cause flush
listener.Close()
close(wait)
}()
<-wait
}
示例13: main
func main() {
var inst_id string
if instanceID == "" {
inst_id := aws.InstanceId()
if inst_id == "unknown" {
log.Fatalln("Unable to get instance id")
}
} else {
inst_id = instanceID
}
auth, err := aws.GetAuth(accesskey, secretkey, "", time.Time{})
if err != nil {
log.Fatalln("Unable to get AWS auth", err)
}
awsec2 = ec2.New(auth, aws.GetRegion(region))
groupMap := getSecurityGroupIds(inst_id)
for _, id := range securityGroupIDs {
groupMap[id] = true
}
groupIds := make([]string, 0, len(groupMap))
for id := range groupMap {
groupIds = append(groupIds, id)
}
opts := &ec2.ModifyInstanceAttributeOptions{SecurityGroups: ec2.SecurityGroupIds(groupIds...)}
resp, err := awsec2.ModifyInstanceAttribute(inst_id, opts)
if err != nil || !resp.Return {
log.Fatalln("Error adding security groups to instance", err)
}
log.Printf("Added security groups %s to instance %s\n", securityGroupIDs.String(), inst_id)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
// this waits until we get a kill signal
<-c
groupMap = getSecurityGroupIds(inst_id)
for _, id := range securityGroupIDs {
delete(groupMap, id)
}
groupIds = make([]string, 0, len(groupMap))
for id := range groupMap {
groupIds = append(groupIds, id)
}
opts = &ec2.ModifyInstanceAttributeOptions{SecurityGroups: ec2.SecurityGroupIds(groupIds...)}
resp, err = awsec2.ModifyInstanceAttribute(inst_id, opts)
if err != nil || !resp.Return {
log.Fatalln("Error removing security groups from instance", err)
}
log.Printf("Removed security groups %s from instance %s\n", securityGroupIDs.String(), inst_id)
}
示例14: TestGetAuthEnv
func (s *S) TestGetAuthEnv(c *check.C) {
os.Clearenv()
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
os.Setenv("AWS_ACCESS_KEY_ID", "access")
auth, err := aws.GetAuth("", "", "", time.Time{})
c.Assert(err, check.IsNil)
c.Assert(auth, check.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
示例15: TestGetAuthStatic
func (s *S) TestGetAuthStatic(c *check.C) {
exptdate := time.Now().Add(time.Hour)
auth, err := aws.GetAuth("access", "secret", "token", exptdate)
c.Assert(err, check.IsNil)
c.Assert(auth.AccessKey, check.Equals, "access")
c.Assert(auth.SecretKey, check.Equals, "secret")
c.Assert(auth.Token(), check.Equals, "token")
c.Assert(auth.Expiration(), check.Equals, exptdate)
}