Skip to content
Snippets Groups Projects
Commit bd6ee753 authored by Ooo0oO0o0oO's avatar Ooo0oO0o0oO
Browse files

add some comments

parent e16d3915
No related branches found
No related tags found
No related merge requests found
......@@ -339,6 +339,8 @@ func (c URL) ServiceKey() string {
return buf.String()
}
// ColonSeparatedKey
// The format is "{interface}:[version]:[group]"
func (c *URL) ColonSeparatedKey() string {
intf := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
if intf == "" {
......
......@@ -8,9 +8,11 @@ import (
// Authenticator
type Authenticator interface {
// Sign
// give a sign to request
Sign(protocol.Invocation, *common.URL) error
// Authenticate
// verify the signature of the request is valid or not
Authenticate(protocol.Invocation, *common.URL) error
}
......@@ -13,6 +13,7 @@ import (
type DefaultAccesskeyStorage struct {
}
// GetAccessKeyPair
// get AccessKeyPair from url by the key "accessKeyId" and "secretAccessKey"
func (storage *DefaultAccesskeyStorage) GetAccessKeyPair(invocation protocol.Invocation, url *common.URL) *filter.AccessKeyPair {
return &filter.AccessKeyPair{
......
......@@ -25,6 +25,8 @@ func init() {
type DefaultAuthenticator struct {
}
// Sign
// add the signature for the invocation
func (authenticator *DefaultAuthenticator) Sign(invocation protocol.Invocation, url *common.URL) error {
currentTimeMillis := strconv.Itoa(int(time.Now().Unix() * 1000))
......@@ -45,6 +47,8 @@ func (authenticator *DefaultAuthenticator) Sign(invocation protocol.Invocation,
return nil
}
// getSignature
// get signature by the metadata and params of the invocation
func getSignature(url *common.URL, invocation protocol.Invocation, secrectKey string, currentTime string) (string, error) {
requestString := fmt.Sprintf(constant.SIGNATURE_STRING_FORMAT,
......@@ -63,6 +67,8 @@ func getSignature(url *common.URL, invocation protocol.Invocation, secrectKey st
return signature, nil
}
// Authenticate
// This method verifies whether the signature sent by the requester is correct
func (authenticator *DefaultAuthenticator) Authenticate(invocation protocol.Invocation, url *common.URL) error {
accessKeyId := invocation.AttachmentsByKey(constant.AK_KEY, "")
......
......@@ -9,6 +9,7 @@ import (
"strings"
)
// Sign
// get a signature string with given information, such as metadata or parameters
func Sign(metadata, key string) string {
return doSign([]byte(metadata), key)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment