本文整理汇总了Golang中github.com/goamz/goamz/aws.NewAuth函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAuth函数的具体用法?Golang NewAuth怎么用?Golang NewAuth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAuth函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: AssumeRole
// Assume role uses the current server role to call STS and assume a different role if permitted
// Params:
// roleArn - the requested role ARN (example: arn:aws:iam::11111111111:role/myrole )
// sessionName - a name to associate with the current session. Use the service name +
// unique idenfitifier preferebly.
// duration - the duration of the session in seconds. Must be between 900 and 3600
// Returns aws.Auth object that can be used with any of the existing goamz APIs
//
// Check http://goo.gl/M6uCu5 for more information
//
func AssumeRole(roleArn string, sessionName string, duration int) (*aws.Auth, error) {
if duration < 900 || duration > 3600 {
return nil, fmt.Errorf("Duration out of bounds")
}
//Try to get our local auth
localAuth, err := aws.GetAuth("", "", "", time.Time{})
if err != nil {
return nil, err
}
stsClient := sts.New(localAuth, aws.Regions[util.GetAwsRegionName()])
stsOptions := &sts.AssumeRoleParams{
DurationSeconds: int(duration),
RoleArn: roleArn,
RoleSessionName: sessionName,
}
//Try to assume role
roleAuth, err := stsClient.AssumeRole(stsOptions)
if err != nil {
return nil, err
}
//Marshal the response into an aws.Auth object
auth := aws.NewAuth(roleAuth.Credentials.AccessKeyId, roleAuth.Credentials.SecretAccessKey,
roleAuth.Credentials.SessionToken, roleAuth.Credentials.Expiration)
return auth, nil
}
开发者ID:choirudin2210,项目名称:service-layer,代码行数:40,代码来源:sts.go
示例2: NewFrom
// NewFrom Create A new SQS Client given an access and secret Key
// region must be one of "us.east, us.west, eu.west"
func NewFrom(accessKey, secretKey, region string) (*SQS, error) {
auth := aws.NewAuth(accessKey, secretKey, "", time.Time{})
aws_region := aws.USEast
switch region {
case "us.east", "us.east.1":
aws_region = aws.USEast
case "us.west", "us.west.1":
aws_region = aws.USWest
case "us.west.2":
aws_region = aws.USWest2
case "eu.west":
aws_region = aws.EUWest
case "ap.southeast", "ap.southeast.1":
aws_region = aws.APSoutheast
case "ap.southeast.2":
aws_region = aws.APSoutheast2
case "ap.northeast", "ap.northeast.1":
aws_region = aws.APNortheast
case "sa.east", "sa.east.1":
aws_region = aws.SAEast
case "cn.north", "cn.north.1":
aws_region = aws.CNNorth
default:
return nil, errors.New(fmt.Sprintf("Unknown/Unsupported region %s", region))
}
aws_sqs := New(auth, aws_region)
return aws_sqs, nil
}
开发者ID:aalness,项目名称:goamz,代码行数:33,代码来源:sqs.go
示例3: TestBasicGroupRequest
func TestBasicGroupRequest(t *testing.T) {
var as *AutoScaling
awsAuth, err := aws.EnvAuth()
if err != nil {
mockTest = true
t.Log("Running mock tests as AWS environment variables are not set")
awsAuth := aws.NewAuth("abc", "123", "", time.Time{})
as = New(awsAuth, aws.Region{AutoScalingEndpoint: testServer.URL})
testServer.Start()
go testServer.WaitRequest()
testServer.Response(200, nil, BasicGroupResponse)
} else {
as = New(awsAuth, aws.USWest2)
}
groupResp, err := as.DescribeAutoScalingGroups(nil, 10, "")
if err != nil {
t.Fatal(err)
}
if len(groupResp.AutoScalingGroups) > 0 {
firstGroup := groupResp.AutoScalingGroups[0]
if len(firstGroup.AutoScalingGroupName) > 0 {
t.Logf("Found AutoScaling group %s\n",
firstGroup.AutoScalingGroupName)
}
}
testServer.Flush()
}
开发者ID:aalness,项目名称:goamz,代码行数:29,代码来源:autoscaling_test.go
示例4: SetUpSuite
func (s *S) SetUpSuite(c *C) {
var err error
testServer.Start()
auth := aws.NewAuth("abc", "123", "", time.Time{})
s.rds, err = rds.New(auth, aws.Region{RDSEndpoint: aws.ServiceInfo{testServer.URL, aws.V2Signature}})
c.Assert(err, IsNil)
}
开发者ID:aalness,项目名称:goamz,代码行数:7,代码来源:rds_test.go
示例5: s3Client
func s3Client() *s3.S3 {
r := aws.Region{
Name: "jp-east",
S3Endpoint: "https://ds.jp-east.idcfcloud.com",
}
auth := aws.NewAuth(os.Getenv("IDCF_ACCESS_KEY"), os.Getenv("IDCF_ACCESS_SECRET"), "", time.Now())
return s3.New(*auth, r)
}
开发者ID:f110,项目名称:okinawa-ceasar,代码行数:8,代码来源:object_storage.go
示例6: SetUp
func (s *LocalServer) SetUp(c *C) {
srv, err := elbtest.NewServer()
c.Assert(err, IsNil)
c.Assert(srv, NotNil)
s.srv = srv
s.region = aws.Region{ELBEndpoint: srv.URL()}
s.auth = aws.NewAuth("", "", "", time.Time{})
}
开发者ID:aalness,项目名称:goamz,代码行数:8,代码来源:elbt_test.go
示例7: TestGetAuthEnv
func (s *S) TestGetAuthEnv(c *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, IsNil)
c.Assert(*auth, Equals, *aws.NewAuth("access", "secret", "", time.Time{}))
}
开发者ID:aalness,项目名称:goamz,代码行数:8,代码来源:aws_test.go
示例8: SetUpSuite
func (s *S) SetUpSuite(c *C) {
testServer.Start()
auth := aws.NewAuth("abc", "123", "", time.Time{})
s.ec2 = ec2.NewWithClient(
auth,
aws.Region{EC2Endpoint: testServer.URL},
testutil.DefaultClient,
)
}
开发者ID:aalness,项目名称:goamz,代码行数:9,代码来源:ec2_test.go
示例9: TestSignatureExample1
func (s *S) TestSignatureExample1(c *C) {
params := map[string]string{
"Timestamp": "2009-02-01T12:53:20+00:00",
"Version": "2007-11-07",
"Action": "ListDomains",
}
elb.Sign(aws.NewAuth("access", "secret", "", time.Time{}), "GET", "/", params, "sdb.amazonaws.com")
expected := "okj96/5ucWBSc1uR2zXVfm6mDHtgfNv657rRtt/aunQ="
c.Assert(params["Signature"], Equals, expected)
}
开发者ID:aalness,项目名称:goamz,代码行数:10,代码来源:sign_test.go
示例10: SetUpSuite
func (s *S) SetUpSuite(c *C) {
testServer.Start()
auth := aws.NewAuth("abc", "123", "", time.Time{})
u, err := url.Parse(testServer.URL)
if err != nil {
panic(err.Error())
}
s.mturk = &mturk.MTurk{
Auth: auth,
URL: u,
}
}
开发者ID:aalness,项目名称:goamz,代码行数:13,代码来源:mturk_test.go
示例11: SetUp
func (s *LocalServer) SetUp(c *C) {
srv, err := s3test.NewServer(s.config)
c.Assert(err, IsNil)
c.Assert(srv, NotNil)
s.srv = srv
s.region = aws.Region{
Name: "faux-region-1",
S3Endpoint: srv.URL(),
S3LocationConstraint: true, // s3test server requires a LocationConstraint
}
s.auth = aws.NewAuth("", "", "", time.Time{})
}
开发者ID:aalness,项目名称:goamz,代码行数:13,代码来源:s3t_test.go
示例12: TestSharedAuthDefaultCredentials
func (s *S) TestSharedAuthDefaultCredentials(c *C) {
os.Clearenv()
d, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
}
defer os.RemoveAll(d)
err = os.Mkdir(d+"/.aws", 0755)
if err != nil {
panic(err)
}
ioutil.WriteFile(d+"/.aws/credentials", []byte("[default]\naws_access_key_id = access\naws_secret_access_key = secret\n"), 0644)
os.Setenv("HOME", d)
auth, err := aws.SharedAuth()
c.Assert(err, IsNil)
c.Assert(*auth, Equals, *aws.NewAuth("access", "secret", "", time.Time{}))
}
开发者ID:aalness,项目名称:goamz,代码行数:21,代码来源:aws_test.go
示例13: setUpAuth
func setUpAuth(c *C) {
if !*amazon && !*local {
c.Skip("Neither test against local nor amazon is enabled.")
}
if *local {
c.Log("Using local server")
dynamodb_region = aws.Region{
DynamoDBEndpoint: "http://127.0.0.1:8000",
DynamoDBStreamsEndpoint: "http://127.0.0.1:8000",
}
dynamodb_auth = aws.NewAuth("DUMMY_KEY", "DUMMY_SECRET", "", time.Time{})
} else {
c.Log("Using REAL AMAZON SERVER")
dynamodb_region = aws.USEast
auth, err := aws.EnvAuth()
if err != nil {
c.Fatal(err)
}
dynamodb_auth = auth
}
}
开发者ID:aalness,项目名称:goamz,代码行数:21,代码来源:dynamodb_test.go
示例14: SetUpSuite
func (s *S) SetUpSuite(c *C) {
testServer.Start()
auth := aws.NewAuth("abc", "123", "", time.Time{})
s.sts = sts.New(auth, aws.Region{STSEndpoint: testServer.URL})
}
开发者ID:aalness,项目名称:goamz,代码行数:5,代码来源:sts_test.go
示例15: SetUpSuite
func (s *S) SetUpSuite(c *C) {
testServer.Start()
auth := aws.NewAuth("abc", "123", "", time.Time{})
s.cf = cf.New(auth, aws.Region{CloudFormationEndpoint: testServer.URL})
}
开发者ID:aalness,项目名称:goamz,代码行数:5,代码来源:cloudformation_test.go
示例16: SetUpSuite
func (s *S) SetUpSuite(c *C) {
s.HTTPSuite.SetUpSuite(c)
auth := aws.NewAuth("abc", "123", "", time.Time{})
s.elb = elb.New(auth, aws.Region{ELBEndpoint: testServer.URL})
}
开发者ID:aalness,项目名称:goamz,代码行数:5,代码来源:elb_test.go
示例17: TestBasicSignature
package elb_test
import (
"time"
"github.com/goamz/goamz/aws"
"github.com/goamz/goamz/elb"
. "gopkg.in/check.v1"
)
var testAuth = aws.NewAuth("user", "secret", "", time.Time{})
func (s *S) TestBasicSignature(c *C) {
params := map[string]string{}
elb.Sign(testAuth, "GET", "/path", params, "localhost")
c.Assert(params["SignatureVersion"], Equals, "2")
c.Assert(params["SignatureMethod"], Equals, "HmacSHA256")
expected := "6lSe5QyXum0jMVc7cOUz32/52ZnL7N5RyKRk/09yiK4="
c.Assert(params["Signature"], Equals, expected)
}
func (s *S) TestParamSignature(c *C) {
params := map[string]string{
"param1": "value1",
"param2": "value2",
"param3": "value3",
}
elb.Sign(testAuth, "GET", "/path", params, "localhost")
expected := "XWOR4+0lmK8bD8CGDGZ4kfuSPbb2JibLJiCl/OPu1oU="
c.Assert(params["Signature"], Equals, expected)
}
开发者ID:aalness,项目名称:goamz,代码行数:31,代码来源:sign_test.go
示例18: TestSignExampleDomainCreate
package sdb_test
import (
"time"
"github.com/goamz/goamz/aws"
"github.com/goamz/goamz/exp/sdb"
. "gopkg.in/check.v1"
)
// SimpleDB ReST authentication docs: http://goo.gl/CaY81
var testAuth = aws.NewAuth("access-key-id-s8eBOWuU", "secret-access-key-UkQjTLd9", "", time.Time{})
func (s *S) TestSignExampleDomainCreate(c *C) {
method := "GET"
params := map[string][]string{
"Action": {"CreateDomain"},
"DomainName": {"MyDomain"},
"Timestamp": {"2011-08-20T07:23:57+12:00"},
"Version": {"2009-04-15"},
}
headers := map[string][]string{
"Host": {"sdb.amazonaws.com"},
}
sdb.Sign(testAuth, method, "", params, headers)
expected := "ot2JaeeqMRJqgAqW67hkzUlffgxdOz4RykbrECB+tDU="
c.Assert(params["Signature"], DeepEquals, []string{expected})
}
// Do a few test methods which takes combinations of params
开发者ID:aalness,项目名称:goamz,代码行数:31,代码来源:sign_test.go
示例19: SetUpSuite
func (s *S) SetUpSuite(c *C) {
testServer.Start()
auth := aws.NewAuth("abc", "123", "", time.Time{})
s.ses = ses.NewSES(auth, aws.Region{Name: "faux-region-1", S3Endpoint: testServer.URL})
}
开发者ID:aalness,项目名称:goamz,代码行数:5,代码来源:ses_test.go
示例20: TestAutoScalingGroup
func TestAutoScalingGroup(t *testing.T) {
var as *AutoScaling
// Launch configuration test config
lc := new(LaunchConfiguration)
lc.LaunchConfigurationName = "LConf1"
lc.ImageId = "ami-03e47533" // Octave debian ami
lc.KernelId = "aki-98e26fa8"
lc.KeyName = "testAWS" // Replace with valid key for your account
lc.InstanceType = "m1.small"
// CreateAutoScalingGroup params test config
asgReq := new(CreateAutoScalingGroupParams)
asgReq.AutoScalingGroupName = "ASGTest1"
asgReq.LaunchConfigurationName = lc.LaunchConfigurationName
asgReq.DefaultCooldown = 300
asgReq.HealthCheckGracePeriod = 300
asgReq.DesiredCapacity = 1
asgReq.MinSize = 1
asgReq.MaxSize = 5
asgReq.AvailabilityZones = []string{"us-west-2a"}
asg := new(AutoScalingGroup)
asg.AutoScalingGroupName = "ASGTest1"
asg.LaunchConfigurationName = lc.LaunchConfigurationName
asg.DefaultCooldown = 300
asg.HealthCheckGracePeriod = 300
asg.DesiredCapacity = 1
asg.MinSize = 1
asg.MaxSize = 5
asg.AvailabilityZones = []string{"us-west-2a"}
awsAuth, err := aws.EnvAuth()
if err != nil {
mockTest = true
t.Log("Running mock tests as AWS environment variables are not set")
awsAuth := aws.NewAuth("abc", "123", "", time.Time{})
as = New(awsAuth, aws.Region{AutoScalingEndpoint: testServer.URL})
} else {
as = New(awsAuth, aws.USWest2)
}
// Create the launch configuration
if mockTest {
testServer.Response(200, nil, CreateLaunchConfigurationResponse)
}
_, err = as.CreateLaunchConfiguration(lc)
if err != nil {
t.Fatal(err)
}
// Check that we can get the launch configuration details
if mockTest {
testServer.Response(200, nil, DescribeLaunchConfigurationsResponse)
}
_, err = as.DescribeLaunchConfigurations([]string{lc.LaunchConfigurationName}, 10, "")
if err != nil {
t.Fatal(err)
}
// Create the AutoScalingGroup
if mockTest {
testServer.Response(200, nil, CreateAutoScalingGroupResponse)
}
_, err = as.CreateAutoScalingGroup(asgReq)
if err != nil {
t.Fatal(err)
}
// Check that we can get the autoscaling group details
if mockTest {
testServer.Response(200, nil, DescribeAutoScalingGroupsResponse)
}
_, err = as.DescribeAutoScalingGroups(nil, 10, "")
if err != nil {
t.Fatal(err)
}
// Suspend the scaling processes for the test AutoScalingGroup
if mockTest {
testServer.Response(200, nil, SuspendProcessesResponse)
}
_, err = as.SuspendProcesses(asg.AutoScalingGroupName, nil)
if err != nil {
t.Fatal(err)
}
// Resume scaling processes for the test AutoScalingGroup
if mockTest {
testServer.Response(200, nil, ResumeProcessesResponse)
}
_, err = as.ResumeProcesses(asg.AutoScalingGroupName, nil)
if err != nil {
t.Fatal(err)
}
// Change the desired capacity from 1 to 2. This will launch a second instance
if mockTest {
testServer.Response(200, nil, SetDesiredCapacityResponse)
}
_, err = as.SetDesiredCapacity(asg.AutoScalingGroupName, 2, false)
//.........这里部分代码省略.........
开发者ID:aalness,项目名称:goamz,代码行数:101,代码来源:autoscaling_test.go
注:本文中的github.com/goamz/goamz/aws.NewAuth函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论