From 99e94ed2ec2dddf63b8f06d32e4206687f140c60 Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 28 Feb 2025 13:07:26 +0000 Subject: [PATCH 1/6] Removed http executer rubbish --- jamf/jamfprointegration/auth_basic.go | 5 ++-- jamf/jamfprointegration/auth_oauth.go | 5 ++-- jamf/jamfprointegration/builders.go | 22 +++++++++--------- jamf/jamfprointegration/interfaces.go | 3 +-- .../load_balancer_workaround.go | 2 +- jamf/jamfprointegration/marshall_test.go | 6 ++--- jamf/jamfprointegration/test/builders_test.go | 23 +++++++++---------- jamf/jamfprointegration/test/helpers.go | 3 +-- 8 files changed, 32 insertions(+), 37 deletions(-) diff --git a/jamf/jamfprointegration/auth_basic.go b/jamf/jamfprointegration/auth_basic.go index 7b3ddf3..f459020 100644 --- a/jamf/jamfprointegration/auth_basic.go +++ b/jamf/jamfprointegration/auth_basic.go @@ -6,7 +6,6 @@ import ( "net/http" "time" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) @@ -20,7 +19,7 @@ type basicAuth struct { hideSensitiveData bool bearerToken string bearerTokenExpiryTime time.Time - httpExecutor httpclient.HTTPExecutor + http http.Client } // basicAuthResponse serves as a json structure map for the basicAuth response from Jamf. @@ -58,7 +57,7 @@ func (a *basicAuth) getNewToken() error { req.SetBasicAuth(a.username, a.password) - resp, err := a.httpExecutor.Do(req) + resp, err := a.http.Do(req) if err != nil { return err } diff --git a/jamf/jamfprointegration/auth_oauth.go b/jamf/jamfprointegration/auth_oauth.go index ee62ab6..f11cadc 100644 --- a/jamf/jamfprointegration/auth_oauth.go +++ b/jamf/jamfprointegration/auth_oauth.go @@ -10,7 +10,6 @@ import ( "strings" "time" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) @@ -24,7 +23,7 @@ type oauth struct { hideSensitiveData bool expiryTime time.Time token string - httpExecutor httpclient.HTTPExecutor + http http.Client } // OAuthResponse represents the response structure when obtaining an OAuth access token from JamfPro. @@ -56,7 +55,7 @@ func (a *oauth) getNewToken() error { req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - resp, err := a.httpExecutor.Do(req) + resp, err := a.http.Do(req) if err != nil { return err } diff --git a/jamf/jamfprointegration/builders.go b/jamf/jamfprointegration/builders.go index ca9d362..a08ead2 100644 --- a/jamf/jamfprointegration/builders.go +++ b/jamf/jamfprointegration/builders.go @@ -1,45 +1,45 @@ package jamfprointegration import ( + "net/http" "time" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) // BuildWithOAuth is a helper function allowing the full construct of a Jamf Integration using OAuth2 -func BuildWithOAuth(jamfProFQDN string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, clientId string, clientSecret string, hideSensitiveData bool, executor httpclient.HTTPExecutor) (*Integration, error) { +func BuildWithOAuth(jamfProFQDN string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, clientId string, clientSecret string, hideSensitiveData bool, client http.Client) (*Integration, error) { integration := Integration{ JamfProFQDN: jamfProFQDN, Sugar: Sugar, AuthMethodDescriptor: "oauth2", - httpExecutor: executor, + http: client, } - integration.BuildOAuth(clientId, clientSecret, bufferPeriod, hideSensitiveData, executor) + integration.BuildOAuth(clientId, clientSecret, bufferPeriod, hideSensitiveData, client) err := integration.CheckRefreshToken() return &integration, err } // BuildWithBasicAuth is a helper function allowing the full construct of a Jamf Integration using BasicAuth -func BuildWithBasicAuth(jamfProFQDN string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, username string, password string, hideSensitiveData bool, executor httpclient.HTTPExecutor) (*Integration, error) { +func BuildWithBasicAuth(jamfProFQDN string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, username string, password string, hideSensitiveData bool, client http.Client) (*Integration, error) { integration := Integration{ JamfProFQDN: jamfProFQDN, Sugar: Sugar, AuthMethodDescriptor: "basic", - httpExecutor: executor, + http: client, } - integration.BuildBasicAuth(username, password, bufferPeriod, hideSensitiveData, executor) + integration.BuildBasicAuth(username, password, bufferPeriod, hideSensitiveData, client) err := integration.CheckRefreshToken() return &integration, err } // BuildOAuth is a helper which returns just a configured OAuth interface -func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPeriod time.Duration, hideSensitiveData bool, executor httpclient.HTTPExecutor) { +func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPeriod time.Duration, hideSensitiveData bool, client http.Client) { authInterface := oauth{ clientId: clientId, clientSecret: clientSecret, @@ -47,14 +47,14 @@ func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPer baseDomain: j.JamfProFQDN, Sugar: j.Sugar, hideSensitiveData: hideSensitiveData, - httpExecutor: executor, + http: client, } j.auth = &authInterface } // BuildBasicAuth is a helper which returns just a configured Basic Auth interface/ -func (j *Integration) BuildBasicAuth(username string, password string, bufferPeriod time.Duration, hideSensitiveData bool, executor httpclient.HTTPExecutor) { +func (j *Integration) BuildBasicAuth(username string, password string, bufferPeriod time.Duration, hideSensitiveData bool, client http.Client) { authInterface := basicAuth{ username: username, password: password, @@ -62,7 +62,7 @@ func (j *Integration) BuildBasicAuth(username string, password string, bufferPer Sugar: j.Sugar, baseDomain: j.JamfProFQDN, hideSensitiveData: hideSensitiveData, - httpExecutor: executor, + http: client, } j.auth = &authInterface diff --git a/jamf/jamfprointegration/interfaces.go b/jamf/jamfprointegration/interfaces.go index aeb49d4..c17550d 100644 --- a/jamf/jamfprointegration/interfaces.go +++ b/jamf/jamfprointegration/interfaces.go @@ -3,7 +3,6 @@ package jamfprointegration import ( "net/http" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) @@ -13,7 +12,7 @@ type Integration struct { AuthMethodDescriptor string Sugar *zap.SugaredLogger auth authInterface - httpExecutor httpclient.HTTPExecutor + http http.Client } // getFQDN returns just the FQDN // TODO remove the "get" diff --git a/jamf/jamfprointegration/load_balancer_workaround.go b/jamf/jamfprointegration/load_balancer_workaround.go index 8ad05bf..5b9a509 100644 --- a/jamf/jamfprointegration/load_balancer_workaround.go +++ b/jamf/jamfprointegration/load_balancer_workaround.go @@ -62,7 +62,7 @@ func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) { return nil, fmt.Errorf("error populating auth: %v", err) } - resp, err = j.httpExecutor.Do(req) + resp, err = j.http.Do(req) if err != nil { return nil, fmt.Errorf("error sending req: %v", err) } diff --git a/jamf/jamfprointegration/marshall_test.go b/jamf/jamfprointegration/marshall_test.go index 394a68e..0cbaac2 100644 --- a/jamf/jamfprointegration/marshall_test.go +++ b/jamf/jamfprointegration/marshall_test.go @@ -1,10 +1,10 @@ package jamfprointegration import ( + "net/http" "reflect" "testing" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) @@ -14,7 +14,7 @@ func TestIntegration_marshalRequest(t *testing.T) { AuthMethodDescriptor string Sugar *zap.SugaredLogger auth authInterface - httpExecutor httpclient.HTTPExecutor + http http.Client } type args struct { body interface{} @@ -37,7 +37,7 @@ func TestIntegration_marshalRequest(t *testing.T) { AuthMethodDescriptor: tt.fields.AuthMethodDescriptor, Sugar: tt.fields.Sugar, auth: tt.fields.auth, - httpExecutor: tt.fields.httpExecutor, + http: tt.fields.http, } got, err := j.marshalRequest(tt.args.body, tt.args.method, tt.args.endpoint) if (err != nil) != tt.wantErr { diff --git a/jamf/jamfprointegration/test/builders_test.go b/jamf/jamfprointegration/test/builders_test.go index 3066d08..697a8f5 100644 --- a/jamf/jamfprointegration/test/builders_test.go +++ b/jamf/jamfprointegration/test/builders_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/deploymenttheory/go-api-http-client-integrations/jamf/jamfprointegration" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) @@ -23,7 +22,7 @@ func Test_BuildWithOAuth(t *testing.T) { clientId string clientSecret string hideSensitiveData bool - executor httpclient.HTTPExecutor + http http.Client } tests := []struct { name string @@ -39,7 +38,7 @@ func Test_BuildWithOAuth(t *testing.T) { clientSecret: os.Getenv(ENV_KEY_CLIENT_SECRET), bufferPeriod: 10 * time.Second, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + http: http.Client{}, Sugar: logger, }, wantErr: false, @@ -52,7 +51,7 @@ func Test_BuildWithOAuth(t *testing.T) { clientSecret: os.Getenv(ENV_KEY_CLIENT_SECRET), bufferPeriod: 10 * time.Minute, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + http: http.Client{}, Sugar: logger, }, wantErr: true, @@ -65,7 +64,7 @@ func Test_BuildWithOAuth(t *testing.T) { clientSecret: os.Getenv(ENV_KEY_CLIENT_SECRET), bufferPeriod: 10 * time.Minute, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + http: http.Client{}, Sugar: logger, }, wantErr: true, @@ -78,7 +77,7 @@ func Test_BuildWithOAuth(t *testing.T) { clientSecret: "", bufferPeriod: 10 * time.Minute, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + http: http.Client{}, Sugar: logger, }, wantErr: true, @@ -86,7 +85,7 @@ func Test_BuildWithOAuth(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := jamfprointegration.BuildWithOAuth(tt.args.jamfProFQDN, tt.args.Sugar, tt.args.bufferPeriod, tt.args.clientId, tt.args.clientSecret, tt.args.hideSensitiveData, tt.args.executor) + _, err := jamfprointegration.BuildWithOAuth(tt.args.jamfProFQDN, tt.args.Sugar, tt.args.bufferPeriod, tt.args.clientId, tt.args.clientSecret, tt.args.hideSensitiveData, tt.args.http) if (err != nil) != tt.wantErr { t.Errorf("BuildWithOAuth() error = %v, wantErr %v", err, tt.wantErr) return @@ -105,7 +104,7 @@ func TestBuildWithBasicAuth(t *testing.T) { username string password string hideSensitiveData bool - executor httpclient.HTTPExecutor + executor http.Client } tests := []struct { name string @@ -121,7 +120,7 @@ func TestBuildWithBasicAuth(t *testing.T) { password: os.Getenv(ENV_KEY_PASSWORD), bufferPeriod: 10 * time.Second, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + executor: http.Client{}, Sugar: logger, }, wantErr: false, @@ -134,7 +133,7 @@ func TestBuildWithBasicAuth(t *testing.T) { password: os.Getenv(ENV_KEY_PASSWORD), bufferPeriod: 100 * time.Minute, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + executor: http.Client{}, Sugar: logger, }, wantErr: true, @@ -147,7 +146,7 @@ func TestBuildWithBasicAuth(t *testing.T) { password: os.Getenv(ENV_KEY_PASSWORD), bufferPeriod: 100 * time.Minute, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + executor: http.Client{}, Sugar: logger, }, wantErr: true, @@ -160,7 +159,7 @@ func TestBuildWithBasicAuth(t *testing.T) { password: "", bufferPeriod: 100 * time.Minute, hideSensitiveData: true, - executor: &httpclient.ProdExecutor{Client: &http.Client{}}, + executor: http.Client{}, Sugar: logger, }, wantErr: true, diff --git a/jamf/jamfprointegration/test/helpers.go b/jamf/jamfprointegration/test/helpers.go index d98947f..efd0067 100644 --- a/jamf/jamfprointegration/test/helpers.go +++ b/jamf/jamfprointegration/test/helpers.go @@ -6,7 +6,6 @@ import ( "time" "github.com/deploymenttheory/go-api-http-client-integrations/jamf/jamfprointegration" - "github.com/deploymenttheory/go-api-http-client/httpclient" "go.uber.org/zap" ) @@ -31,7 +30,7 @@ func NewIntegrationFromEnv() *jamfprointegration.Integration { os.Getenv(ENV_KEY_CLIENT_ID), os.Getenv(ENV_KEY_CLIENT_SECRET), false, - &httpclient.ProdExecutor{Client: &http.Client{}}, + http.Client{}, ) if err != nil { From c5207b9d7a09b3c8680cbe57fb16cf734c7b35b1 Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 28 Feb 2025 13:08:14 +0000 Subject: [PATCH 2/6] shut up mod --- go.mod | 12 ++---------- go.sum | 41 ----------------------------------------- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/go.mod b/go.mod index 295a53c..9e6b6ff 100644 --- a/go.mod +++ b/go.mod @@ -2,17 +2,9 @@ module github.com/deploymenttheory/go-api-http-client-integrations go 1.22.4 -require ( - github.com/deploymenttheory/go-api-http-client v0.2.11 - go.uber.org/zap v1.27.0 -) +require go.uber.org/zap v1.27.0 require ( - github.com/antchfx/xmlquery v1.4.1 // indirect - github.com/antchfx/xpath v1.3.1 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/google/uuid v1.6.0 // indirect + github.com/stretchr/testify v1.9.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/text v0.16.0 // indirect ) diff --git a/go.sum b/go.sum index 17ab9e0..bde6d89 100644 --- a/go.sum +++ b/go.sum @@ -1,55 +1,14 @@ -github.com/antchfx/xmlquery v1.4.1 h1:YgpSwbeWvLp557YFTi8E3z6t6/hYjmFEtiEKbDfEbl0= -github.com/antchfx/xmlquery v1.4.1/go.mod h1:lKezcT8ELGt8kW5L+ckFMTbgdR61/odpPgDv8Gvi1fI= -github.com/antchfx/xpath v1.3.1 h1:PNbFuUqHwWl0xRjvUPjJ95Agbmdj2uzzIwmQKgu4oCk= -github.com/antchfx/xpath v1.3.1/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deploymenttheory/go-api-http-client v0.2.11 h1:hEVxXX60cUxRqKkJBHADC/S91+iCPYdBIwkT6stexTY= -github.com/deploymenttheory/go-api-http-client v0.2.11/go.mod h1:LKDnBcieS6CyikZjTKPpziVdxnTwzBHE6Hx1cuWRcuU= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From bf11d7f1dbae438eb8a0a6e82f30017a84999e7a Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 3 Mar 2025 11:13:16 +0000 Subject: [PATCH 3/6] re-adding loadbalancer jammy --- .../load_balancer_workaround.go | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/jamf/jamfprointegration/load_balancer_workaround.go b/jamf/jamfprointegration/load_balancer_workaround.go index 5b9a509..5367019 100644 --- a/jamf/jamfprointegration/load_balancer_workaround.go +++ b/jamf/jamfprointegration/load_balancer_workaround.go @@ -3,7 +3,8 @@ package jamfprointegration import ( "fmt" "net/http" - "slices" + "time" + "strings" ) // GetSessionCookies retrieves all cookies from the current session @@ -25,6 +26,8 @@ func (j *Integration) GetLoadBalancer(urlString string) (string, error) { } chosenCookie := chooseMostAlphabeticalString(*allBalancers) + // chosenCookie = "9a794a6f22fea3b1" + j.Sugar.Debugf("Chosen Cookie:%v ", chosenCookie) return chosenCookie, nil } @@ -46,39 +49,73 @@ func chooseMostAlphabeticalString(strings []string) string { // TODO migrate strings func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) { + // j.Sugar.Debug("LOGHERE1") + j.Sugar.Debug("Starting cookie magic (has this propogated?)") var outList []string var err error var req *http.Request var resp *http.Response + var iterations int - for i := 0; i < LoadBalancerPollCount; i++ { + iterations = 0 + startTimeEpoch := time.Now().Unix() + // j.Sugar.Debugf("Start time: %d", startTimeEpoch) + endTimeEpoch := startTimeEpoch + int64(LoadBalancerTimeOut.Seconds()) + // j.Sugar.Debugf("End Time: %d", endTimeEpoch) + + for i := time.Now().Unix(); i < endTimeEpoch; { + // j.Sugar.Debugf("################Iterations:%v####################", iterations) req, err = http.NewRequest("GET", urlString, nil) if err != nil { return nil, fmt.Errorf("error creating request: %v", err) } + // Auth required on login screen or 404 err = j.PrepRequestParamsAndAuth(req) if err != nil { return nil, fmt.Errorf("error populating auth: %v", err) } - resp, err = j.http.Do(req) + resp, err = j.httpExecutor.Do(req) if err != nil { return nil, fmt.Errorf("error sending req: %v", err) } respCookies := resp.Cookies() + // j.Sugar.Debugf("Cookies got: %+v", respCookies) for _, v := range respCookies { if v.Name == LoadBalancerTargetCookie { - outList = append(outList, v.Value) + strippedCookie := strings.TrimSpace(v.Value) + // j.Sugar.Debugf("Removing Whitespace. Before #%v# After #%v#", v.Value, strippedCookie) + // j.Sugar.Debugf("Appending: %v", strippedCookie) + outList = append(outList, strippedCookie) } } + // j.Sugar.Debugf("BEGIN DUPE REMOVAL. OUTLIST: %v", outList) + + uniqueMap := make(map[string]bool) + + for _, str := range outList { + uniqueMap[str] = true + } + + cookieDupesRemoved := make([]string, 0, len(uniqueMap)) + + for str := range uniqueMap { + cookieDupesRemoved = append(cookieDupesRemoved, str) + } - } - slices.Sort(outList) - newList := slices.Compact(outList) - return &newList, nil + // j.Sugar.Debugf("DUPES REMOVED: %v", cookieDupesRemoved) + if len(cookieDupesRemoved) > 1 { + j.Sugar.Debugf("### COMPLETED COOKIE MAGIC ### Dupes removed: %v, outlist: %v", cookieDupesRemoved, outList) + break + } + + i = time.Now().Unix() + iterations += 1 + } + return &outList, nil } From fd8f48cad0db5c9db64648f5e4f9715999edc904 Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 3 Mar 2025 11:25:26 +0000 Subject: [PATCH 4/6] update constants --- jamf/jamfprointegration/constants.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jamf/jamfprointegration/constants.go b/jamf/jamfprointegration/constants.go index 7051720..46e86bb 100644 --- a/jamf/jamfprointegration/constants.go +++ b/jamf/jamfprointegration/constants.go @@ -1,5 +1,7 @@ package jamfprointegration +import "time" + // Endpoint constants represent the URL suffixes used for Jamf API token interactions. const ( // Auth @@ -11,4 +13,6 @@ const ( // Load balancer workaround LoadBalancerTargetCookie string = "jpro-ingress" LoadBalancerPollCount int = 5 + LoadBalancerTimeOut time.Duration = 7 * time.Second + ) From 5013bf3d41c0631ddd677d63ecb23a7a7cd0c013 Mon Sep 17 00:00:00 2001 From: bobby williams Date: Mon, 3 Mar 2025 14:22:11 +0000 Subject: [PATCH 5/6] fixed executor bug --- jamf/jamfprointegration/load_balancer_workaround.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jamf/jamfprointegration/load_balancer_workaround.go b/jamf/jamfprointegration/load_balancer_workaround.go index 5367019..e7ab8d2 100644 --- a/jamf/jamfprointegration/load_balancer_workaround.go +++ b/jamf/jamfprointegration/load_balancer_workaround.go @@ -76,7 +76,7 @@ func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) { return nil, fmt.Errorf("error populating auth: %v", err) } - resp, err = j.httpExecutor.Do(req) + resp, err = j.http.Do(req) if err != nil { return nil, fmt.Errorf("error sending req: %v", err) } From a2fb46a18950d9fb2e1985a787cc98bb3c3efda9 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 4 Mar 2025 13:43:24 +0000 Subject: [PATCH 6/6] Tidied up debugs --- .../load_balancer_workaround.go | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/jamf/jamfprointegration/load_balancer_workaround.go b/jamf/jamfprointegration/load_balancer_workaround.go index e7ab8d2..ceab794 100644 --- a/jamf/jamfprointegration/load_balancer_workaround.go +++ b/jamf/jamfprointegration/load_balancer_workaround.go @@ -3,8 +3,8 @@ package jamfprointegration import ( "fmt" "net/http" - "time" "strings" + "time" ) // GetSessionCookies retrieves all cookies from the current session @@ -26,7 +26,6 @@ func (j *Integration) GetLoadBalancer(urlString string) (string, error) { } chosenCookie := chooseMostAlphabeticalString(*allBalancers) - // chosenCookie = "9a794a6f22fea3b1" j.Sugar.Debugf("Chosen Cookie:%v ", chosenCookie) return chosenCookie, nil } @@ -49,8 +48,7 @@ func chooseMostAlphabeticalString(strings []string) string { // TODO migrate strings func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) { - // j.Sugar.Debug("LOGHERE1") - j.Sugar.Debug("Starting cookie magic (has this propogated?)") + j.Sugar.Debug("Starting load balancer workaround") var outList []string var err error var req *http.Request @@ -59,12 +57,9 @@ func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) { iterations = 0 startTimeEpoch := time.Now().Unix() - // j.Sugar.Debugf("Start time: %d", startTimeEpoch) endTimeEpoch := startTimeEpoch + int64(LoadBalancerTimeOut.Seconds()) - // j.Sugar.Debugf("End Time: %d", endTimeEpoch) for i := time.Now().Unix(); i < endTimeEpoch; { - // j.Sugar.Debugf("################Iterations:%v####################", iterations) req, err = http.NewRequest("GET", urlString, nil) if err != nil { return nil, fmt.Errorf("error creating request: %v", err) @@ -82,34 +77,28 @@ func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) { } respCookies := resp.Cookies() - // j.Sugar.Debugf("Cookies got: %+v", respCookies) for _, v := range respCookies { if v.Name == LoadBalancerTargetCookie { strippedCookie := strings.TrimSpace(v.Value) - // j.Sugar.Debugf("Removing Whitespace. Before #%v# After #%v#", v.Value, strippedCookie) - // j.Sugar.Debugf("Appending: %v", strippedCookie) outList = append(outList, strippedCookie) } } - // j.Sugar.Debugf("BEGIN DUPE REMOVAL. OUTLIST: %v", outList) - + uniqueMap := make(map[string]bool) - + for _, str := range outList { uniqueMap[str] = true } - + cookieDupesRemoved := make([]string, 0, len(uniqueMap)) - + for str := range uniqueMap { cookieDupesRemoved = append(cookieDupesRemoved, str) } - - // j.Sugar.Debugf("DUPES REMOVED: %v", cookieDupesRemoved) - if len(cookieDupesRemoved) > 1 { - j.Sugar.Debugf("### COMPLETED COOKIE MAGIC ### Dupes removed: %v, outlist: %v", cookieDupesRemoved, outList) + if len(cookieDupesRemoved) > 1 { + j.Sugar.Debugf("### COMPLETED LOADBALANCER WORKAROUND ### Dupes removed: %v, outlist: %v", cookieDupesRemoved, outList) break }