diff --git a/jamf/jamfprointegration/auth.go b/jamf/jamfprointegration/auth.go index 72e6c1e..5282daf 100644 --- a/jamf/jamfprointegration/auth.go +++ b/jamf/jamfprointegration/auth.go @@ -10,12 +10,9 @@ const ( ) type authInterface interface { - // Token Operations getNewToken() error getTokenString() string getExpiryTime() time.Time - - // Token Utils tokenExpired() bool tokenInBuffer() bool tokenEmpty() bool diff --git a/jamf/jamfprointegration/auth_basic.go b/jamf/jamfprointegration/auth_basic.go index ddb0ed0..0cfe6c0 100644 --- a/jamf/jamfprointegration/auth_basic.go +++ b/jamf/jamfprointegration/auth_basic.go @@ -9,29 +9,24 @@ import ( "go.uber.org/zap" ) +// basicAuth struct implements authInterface for this integration type basicAuth struct { - Sugar *zap.SugaredLogger - - // Set - baseDomain string - username string - password string - bufferPeriod time.Duration - hideSensitiveData bool - - // Computed - // basicToken string + Sugar *zap.SugaredLogger + baseDomain string + username string + password string + bufferPeriod time.Duration + hideSensitiveData bool bearerToken string bearerTokenExpiryTime time.Time } +// basicAuthResponse serves as a json structure map for the basicAuth response from Jamf. type basicAuthResponse struct { Token string `json:"token"` Expires time.Time `json:"expires"` } -// Operations - // getNewToken obtains a new bearer token from the authentication server. // This function constructs a new HTTP request to the bearer token endpoint using the basic authentication credentials, // sends the request, and updates the basicAuth instance with the new bearer token and its expiry time. @@ -50,7 +45,6 @@ type basicAuthResponse struct { // TODO migrate strings func (a *basicAuth) getNewToken() error { client := http.Client{} - completeBearerEndpoint := a.baseDomain + bearerTokenEndpoint a.Sugar.Debugf("bearer endpoint constructed: %s", completeBearerEndpoint) @@ -58,6 +52,7 @@ func (a *basicAuth) getNewToken() error { if err != nil { return err } + a.Sugar.Debugf("bearer token request constructed: %+v", req) req.SetBasicAuth(a.username, a.password) @@ -67,6 +62,7 @@ func (a *basicAuth) getNewToken() error { return err } defer resp.Body.Close() + a.Sugar.Debugf("bearer token request made: %v", resp.StatusCode) if resp.StatusCode != http.StatusOK { @@ -110,8 +106,6 @@ func (a *basicAuth) getExpiryTime() time.Time { return a.bearerTokenExpiryTime } -// Utils - // tokenExpired checks if the current bearer token has expired. // This function compares the current time with the bearer token's expiry time to determine if the token has expired. // diff --git a/jamf/jamfprointegration/auth_oauth.go b/jamf/jamfprointegration/auth_oauth.go index baa4675..94a80e5 100644 --- a/jamf/jamfprointegration/auth_oauth.go +++ b/jamf/jamfprointegration/auth_oauth.go @@ -13,19 +13,16 @@ import ( "go.uber.org/zap" ) +// oauth implements the authInterface for Oauth2 support type oauth struct { - Sugar *zap.SugaredLogger - - // Set + Sugar *zap.SugaredLogger baseDomain string clientId string clientSecret string bufferPeriod time.Duration hideSensitiveData bool - - // Computed - expiryTime time.Time - token string + expiryTime time.Time + token string } // OAuthResponse represents the response structure when obtaining an OAuth access token from JamfPro. @@ -36,13 +33,12 @@ type OAuthResponse struct { RefreshToken string `json:"refresh_token,omitempty"` } -// Operations - // TODO migrate strings + +// getNewToken updates the held token and expiry information func (a *oauth) getNewToken() error { client := http.Client{} data := url.Values{} - data.Set("client_id", a.clientId) data.Set("client_secret", a.clientSecret) data.Set("grant_type", "client_credentials") @@ -99,29 +95,27 @@ func (a *oauth) getNewToken() error { return nil } -// TODO func comment +// getTokenString returns the current token as a string func (a *oauth) getTokenString() string { return a.token } -// TODO func comment +// getExpiryTime returns the current token's expiry time as a time.Time var. func (a *oauth) getExpiryTime() time.Time { return a.expiryTime } -// Utils - -// TODO func comment +// tokenExpired returns a bool denoting if the current token expiry time has passed. func (a *oauth) tokenExpired() bool { return a.expiryTime.Before(time.Now()) } -// TODO func comment +// tokenInBuffer returns a bool denoting if the current token's duration until expiry is within the buffer period func (a *oauth) tokenInBuffer() bool { return time.Until(a.expiryTime) <= a.bufferPeriod } -// TODO func comment +// tokenEmpty returns a bool denoting if the current token string is empty. func (a *oauth) tokenEmpty() bool { return a.token == "" } diff --git a/jamf/jamfprointegration/builders.go b/jamf/jamfprointegration/builders.go index f123e11..9cff98e 100644 --- a/jamf/jamfprointegration/builders.go +++ b/jamf/jamfprointegration/builders.go @@ -6,7 +6,7 @@ import ( "go.uber.org/zap" ) -// TODO migrate strings +// BuildWithOAuth is a helper function allowing the full construct of a Jamf Integration using OAuth2 func BuildWithOAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, clientId string, clientSecret string, hideSensitiveData bool) (*Integration, error) { integration := Integration{ BaseDomain: jamfBaseDomain, @@ -20,7 +20,7 @@ func BuildWithOAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferPerio return &integration, err } -// TODO migrate strings +// BuildWithBasicAuth is a helper function allowing the full construct of a Jamf Integration using BasicAuth func BuildWithBasicAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, username string, password string, hideSensitiveData bool) (*Integration, error) { integration := Integration{ BaseDomain: jamfBaseDomain, @@ -34,7 +34,7 @@ func BuildWithBasicAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferP return &integration, err } -// TODO migrate strings +// BuildOAuth is a helper which returns just a configured OAuth interface func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPeriod time.Duration, hideSensitiveData bool) { authInterface := oauth{ clientId: clientId, @@ -48,7 +48,7 @@ func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPer j.auth = &authInterface } -// TODO migrate strings +// 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) { authInterface := basicAuth{ username: username, diff --git a/jamf/jamfprointegration/interface.go b/jamf/jamfprointegration/interface.go index 551d167..1b67e5b 100644 --- a/jamf/jamfprointegration/interface.go +++ b/jamf/jamfprointegration/interface.go @@ -14,46 +14,42 @@ type Integration struct { auth authInterface } -// Info - -// TODO migrate strings +// getFQDN returns just the FQDN // TODO remove the "get" func (j *Integration) GetFQDN() string { return j.BaseDomain } -// TODO this comment +// constructURL appends any endpoint to the FQDN func (j *Integration) ConstructURL(endpoint string) string { return j.GetFQDN() + endpoint } -// TODO migrate strings +// GetAuthMethodDescriptor returns a single string describing the auth method for debug and logging purposes func (j *Integration) GetAuthMethodDescriptor() string { return j.AuthMethodDescriptor } -// Utilities - -// TODO migrate strings +// CheckRefreshToken ensures the token is valid and refreshes if it is not. func (j *Integration) CheckRefreshToken() error { return j.checkRefreshToken() } -// TODO migrate strings +// PrepRequestParamsAndAuth applies any parameters and authentication headers to a http.Request func (j *Integration) PrepRequestParamsAndAuth(req *http.Request) error { return j.prepRequest(req) } -// TODO migrate strings +// PrepRequestBody formats body data to meet the API requirements. func (j *Integration) PrepRequestBody(body interface{}, method string, endpoint string) ([]byte, error) { return j.marshalRequest(body, method, endpoint) } -// TODO migrate strings +// TODO this comment func (j *Integration) MarshalMultipartRequest(fields map[string]string, files map[string]string) ([]byte, string, error) { return j.marshalMultipartRequest(fields, files) } -// TODO migrate strings +// GetSessionCookies retrieves all cookies from the current session func (j *Integration) GetSessionCookies() ([]*http.Cookie, error) { domain := j.GetFQDN() return j.getSessionCookies(domain) diff --git a/jamf/jamfprointegration/load_balancer_workaround.go b/jamf/jamfprointegration/load_balancer_workaround.go index c58f029..fcfaf1b 100644 --- a/jamf/jamfprointegration/load_balancer_workaround.go +++ b/jamf/jamfprointegration/load_balancer_workaround.go @@ -6,7 +6,7 @@ import ( "slices" ) -// TODO migrate strings +// GetSessionCookies retrieves all cookies from the current session func (j *Integration) getSessionCookies(urlString string) ([]*http.Cookie, error) { var returnList []*http.Cookie balancerValue, err := j.GetLoadBalancer(urlString) @@ -17,7 +17,7 @@ func (j *Integration) getSessionCookies(urlString string) ([]*http.Cookie, error return returnList, nil } -// TODO migrate strings +// GetLoadBalancer programatically always returns the most alphabetical load balancer from a session func (j *Integration) GetLoadBalancer(urlString string) (string, error) { allBalancers, err := j.getAllLoadBalancers(urlString) if err != nil { @@ -28,7 +28,7 @@ func (j *Integration) GetLoadBalancer(urlString string) (string, error) { return chosenCookie, nil } -// TODO migrate strings +// chooseMostAlphabeticalString returns the most alphabetical string from a list of strings func chooseMostAlphabeticalString(strings []string) string { if len(strings) == 0 { return ""