Move TO tocookie out of experimental

Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/96edf7df
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/96edf7df
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/96edf7df

Branch: refs/heads/master
Commit: 96edf7dfb239479a55b58356a9c497647e4f4bd8
Parents: b5fa231
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Fri Jul 21 18:16:56 2017 -0600
Committer: Dewayne Richardson <dewr...@apache.org>
Committed: Thu Aug 10 09:46:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/experimental/tocookie/tocookie.go | 103 ---------------------
 traffic_ops/tocookie/tocookie.go              | 103 +++++++++++++++++++++
 traffic_ops/traffic_ops_golang/wrappers.go    |   2 +-
 3 files changed, 104 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/96edf7df/traffic_ops/experimental/tocookie/tocookie.go
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/tocookie/tocookie.go 
b/traffic_ops/experimental/tocookie/tocookie.go
deleted file mode 100644
index 658224d..0000000
--- a/traffic_ops/experimental/tocookie/tocookie.go
+++ /dev/null
@@ -1,103 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-
-// http://www.apache.org/licenses/LICENSE-2.0
-
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package tocookie
-
-import (
-       "crypto/hmac"
-       "crypto/sha1"
-       "encoding/base64"
-       "encoding/hex"
-       "encoding/json"
-       "fmt"
-       "strings"
-       "time"
-)
-
-const Name = "mojolicious"
-const DefaultDuration = time.Hour
-
-type Cookie struct {
-       AuthData    string `json:"auth_data"`
-       ExpiresUnix int64  `json:"expires"`
-}
-
-func checkHmac(message, messageMAC, key []byte) bool {
-       mac := hmac.New(sha1.New, key)
-       mac.Write(message)
-       expectedMAC := mac.Sum(nil)
-       return hmac.Equal(messageMAC, expectedMAC)
-}
-
-func Parse(secret, cookie string) (*Cookie, error) {
-       dashPos := strings.Index(cookie, "-")
-       if dashPos == -1 {
-               return nil, fmt.Errorf("malformed cookie '%s' - no dashes", 
cookie)
-       }
-
-       lastDashPos := strings.LastIndex(cookie, "-")
-       if lastDashPos == -1 {
-               return nil, fmt.Errorf("malformed cookie '%s' - no dashes", 
cookie)
-       }
-
-       if len(cookie) < lastDashPos+1 {
-               return nil, fmt.Errorf("malformed cookie '%s' -- no signature", 
cookie)
-       }
-
-       base64Txt := cookie[:dashPos]
-       txtBytes, err := base64.RawURLEncoding.DecodeString(base64Txt)
-       if err != nil {
-               return nil, fmt.Errorf("error decoding base64 data: %v", err)
-       }
-       base64TxtSig := cookie[:lastDashPos-1] // the signature signs the 
base64 including trailing hyphens, but the Go base64 decoder doesn't want the 
trailing hyphens.
-
-       base64Sig := cookie[lastDashPos+1:]
-       sigBytes, err := hex.DecodeString(base64Sig)
-       if err != nil {
-               return nil, fmt.Errorf("error decoding signature: %v", err)
-       }
-
-       if !checkHmac([]byte(base64TxtSig), sigBytes, []byte(secret)) {
-               return nil, fmt.Errorf("bad signature")
-       }
-
-       cookieData := Cookie{}
-       if err := json.Unmarshal(txtBytes, &cookieData); err != nil {
-               return nil, fmt.Errorf("error decoding base64 text '%s' to 
JSON: %v", string(txtBytes), err)
-       }
-
-       if cookieData.ExpiresUnix-time.Now().Unix() < 0 {
-               return nil, fmt.Errorf("signature expired")
-       }
-
-       return &cookieData, nil
-}
-
-func NewRawMsg(msg, key []byte) string {
-       base64Msg := base64.RawURLEncoding.WithPadding('-').EncodeToString(msg)
-       mac := hmac.New(sha1.New, []byte(key))
-       mac.Write([]byte(base64Msg))
-       encMac := mac.Sum(nil)
-       base64Sig := hex.EncodeToString(encMac)
-       return base64Msg + "--" + base64Sig
-}
-
-func New(user string, expiration time.Time, key string) string {
-       cookieMsg := Cookie{AuthData: user, ExpiresUnix: expiration.Unix()}
-       msg, _ := json.Marshal(cookieMsg)
-       return NewRawMsg(msg, []byte(key))
-}
-
-// Update takes an existing cookie and returns a new serialized cookie with an 
updated expiration
-func Refresh(c *Cookie, key string) string {
-       return New(c.AuthData, time.Now().Add(DefaultDuration), key)
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/96edf7df/traffic_ops/tocookie/tocookie.go
----------------------------------------------------------------------
diff --git a/traffic_ops/tocookie/tocookie.go b/traffic_ops/tocookie/tocookie.go
new file mode 100644
index 0000000..658224d
--- /dev/null
+++ b/traffic_ops/tocookie/tocookie.go
@@ -0,0 +1,103 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package tocookie
+
+import (
+       "crypto/hmac"
+       "crypto/sha1"
+       "encoding/base64"
+       "encoding/hex"
+       "encoding/json"
+       "fmt"
+       "strings"
+       "time"
+)
+
+const Name = "mojolicious"
+const DefaultDuration = time.Hour
+
+type Cookie struct {
+       AuthData    string `json:"auth_data"`
+       ExpiresUnix int64  `json:"expires"`
+}
+
+func checkHmac(message, messageMAC, key []byte) bool {
+       mac := hmac.New(sha1.New, key)
+       mac.Write(message)
+       expectedMAC := mac.Sum(nil)
+       return hmac.Equal(messageMAC, expectedMAC)
+}
+
+func Parse(secret, cookie string) (*Cookie, error) {
+       dashPos := strings.Index(cookie, "-")
+       if dashPos == -1 {
+               return nil, fmt.Errorf("malformed cookie '%s' - no dashes", 
cookie)
+       }
+
+       lastDashPos := strings.LastIndex(cookie, "-")
+       if lastDashPos == -1 {
+               return nil, fmt.Errorf("malformed cookie '%s' - no dashes", 
cookie)
+       }
+
+       if len(cookie) < lastDashPos+1 {
+               return nil, fmt.Errorf("malformed cookie '%s' -- no signature", 
cookie)
+       }
+
+       base64Txt := cookie[:dashPos]
+       txtBytes, err := base64.RawURLEncoding.DecodeString(base64Txt)
+       if err != nil {
+               return nil, fmt.Errorf("error decoding base64 data: %v", err)
+       }
+       base64TxtSig := cookie[:lastDashPos-1] // the signature signs the 
base64 including trailing hyphens, but the Go base64 decoder doesn't want the 
trailing hyphens.
+
+       base64Sig := cookie[lastDashPos+1:]
+       sigBytes, err := hex.DecodeString(base64Sig)
+       if err != nil {
+               return nil, fmt.Errorf("error decoding signature: %v", err)
+       }
+
+       if !checkHmac([]byte(base64TxtSig), sigBytes, []byte(secret)) {
+               return nil, fmt.Errorf("bad signature")
+       }
+
+       cookieData := Cookie{}
+       if err := json.Unmarshal(txtBytes, &cookieData); err != nil {
+               return nil, fmt.Errorf("error decoding base64 text '%s' to 
JSON: %v", string(txtBytes), err)
+       }
+
+       if cookieData.ExpiresUnix-time.Now().Unix() < 0 {
+               return nil, fmt.Errorf("signature expired")
+       }
+
+       return &cookieData, nil
+}
+
+func NewRawMsg(msg, key []byte) string {
+       base64Msg := base64.RawURLEncoding.WithPadding('-').EncodeToString(msg)
+       mac := hmac.New(sha1.New, []byte(key))
+       mac.Write([]byte(base64Msg))
+       encMac := mac.Sum(nil)
+       base64Sig := hex.EncodeToString(encMac)
+       return base64Msg + "--" + base64Sig
+}
+
+func New(user string, expiration time.Time, key string) string {
+       cookieMsg := Cookie{AuthData: user, ExpiresUnix: expiration.Unix()}
+       msg, _ := json.Marshal(cookieMsg)
+       return NewRawMsg(msg, []byte(key))
+}
+
+// Update takes an existing cookie and returns a new serialized cookie with an 
updated expiration
+func Refresh(c *Cookie, key string) string {
+       return New(c.AuthData, time.Now().Add(DefaultDuration), key)
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/96edf7df/traffic_ops/traffic_ops_golang/wrappers.go
----------------------------------------------------------------------
diff --git a/traffic_ops/traffic_ops_golang/wrappers.go 
b/traffic_ops/traffic_ops_golang/wrappers.go
index 30c36b4..c6eb8cf 100644
--- a/traffic_ops/traffic_ops_golang/wrappers.go
+++ b/traffic_ops/traffic_ops_golang/wrappers.go
@@ -23,7 +23,7 @@ import (
        "database/sql"
        "fmt"
        
"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/common/log"
-       
"github.com/apache/incubator-trafficcontrol/traffic_ops/experimental/tocookie"
+       "github.com/apache/incubator-trafficcontrol/traffic_ops/tocookie"
        "net/http"
        "time"
 )

Reply via email to