This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 8fe363309e3cf7f23f88b202e680fffa053b1b9b
Author: Dewayne Richardson <dewr...@apache.org>
AuthorDate: Mon Mar 5 11:38:30 2018 -0700

    added new session wrapper to allow for /login and /logout (session 
switching)
---
 traffic_ops/testing/api/v13/session.go | 61 ++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/traffic_ops/testing/api/v13/session.go 
b/traffic_ops/testing/api/v13/session.go
new file mode 100644
index 0000000..b3c6085
--- /dev/null
+++ b/traffic_ops/testing/api/v13/session.go
@@ -0,0 +1,61 @@
+package v13
+
+/*
+
+   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.
+*/
+
+import (
+       "time"
+
+       "github.com/apache/incubator-trafficcontrol/traffic_ops/client/v13"
+       _ "github.com/lib/pq"
+)
+
+var (
+       TOSession *v13.Session
+)
+
+func SetupSession(toReqTimeout time.Duration, toURL string, toUser string, 
toPass string) error {
+       var err error
+
+       toReqTimeout = time.Second * 
time.Duration(Config.Default.Session.TimeoutInSecs)
+       TOSession, _, err = v13.LoginWithAgent(toURL, toUser, toPass, true, 
"to-api-v13-client-tests", true, toReqTimeout)
+       if err != nil {
+               return err
+       }
+       return err
+}
+
+func TeardownSession(toReqTimeout time.Duration, toURL string, toUser string, 
toPass string) error {
+       var err error
+       toReqTimeout = time.Second * 
time.Duration(Config.Default.Session.TimeoutInSecs)
+       TOSession, _, err = v13.LogoutWithAgent(toURL, toUser, toPass, true, 
"to-api-v13-client-tests", true, toReqTimeout)
+       if err != nil {
+               return err
+       }
+
+       return err
+}
+
+func SwitchSession(toReqTimeout time.Duration, toURL string, toOldUser string, 
toOldPass string, toNewUser string, toNewPass string) error {
+       err := TeardownSession(toReqTimeout, toURL, toOldUser, toOldPass)
+       if err != nil {
+               return err
+       }
+       err = SetupSession(toReqTimeout, toURL, toNewUser, toNewPass)
+       if err != nil {
+               return err
+       }
+       return err
+}

-- 
To stop receiving notification emails like this one, please contact
dang...@apache.org.

Reply via email to