From e652b2a38950b5150b6a58294415653020744452 Mon Sep 17 00:00:00 2001 From: Ooo0oO0o0oO <907709476@qq.com> Date: Tue, 4 Feb 2020 23:13:45 +0800 Subject: [PATCH] add some comments --- common/url.go | 2 ++ filter/authenticator.go | 2 ++ filter/filter_impl/auth/accesskey_storage.go | 1 + filter/filter_impl/auth/default_authenticator.go | 6 ++++++ filter/filter_impl/auth/sign_util.go | 1 + 5 files changed, 12 insertions(+) diff --git a/common/url.go b/common/url.go index 64a5930c6..b2a514b4e 100644 --- a/common/url.go +++ b/common/url.go @@ -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 == "" { diff --git a/filter/authenticator.go b/filter/authenticator.go index f969769bc..ce0547b36 100644 --- a/filter/authenticator.go +++ b/filter/authenticator.go @@ -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 } diff --git a/filter/filter_impl/auth/accesskey_storage.go b/filter/filter_impl/auth/accesskey_storage.go index 4495c9cc4..0a2bf47cb 100644 --- a/filter/filter_impl/auth/accesskey_storage.go +++ b/filter/filter_impl/auth/accesskey_storage.go @@ -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{ diff --git a/filter/filter_impl/auth/default_authenticator.go b/filter/filter_impl/auth/default_authenticator.go index 20c3b64b1..73eb9cddc 100644 --- a/filter/filter_impl/auth/default_authenticator.go +++ b/filter/filter_impl/auth/default_authenticator.go @@ -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, "") diff --git a/filter/filter_impl/auth/sign_util.go b/filter/filter_impl/auth/sign_util.go index 938731491..60698439c 100644 --- a/filter/filter_impl/auth/sign_util.go +++ b/filter/filter_impl/auth/sign_util.go @@ -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) -- GitLab