@@ -3,8 +3,8 @@ package jamfprointegration
33import (
44 "fmt"
55 "net/http"
6- "time"
76 "strings"
7+ "time"
88)
99
1010// GetSessionCookies retrieves all cookies from the current session
@@ -26,7 +26,6 @@ func (j *Integration) GetLoadBalancer(urlString string) (string, error) {
2626 }
2727
2828 chosenCookie := chooseMostAlphabeticalString (* allBalancers )
29- // chosenCookie = "9a794a6f22fea3b1"
3029 j .Sugar .Debugf ("Chosen Cookie:%v " , chosenCookie )
3130 return chosenCookie , nil
3231}
@@ -49,8 +48,7 @@ func chooseMostAlphabeticalString(strings []string) string {
4948
5049// TODO migrate strings
5150func (j * Integration ) getAllLoadBalancers (urlString string ) (* []string , error ) {
52- // j.Sugar.Debug("LOGHERE1")
53- j .Sugar .Debug ("Starting cookie magic (has this propogated?)" )
51+ j .Sugar .Debug ("Starting load balancer workaround" )
5452 var outList []string
5553 var err error
5654 var req * http.Request
@@ -59,12 +57,9 @@ func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) {
5957
6058 iterations = 0
6159 startTimeEpoch := time .Now ().Unix ()
62- // j.Sugar.Debugf("Start time: %d", startTimeEpoch)
6360 endTimeEpoch := startTimeEpoch + int64 (LoadBalancerTimeOut .Seconds ())
64- // j.Sugar.Debugf("End Time: %d", endTimeEpoch)
6561
6662 for i := time .Now ().Unix (); i < endTimeEpoch ; {
67- // j.Sugar.Debugf("################Iterations:%v####################", iterations)
6863 req , err = http .NewRequest ("GET" , urlString , nil )
6964 if err != nil {
7065 return nil , fmt .Errorf ("error creating request: %v" , err )
@@ -82,34 +77,28 @@ func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) {
8277 }
8378
8479 respCookies := resp .Cookies ()
85- // j.Sugar.Debugf("Cookies got: %+v", respCookies)
8680
8781 for _ , v := range respCookies {
8882 if v .Name == LoadBalancerTargetCookie {
8983 strippedCookie := strings .TrimSpace (v .Value )
90- // j.Sugar.Debugf("Removing Whitespace. Before #%v# After #%v#", v.Value, strippedCookie)
91- // j.Sugar.Debugf("Appending: %v", strippedCookie)
9284 outList = append (outList , strippedCookie )
9385 }
9486 }
95- // j.Sugar.Debugf("BEGIN DUPE REMOVAL. OUTLIST: %v", outList)
96-
87+
9788 uniqueMap := make (map [string ]bool )
98-
89+
9990 for _ , str := range outList {
10091 uniqueMap [str ] = true
10192 }
102-
93+
10394 cookieDupesRemoved := make ([]string , 0 , len (uniqueMap ))
104-
95+
10596 for str := range uniqueMap {
10697 cookieDupesRemoved = append (cookieDupesRemoved , str )
10798 }
10899
109-
110- // j.Sugar.Debugf("DUPES REMOVED: %v", cookieDupesRemoved)
111- if len (cookieDupesRemoved ) > 1 {
112- j .Sugar .Debugf ("### COMPLETED COOKIE MAGIC ### Dupes removed: %v, outlist: %v" , cookieDupesRemoved , outList )
100+ if len (cookieDupesRemoved ) > 1 {
101+ j .Sugar .Debugf ("### COMPLETED LOADBALANCER WORKAROUND ### Dupes removed: %v, outlist: %v" , cookieDupesRemoved , outList )
113102 break
114103 }
115104
0 commit comments