本文整理汇总了Golang中github.com/awslabs/aws-sdk-go/aws.Creds函数的典型用法代码示例。如果您正苦于以下问题:Golang Creds函数的具体用法?Golang Creds怎么用?Golang Creds使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Creds函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
creds := aws.Creds(os.Getenv("research_key"), os.Getenv("research_secret"), "")
cli := elb.New(creds, "us-east-1", nil)
resp, err := descElb("grinder-perf", cli)
if err != nil {
fmt.Println(err)
}
// fmt.Println(resp)
for _, v := range resp.LoadBalancerDescriptions {
descInstanceHealth(v.Instances, cli)
}
//fmt.Printf("%v", reflect.TypeOf(cli))
// args := os.Args[1:]
// for i := 0; i < len(args); i++ {
//elbinput := elb.DescribeAccessPointsInput{LoadBalancerNames: []string{args[i]},}
//elbs, err := cli.DescribeLoadBalancers(&elbinput)
//elbs, err := cli.DescribeLoadBalancers(nil)
// if err != nil {
// fmt.Print(err)
// }
// for _, elb := range elbs.LoadBalancerDescriptions {
// fmt.Println("LoadBalancer Name:", *elb.LoadBalancerName)
// for _, instance := range elb.Instances {
// fmt.Println(*instance.InstanceID)
// }
// }
// }
}
开发者ID:jaibheem,项目名称:trash,代码行数:29,代码来源:new_elbstat.go
示例2: main
func main() {
AccessKey := os.Getenv("AWS_ACCESS_KEY")
SecretKey := os.Getenv("AWS_SECRET_KEY")
creds := aws.Creds(AccessKey, SecretKey, "")
svc := ec2.New(&aws.Config{Credentials: creds, Region: "ap-southeast-1"})
resp, err := svc.DescribeInstances(nil)
fmt.Println(reflect.TypeOf(resp))
if err != nil {
panic(err)
}
//fmt.Println(resp.Reservations)
for _, reservation := range resp.Reservations {
//fmt.Println(reservation.Instances)
for _, instance := range reservation.Instances {
for _, t := range instance.Tags {
if *t.Value == "cassandra" {
fmt.Print(*instance.InstanceID, "\t", *instance.InstanceType, "\t", *instance.PrivateIPAddress, "\t")
fmt.Println(*t.Value)
fmt.Println()
}
}
}
}
}
开发者ID:jaibheem,项目名称:trash,代码行数:26,代码来源:list_instance.go
示例3: doesSubDomainExist
func doesSubDomainExist(subDomain string) bool {
// if it's configured for testing then skip this step
if utils.Cfg.AWSSettings.Route53AccessKeyId == "" {
return false
}
creds := aws.Creds(utils.Cfg.AWSSettings.Route53AccessKeyId, utils.Cfg.AWSSettings.Route53SecretAccessKey, "")
r53 := route53.New(aws.DefaultConfig.Merge(&aws.Config{Credentials: creds, Region: utils.Cfg.AWSSettings.Route53Region}))
r53req := &route53.ListResourceRecordSetsInput{
HostedZoneID: aws.String(utils.Cfg.AWSSettings.Route53ZoneId),
MaxItems: aws.String("1"),
StartRecordName: aws.String(fmt.Sprintf("%v.%v.", subDomain, utils.Cfg.ServiceSettings.Domain)),
}
if result, err := r53.ListResourceRecordSets(r53req); err != nil {
l4g.Error("error in doesSubDomainExist domain=%v err=%v", subDomain, err)
return true
} else {
for _, v := range result.ResourceRecordSets {
if v.Name != nil && *v.Name == fmt.Sprintf("%v.%v.", subDomain, utils.Cfg.ServiceSettings.Domain) {
return true
}
}
}
return false
}
开发者ID:rasheedamir,项目名称:platform,代码行数:30,代码来源:team.go
示例4: main
func main() {
creds := aws.Creds("ACCESS", "SECRET", "")
cli := elb.New(creds, "us-east-1", nil)
// elbs := elb.DescribeAccessPointsInput{LoadBalancerNames: []string{"grinder-perf", "etcd-test"}}
// elbs.LoadBalancerNames = []string{"test"}
// resp, err := cli.DescribeLoadBalancers(&elbs)
resp, err := getElbInfo("grinder-perf", &cli)
if err != nil {
fmt.Println(err)
return
}
for _, v := range resp.LoadBalancerDescriptions {
// elbInfo[*v.DNSName]
getInstanceHealth(v.Instances, &cli)
// for _, instance := range v.Instances {
// health = getInstanceHealth(id, &cli)
// elbInfo[*v.DNSName][*instance.InstanceID]
// fmt.Println(elbInfo)
// }
// elbInfo["test"]["instance"] = string(*v.Instances[0].InstanceID)
// fmt.Println(*v.Instances[0].InstanceID)
// fmt.Println(v.AvailabilityZones)
}
fmt.Println("######################", elbInfo)
}
开发者ID:jaibheem,项目名称:trash,代码行数:26,代码来源:elbstat.go
示例5: TestRestRequestXMLError
func TestRestRequestXMLError(t *testing.T) {
var m sync.Mutex
var httpReq *http.Request
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
m.Lock()
defer m.Unlock()
httpReq = r
w.Header().Set("Content-Type", "application/xml")
w.WriteHeader(500)
fmt.Fprintln(w, `<Error>
<Code>bonus</Code>
<BucketName>bingo</BucketName>
<Message>the bad thing</Message>
<RequestId>woo woo</RequestId>
<HostId>woo woo</HostId>
</Error>`)
},
))
defer server.Close()
client := aws.RestClient{
Context: aws.Context{
Service: "animals",
Region: "us-west-2",
Credentials: aws.Creds(
"accessKeyID",
"secretAccessKey",
"securityToken",
),
},
Client: http.DefaultClient,
}
req, err := http.NewRequest("GET", server.URL+"/yay", nil)
if err != nil {
t.Fatal(err)
}
_, err = client.Do(req)
if err == nil {
t.Fatal("Expected an error but none was returned")
}
if err, ok := err.(aws.APIError); ok {
if v, want := err.Code, "bonus"; v != want {
t.Errorf("Error code was %v, but expected %v", v, want)
}
if v, want := err.Message, "the bad thing"; v != want {
t.Errorf("Error message was %v, but expected %v", v, want)
}
} else {
t.Errorf("Unknown error returned: %#v", err)
}
}
开发者ID:2722,项目名称:lantern,代码行数:59,代码来源:rest_test.go
示例6: NewManager
func NewManager(addr string, password string, awsId string, awsKey string, zoneId string, defaultTTL int64, reservedPrefixes []string, maxUserDomains int) (*Manager, error) {
log.Debugf("connecting to redis: addr=%s", addr)
pool := &redis.Pool{
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", addr)
if err != nil {
return nil, err
}
if password != "" {
if _, err := c.Do("AUTH", password); err != nil {
c.Close()
return nil, err
}
}
return c, err
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
log.Debugf("maximum user domains: %d", maxUserDomains)
creds := aws.Creds(awsId, awsKey, "")
awsConfig := &aws.Config{
Credentials: creds,
}
r53 := route53.New(awsConfig)
params := &route53.GetHostedZoneInput{
ID: aws.String(zoneId),
}
resp, err := r53.GetHostedZone(params)
if err != nil {
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("no zone returned")
}
zoneBase := *resp.HostedZone.Name
log.Infof("connected to route53: zone=%s", zoneBase)
return &Manager{
pool: pool,
r53: r53,
zoneId: zoneId,
defaultTTL: defaultTTL,
zoneBase: zoneBase,
reservedPrefixes: reservedPrefixes,
maxUserDomains: maxUserDomains,
}, nil
}
开发者ID:cncodog,项目名称:shpd,代码行数:59,代码来源:manager.go
示例7: NewS3Source
//NewS3Source create s3 source with access key and secret key
func NewS3Source(accessKey, secretKey string) *S3Source {
cli := s3.New(&aws.Config{
Credentials: aws.Creds(accessKey, secretKey, ""),
Region: "ap-southeast-1",
})
return &S3Source{cli}
}
开发者ID:maxid,项目名称:ivy,代码行数:9,代码来源:s3source.go
示例8: FindCredentials
func (c *AWSCluster) FindCredentials() (aws.CredentialsProvider, error) {
if c.base.CredentialID == "aws_env" {
return aws.EnvCreds()
}
cred, err := c.base.FindCredentials()
if err != nil {
return nil, err
}
return aws.Creds(cred.ID, cred.Secret, ""), nil
}
开发者ID:ably-forks,项目名称:flynn,代码行数:10,代码来源:aws_cluster.go
示例9: SetCreds
func (c *AWSCluster) SetCreds(creds *Credential) error {
if creds == nil || creds.ID == "aws_env" {
c.base.CredentialID = "aws_env"
awsCreds, err := aws.EnvCreds()
if err != nil {
return err
}
c.creds = awsCreds
} else {
c.base.credential = creds
c.base.CredentialID = creds.ID
c.creds = aws.Creds(creds.ID, creds.Secret, "")
}
c.ec2 = ec2.New(c.creds, c.Region, nil)
c.cf = cloudformation.New(c.creds, c.Region, nil)
return nil
}
开发者ID:ably-forks,项目名称:flynn,代码行数:17,代码来源:aws_cluster.go
示例10: TestJSONRequestError
func TestJSONRequestError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
fmt.Fprintln(w, `{"__type":"Problem", "message":"What even"}`)
},
))
defer server.Close()
client := aws.JSONClient{
Context: aws.Context{
Service: "animals",
Region: "us-west-2",
Credentials: aws.Creds(
"accessKeyID",
"secretAccessKey",
"securityToken",
),
},
Client: http.DefaultClient,
Endpoint: server.URL,
TargetPrefix: "Animals",
JSONVersion: "1.1",
}
req := fakeJSONRequest{Name: "Penny"}
var resp fakeJSONResponse
err := client.Do("PetTheDog", "POST", "/", req, &resp)
if err == nil {
t.Fatal("Expected an error but none was returned")
}
if err, ok := err.(aws.APIError); ok {
if v, want := err.Type, "Problem"; v != want {
t.Errorf("Error type was %v, but expected %v", v, want)
}
if v, want := err.Message, "What even"; v != want {
t.Errorf("Error message was %v, but expected %v", v, want)
}
} else {
t.Errorf("Unknown error returned: %#v", err)
}
}
开发者ID:ComeOn-Wuhan,项目名称:lantern,代码行数:44,代码来源:json_test.go
示例11: createSubDomain
func createSubDomain(subDomain string, target string) {
if utils.Cfg.AWSSettings.Route53AccessKeyId == "" {
return
}
creds := aws.Creds(utils.Cfg.AWSSettings.Route53AccessKeyId, utils.Cfg.AWSSettings.Route53SecretAccessKey, "")
r53 := route53.New(aws.DefaultConfig.Merge(&aws.Config{Credentials: creds, Region: utils.Cfg.AWSSettings.Route53Region}))
rr := route53.ResourceRecord{
Value: aws.String(target),
}
rrs := make([]*route53.ResourceRecord, 1)
rrs[0] = &rr
change := route53.Change{
Action: aws.String("CREATE"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(fmt.Sprintf("%v.%v", subDomain, utils.Cfg.ServiceSettings.Domain)),
TTL: aws.Long(300),
Type: aws.String("CNAME"),
ResourceRecords: rrs,
},
}
changes := make([]*route53.Change, 1)
changes[0] = &change
r53req := &route53.ChangeResourceRecordSetsInput{
HostedZoneID: aws.String(utils.Cfg.AWSSettings.Route53ZoneId),
ChangeBatch: &route53.ChangeBatch{
Changes: changes,
},
}
if _, err := r53.ChangeResourceRecordSets(r53req); err != nil {
l4g.Error("erro in createSubDomain domain=%v err=%v", subDomain, err)
return
}
}
开发者ID:rasheedamir,项目名称:platform,代码行数:41,代码来源:team.go
示例12: main
func main() {
// files := map[string]*s3driver.MemoryFile{
// "/": &s3driver.MemoryFile{graval.NewDirItem(""), nil},
// }
credentialsProvider := aws.Creds(awsAccessKeyID, awsSecretAccessKey, "")
factory := &s3driver.S3DriverFactory{
Username: username,
Password: password,
AWSRegion: awsRegion,
AWSCredentialsProvider: credentialsProvider,
AWSBucketName: awsBucketName,
}
server := graval.NewFTPServer(&graval.FTPServerOpts{
ServerName: serverName,
Factory: factory,
Hostname: host,
Port: port,
PassiveOpts: &graval.PassiveOpts{
ListenAddress: host,
NatAddress: host,
PassivePorts: &graval.PassivePorts{
Low: 42000,
High: 45000,
},
},
})
log.Printf("FTP2S3 server listening on %s:%d", host, port)
log.Printf("Access: ftp://%s:%[email protected]%s:%d/", username, password, host, port)
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}
开发者ID:PaulMaddox,项目名称:ftp2s3,代码行数:39,代码来源:ftp2s3.go
示例13: TestQueryRequest
func TestQueryRequest(t *testing.T) {
var m sync.Mutex
var httpReq *http.Request
var form url.Values
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
m.Lock()
defer m.Unlock()
httpReq = r
if err := r.ParseForm(); err != nil {
t.Fatal(err)
}
form = r.Form
fmt.Fprintln(w, `<Thing><IpAddress>woo</IpAddress></Thing>`)
},
))
defer server.Close()
client := aws.QueryClient{
Context: aws.Context{
Service: "animals",
Region: "us-west-2",
Credentials: aws.Creds(
"accessKeyID",
"secretAccessKey",
"securityToken",
),
},
Client: http.DefaultClient,
Endpoint: server.URL,
APIVersion: "1.1",
}
req := fakeQueryRequest{
PresentString: aws.String("string"),
PresentBoolean: aws.True(),
PresentInteger: aws.Integer(1),
PresentLong: aws.Long(2),
PresentDouble: aws.Double(1.2),
PresentFloat: aws.Float(2.3),
PresentTime: time.Date(2001, 1, 1, 2, 1, 1, 0, time.FixedZone("UTC+1", 3600)),
PresentSlice: []string{"one", "two"},
PresentStruct: &EmbeddedStruct{Value: aws.String("v")},
PresentStructSlice: []EmbeddedStruct{
{Value: aws.String("p")},
{Value: aws.String("q")},
},
PresentMap: map[string]EmbeddedStruct{
"aa": EmbeddedStruct{Value: aws.String("AA")},
"bb": EmbeddedStruct{Value: aws.String("BB")},
},
}
var resp fakeQueryResponse
if err := client.Do("GetIP", "POST", "/", &req, &resp); err != nil {
t.Fatal(err)
}
m.Lock()
defer m.Unlock()
if v, want := httpReq.Method, "POST"; v != want {
t.Errorf("Method was %v but expected %v", v, want)
}
if httpReq.Header.Get("Authorization") == "" {
t.Error("Authorization header is missing")
}
if v, want := httpReq.Header.Get("Content-Type"), "application/x-www-form-urlencoded"; v != want {
t.Errorf("Content-Type was %v but expected %v", v, want)
}
if v, want := httpReq.Header.Get("User-Agent"), "aws-go"; v != want {
t.Errorf("User-Agent was %v but expected %v", v, want)
}
if err := httpReq.ParseForm(); err != nil {
t.Fatal(err)
}
expectedForm := url.Values{
"Action": []string{"GetIP"},
"Version": []string{"1.1"},
"PresentString": []string{"string"},
"PresentBoolean": []string{"true"},
"PresentInteger": []string{"1"},
"PresentLong": []string{"2"},
"PresentDouble": []string{"1.2"},
"PresentFloat": []string{"2.3"},
"PresentTime": []string{"2001-01-01T01:01:01Z"},
"PresentSlice.1": []string{"one"},
"PresentSlice.2": []string{"two"},
"PresentStruct.Value": []string{"v"},
"PresentStructSlice.1.Value": []string{"p"},
"PresentStructSlice.2.Value": []string{"q"},
"PresentMap.1.Name": []string{"aa"},
//.........这里部分代码省略.........
开发者ID:ComeOn-Wuhan,项目名称:lantern,代码行数:101,代码来源:query_test.go
示例14: TestQueryRequestError
func TestQueryRequestError(t *testing.T) {
var m sync.Mutex
var httpReq *http.Request
var form url.Values
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
m.Lock()
defer m.Unlock()
httpReq = r
if err := r.ParseForm(); err != nil {
t.Fatal(err)
}
form = r.Form
w.WriteHeader(400)
fmt.Fprintln(w, `<ErrorResponse>
<RequestId>woo</RequestId>
<Error>
<Type>Problem</Type>
<Code>Uh Oh</Code>
<Message>You done did it</Message>
</Error>
</ErrorResponse>`)
},
))
defer server.Close()
client := aws.QueryClient{
Context: aws.Context{
Service: "animals",
Region: "us-west-2",
Credentials: aws.Creds(
"accessKeyID",
"secretAccessKey",
"securityToken",
),
},
Client: http.DefaultClient,
Endpoint: server.URL,
APIVersion: "1.1",
}
req := fakeQueryRequest{}
var resp fakeQueryResponse
err := client.Do("GetIP", "POST", "/", &req, &resp)
if err == nil {
t.Fatal("Expected an error but none was returned")
}
if err, ok := err.(aws.APIError); ok {
if v, want := err.Type, "Problem"; v != want {
t.Errorf("Error type was %v, but expected %v", v, want)
}
if v, want := err.Code, "Uh Oh"; v != want {
t.Errorf("Error type was %v, but expected %v", v, want)
}
if v, want := err.Message, "You done did it"; v != want {
t.Errorf("Error message was %v, but expected %v", v, want)
}
} else {
t.Errorf("Unknown error returned: %#v", err)
}
}
开发者ID:ComeOn-Wuhan,项目名称:lantern,代码行数:68,代码来源:query_test.go
示例15: newClient
func (s3 *s3) newClient() *awsS3.S3 {
return awsS3.New(&aws.Config{
Credentials: aws.Creds(s3.conf.AWS.AccessKeyID, s3.conf.AWS.SecretAccessKey, ""),
Region: s3.conf.AWS.Region,
})
}
开发者ID:experiment,项目名称:front,代码行数:6,代码来源:s3.go
示例16: TestRestRequest
func TestRestRequest(t *testing.T) {
var m sync.Mutex
var httpReq *http.Request
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
m.Lock()
defer m.Unlock()
httpReq = r
fmt.Fprintln(w, `woo`)
},
))
defer server.Close()
client := aws.RestClient{
Context: aws.Context{
Service: "animals",
Region: "us-west-2",
Credentials: aws.Creds(
"accessKeyID",
"secretAccessKey",
"securityToken",
),
},
Client: http.DefaultClient,
}
req, err := http.NewRequest("GET", server.URL+"/yay", nil)
if err != nil {
t.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if v, want := string(body), "woo\n"; v != want {
t.Errorf("Response entity was %q, but expected %q", v, want)
}
m.Lock()
defer m.Unlock()
if v, want := httpReq.Method, "GET"; v != want {
t.Errorf("Method was %v but expected %v", v, want)
}
if httpReq.Header.Get("Authorization") == "" {
t.Error("Authorization header is missing")
}
if v, want := httpReq.Header.Get("User-Agent"), "aws-go"; v != want {
t.Errorf("User-Agent was %v but expected %v", v, want)
}
if v, want := httpReq.URL.String(), "/yay"; v != want {
t.Errorf("URL was %v but expected %v", v, want)
}
}
开发者ID:2722,项目名称:lantern,代码行数:68,代码来源:rest_test.go
示例17: TestJSONRequest
func TestJSONRequest(t *testing.T) {
var m sync.Mutex
var httpReq *http.Request
var body []byte
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
m.Lock()
defer m.Unlock()
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
defer r.Body.Close()
httpReq = r
body = b
fmt.Fprintln(w, `{"TailWagged":true}`)
},
))
defer server.Close()
client := aws.JSONClient{
Context: aws.Context{
Service: "animals",
Region: "us-west-2",
Credentials: aws.Creds(
"accessKeyID",
"secretAccessKey",
"securityToken",
),
},
Client: http.DefaultClient,
Endpoint: server.URL,
TargetPrefix: "Animals",
JSONVersion: "1.1",
}
req := fakeJSONRequest{Name: "Penny"}
var resp fakeJSONResponse
if err := client.Do("PetTheDog", "POST", "/", req, &resp); err != nil {
t.Fatal(err)
}
m.Lock()
defer m.Unlock()
if v, want := httpReq.Method, "POST"; v != want {
t.Errorf("Method was %v but expected %v", v, want)
}
if httpReq.Header.Get("Authorization") == "" {
t.Error("Authorization header is missing")
}
if v, want := httpReq.Header.Get("Content-Type"), "application/x-amz-json-1.1"; v != want {
t.Errorf("Content-Type was %v but expected %v", v, want)
}
if v, want := httpReq.Header.Get("User-Agent"), "aws-go"; v != want {
t.Errorf("User-Agent was %v but expected %v", v, want)
}
if v, want := httpReq.Header.Get("X-Amz-Target"), "Animals.PetTheDog"; v != want {
t.Errorf("X-Amz-Target was %v but expected %v", v, want)
}
if v, want := string(body), `{"Name":"Penny"}`; v != want {
t.Errorf("Body was %v but expected %v", v, want)
}
if v, want := resp, (fakeJSONResponse{TailWagged: true}); v != want {
t.Errorf("Response was %#v but expected %#v", v, want)
}
}
开发者ID:ComeOn-Wuhan,项目名称:lantern,代码行数:77,代码来源:json_test.go
注:本文中的github.com/awslabs/aws-sdk-go/aws.Creds函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论