예제 #1
0
func createHeaders(extraHeaders http.Header, credentials *auth.Credentials, contentType, rfc1123Date,
	apiVersion string, isMantaRequest bool) (http.Header, error) {

	headers := make(http.Header)
	if extraHeaders != nil {
		for header, values := range extraHeaders {
			for _, value := range values {
				headers.Add(header, value)
			}
		}
	}
	if extraHeaders.Get("Content-Type") == "" {
		headers.Add("Content-Type", contentType)
	}
	if extraHeaders.Get("Accept") == "" {
		headers.Add("Accept", contentType)
	}
	if rfc1123Date != "" {
		headers.Set("Date", rfc1123Date)
	} else {
		headers.Set("Date", getDateForRegion(credentials, isMantaRequest))
	}
	authHeaders, err := auth.CreateAuthorizationHeader(headers, credentials, isMantaRequest)
	if err != nil {
		return http.Header{}, err
	}
	headers.Set("Authorization", authHeaders)
	if apiVersion != "" {
		headers.Set("X-Api-Version", apiVersion)
	}
	headers.Add("User-Agent", gojoyentAgent())
	return headers, nil
}
예제 #2
0
파일: auth_test.go 프로젝트: joyent/gosign
func (s *AuthSuite) TestCreateMantaAuthorizationHeader(c *gc.C) {
	headers := make(http.Header)
	headers["Date"] = []string{"Mon, 14 Oct 2013 18:49:29 GMT"}
	authentication, err := auth.NewAuth("test_user", key, "rsa-sha256")
	c.Assert(err, gc.IsNil)
	credentials := &auth.Credentials{
		UserAuthentication: authentication,
		MantaKeyId:         "test_key",
		MantaEndpoint:      auth.Endpoint{URL: "http://gotest.manta.joyent.com"},
	}
	authHeader, err := auth.CreateAuthorizationHeader(headers, credentials, true)
	c.Assert(err, gc.IsNil)
	c.Assert(authHeader, gc.Equals, "Signature keyId=\"/test_user/keys/"+testJpcKeyName+"\",algorithm=\"rsa-sha256\",signature=\""+MantaSignature+"\"")
}
예제 #3
0
func SignHeader(url string, header http.Header, org, user, key string) string {
	// TODO: algorithm should be dynamic
	authentication, err := auth.NewAuth(org, key, "rsa-sha256")
	check(err, "Error while creating a new auth:")

	credentials := &auth.Credentials{
		UserAuthentication: authentication,
		SdcKeyId:           user,
		SdcEndpoint:        auth.Endpoint{URL: url},
	}
	auth_header, err := auth.CreateAuthorizationHeader(header, credentials, false)
	check(err, "Error while CreateAuthorizationHeader:")

	return auth_header
}