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


Golang aws.Auth类代码示例

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


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

示例1: sign

func sign(auth aws.Auth, method, path string, params map[string]string, host string) {
	params["AWSAccessKeyId"] = auth.AccessKey
	params["SignatureVersion"] = "2"
	params["SignatureMethod"] = "HmacSHA256"
	if auth.Token() != "" {
		params["SecurityToken"] = auth.Token()
	}

	// AWS specifies that the parameters in a signed request must
	// be provided in the natural order of the keys. This is distinct
	// from the natural order of the encoded value of key=value.
	// Percent and gocheck.Equals affect the sorting order.
	var keys, sarray []string
	for k, _ := range params {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, k := range keys {
		sarray = append(sarray, aws.Encode(k)+"="+aws.Encode(params[k]))
	}
	joined := strings.Join(sarray, "&")
	payload := method + "\n" + host + "\n" + path + "\n" + joined
	hash := hmac.New(sha256.New, []byte(auth.SecretKey))
	hash.Write([]byte(payload))
	signature := make([]byte, b64.EncodedLen(hash.Size()))
	b64.Encode(signature, hash.Sum(nil))

	params["Signature"] = string(signature)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:29,代码来源:sign.go

示例2: MakeDynamoDBStore

func MakeDynamoDBStore(awsAccessKey, awsSecretKey string) *TDynamoDBStore {
	var (
		auth aws.Auth
		pk   dynamodb.PrimaryKey
	)
	contract.RequireNoErrors(
		func() (err error) {
			auth, err = aws.GetAuth(awsAccessKey, awsSecretKey, auth.Token(), auth.Expiration())
			return
		},
		func() (err error) {
			desc := DynamoDBDemoTableDescription()
			pk, err = desc.BuildPrimaryKey()
			return
		})

	dynamo := dynamodb.Server{auth, aws.USWest2} // hardcode ftw
	table := dynamo.NewTable(DynamoDbDemoTable, pk)
	return &TDynamoDBStore{&dynamo, table}
}
开发者ID:superduper,项目名称:gosandbox,代码行数:20,代码来源:dynamodb.go

示例3: sign

func sign(auth aws.Auth, method, path string, params url.Values, headers http.Header) {
	var host string
	for k, v := range headers {
		k = strings.ToLower(k)
		switch k {
		case "host":
			host = v[0]
		}
	}

	// set up some defaults used for signing the request
	params["AWSAccessKeyId"] = []string{auth.AccessKey}
	params["SignatureVersion"] = []string{"2"}
	params["SignatureMethod"] = []string{"HmacSHA256"}
	if auth.Token() != "" {
		params["SecurityToken"] = []string{auth.Token()}
	}

	// join up all the incoming params
	var sarray []string
	for k, v := range params {
		sarray = append(sarray, aws.Encode(k)+"="+aws.Encode(v[0]))
	}
	sort.StringSlice(sarray).Sort()
	joined := strings.Join(sarray, "&")

	// create the payload, sign it and create the signature
	payload := strings.Join([]string{method, host, "/", joined}, "\n")
	hash := hmac.New(sha256.New, []byte(auth.SecretKey))
	hash.Write([]byte(payload))
	signature := make([]byte, b64.EncodedLen(hash.Size()))
	b64.Encode(signature, hash.Sum(nil))

	// add the signature to the outgoing params
	params["Signature"] = []string{string(signature)}
}
开发者ID:hayesgm,项目名称:goamz,代码行数:36,代码来源:sign.go


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