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


Golang aws.NewAuth函数代码示例

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


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


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