Skip to content

Commit ab046a3

Browse files
committed
Comments
1 parent dcf2d5f commit ab046a3

File tree

6 files changed

+36
-55
lines changed

6 files changed

+36
-55
lines changed

jamf/jamfprointegration/auth.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ const (
1010
)
1111

1212
type authInterface interface {
13-
// Token Operations
1413
getNewToken() error
1514
getTokenString() string
1615
getExpiryTime() time.Time
17-
18-
// Token Utils
1916
tokenExpired() bool
2017
tokenInBuffer() bool
2118
tokenEmpty() bool

jamf/jamfprointegration/auth_basic.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,24 @@ import (
99
"go.uber.org/zap"
1010
)
1111

12+
// basicAuth struct implements authInterface for this integration
1213
type basicAuth struct {
13-
Sugar *zap.SugaredLogger
14-
15-
// Set
16-
baseDomain string
17-
username string
18-
password string
19-
bufferPeriod time.Duration
20-
hideSensitiveData bool
21-
22-
// Computed
23-
// basicToken string
14+
Sugar *zap.SugaredLogger
15+
baseDomain string
16+
username string
17+
password string
18+
bufferPeriod time.Duration
19+
hideSensitiveData bool
2420
bearerToken string
2521
bearerTokenExpiryTime time.Time
2622
}
2723

24+
// basicAuthResponse serves as a json structure map for the basicAuth response from Jamf.
2825
type basicAuthResponse struct {
2926
Token string `json:"token"`
3027
Expires time.Time `json:"expires"`
3128
}
3229

33-
// Operations
34-
3530
// getNewToken obtains a new bearer token from the authentication server.
3631
// This function constructs a new HTTP request to the bearer token endpoint using the basic authentication credentials,
3732
// sends the request, and updates the basicAuth instance with the new bearer token and its expiry time.
@@ -50,14 +45,14 @@ type basicAuthResponse struct {
5045
// TODO migrate strings
5146
func (a *basicAuth) getNewToken() error {
5247
client := http.Client{}
53-
5448
completeBearerEndpoint := a.baseDomain + bearerTokenEndpoint
5549
a.Sugar.Debugf("bearer endpoint constructed: %s", completeBearerEndpoint)
5650

5751
req, err := http.NewRequest("POST", completeBearerEndpoint, nil)
5852
if err != nil {
5953
return err
6054
}
55+
6156
a.Sugar.Debugf("bearer token request constructed: %+v", req)
6257

6358
req.SetBasicAuth(a.username, a.password)
@@ -67,6 +62,7 @@ func (a *basicAuth) getNewToken() error {
6762
return err
6863
}
6964
defer resp.Body.Close()
65+
7066
a.Sugar.Debugf("bearer token request made: %v", resp.StatusCode)
7167

7268
if resp.StatusCode != http.StatusOK {
@@ -110,8 +106,6 @@ func (a *basicAuth) getExpiryTime() time.Time {
110106
return a.bearerTokenExpiryTime
111107
}
112108

113-
// Utils
114-
115109
// tokenExpired checks if the current bearer token has expired.
116110
// This function compares the current time with the bearer token's expiry time to determine if the token has expired.
117111
//

jamf/jamfprointegration/auth_oauth.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@ import (
1313
"go.uber.org/zap"
1414
)
1515

16+
// oauth implements the authInterface for Oauth2 support
1617
type oauth struct {
17-
Sugar *zap.SugaredLogger
18-
19-
// Set
18+
Sugar *zap.SugaredLogger
2019
baseDomain string
2120
clientId string
2221
clientSecret string
2322
bufferPeriod time.Duration
2423
hideSensitiveData bool
25-
26-
// Computed
27-
expiryTime time.Time
28-
token string
24+
expiryTime time.Time
25+
token string
2926
}
3027

3128
// OAuthResponse represents the response structure when obtaining an OAuth access token from JamfPro.
@@ -36,13 +33,12 @@ type OAuthResponse struct {
3633
RefreshToken string `json:"refresh_token,omitempty"`
3734
}
3835

39-
// Operations
40-
4136
// TODO migrate strings
37+
38+
// getNewToken updates the held token and expiry information
4239
func (a *oauth) getNewToken() error {
4340
client := http.Client{}
4441
data := url.Values{}
45-
4642
data.Set("client_id", a.clientId)
4743
data.Set("client_secret", a.clientSecret)
4844
data.Set("grant_type", "client_credentials")
@@ -99,29 +95,27 @@ func (a *oauth) getNewToken() error {
9995
return nil
10096
}
10197

102-
// TODO func comment
98+
// getTokenString returns the current token as a string
10399
func (a *oauth) getTokenString() string {
104100
return a.token
105101
}
106102

107-
// TODO func comment
103+
// getExpiryTime returns the current token's expiry time as a time.Time var.
108104
func (a *oauth) getExpiryTime() time.Time {
109105
return a.expiryTime
110106
}
111107

112-
// Utils
113-
114-
// TODO func comment
108+
// tokenExpired returns a bool denoting if the current token expiry time has passed.
115109
func (a *oauth) tokenExpired() bool {
116110
return a.expiryTime.Before(time.Now())
117111
}
118112

119-
// TODO func comment
113+
// tokenInBuffer returns a bool denoting if the current token's duration until expiry is within the buffer period
120114
func (a *oauth) tokenInBuffer() bool {
121115
return time.Until(a.expiryTime) <= a.bufferPeriod
122116
}
123117

124-
// TODO func comment
118+
// tokenEmpty returns a bool denoting if the current token string is empty.
125119
func (a *oauth) tokenEmpty() bool {
126120
return a.token == ""
127121
}

jamf/jamfprointegration/builders.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"go.uber.org/zap"
77
)
88

9-
// TODO migrate strings
9+
// BuildWithOAuth is a helper function allowing the full construct of a Jamf Integration using OAuth2
1010
func BuildWithOAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, clientId string, clientSecret string, hideSensitiveData bool) (*Integration, error) {
1111
integration := Integration{
1212
BaseDomain: jamfBaseDomain,
@@ -20,7 +20,7 @@ func BuildWithOAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferPerio
2020
return &integration, err
2121
}
2222

23-
// TODO migrate strings
23+
// BuildWithBasicAuth is a helper function allowing the full construct of a Jamf Integration using BasicAuth
2424
func BuildWithBasicAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferPeriod time.Duration, username string, password string, hideSensitiveData bool) (*Integration, error) {
2525
integration := Integration{
2626
BaseDomain: jamfBaseDomain,
@@ -34,7 +34,7 @@ func BuildWithBasicAuth(jamfBaseDomain string, Sugar *zap.SugaredLogger, bufferP
3434
return &integration, err
3535
}
3636

37-
// TODO migrate strings
37+
// BuildOAuth is a helper which returns just a configured OAuth interface
3838
func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPeriod time.Duration, hideSensitiveData bool) {
3939
authInterface := oauth{
4040
clientId: clientId,
@@ -48,7 +48,7 @@ func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPer
4848
j.auth = &authInterface
4949
}
5050

51-
// TODO migrate strings
51+
// BuildBasicAuth is a helper which returns just a configured Basic Auth interface/
5252
func (j *Integration) BuildBasicAuth(username string, password string, bufferPeriod time.Duration, hideSensitiveData bool) {
5353
authInterface := basicAuth{
5454
username: username,

jamf/jamfprointegration/interface.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,42 @@ type Integration struct {
1414
auth authInterface
1515
}
1616

17-
// Info
18-
19-
// TODO migrate strings
17+
// getFQDN returns just the FQDN // TODO remove the "get"
2018
func (j *Integration) GetFQDN() string {
2119
return j.BaseDomain
2220
}
2321

24-
// TODO this comment
22+
// constructURL appends any endpoint to the FQDN
2523
func (j *Integration) ConstructURL(endpoint string) string {
2624
return j.GetFQDN() + endpoint
2725
}
2826

29-
// TODO migrate strings
27+
// GetAuthMethodDescriptor returns a single string describing the auth method for debug and logging purposes
3028
func (j *Integration) GetAuthMethodDescriptor() string {
3129
return j.AuthMethodDescriptor
3230
}
3331

34-
// Utilities
35-
36-
// TODO migrate strings
32+
// CheckRefreshToken ensures the token is valid and refreshes if it is not.
3733
func (j *Integration) CheckRefreshToken() error {
3834
return j.checkRefreshToken()
3935
}
4036

41-
// TODO migrate strings
37+
// PrepRequestParamsAndAuth applies any parameters and authentication headers to a http.Request
4238
func (j *Integration) PrepRequestParamsAndAuth(req *http.Request) error {
4339
return j.prepRequest(req)
4440
}
4541

46-
// TODO migrate strings
42+
// PrepRequestBody formats body data to meet the API requirements.
4743
func (j *Integration) PrepRequestBody(body interface{}, method string, endpoint string) ([]byte, error) {
4844
return j.marshalRequest(body, method, endpoint)
4945
}
5046

51-
// TODO migrate strings
47+
// TODO this comment
5248
func (j *Integration) MarshalMultipartRequest(fields map[string]string, files map[string]string) ([]byte, string, error) {
5349
return j.marshalMultipartRequest(fields, files)
5450
}
5551

56-
// TODO migrate strings
52+
// GetSessionCookies retrieves all cookies from the current session
5753
func (j *Integration) GetSessionCookies() ([]*http.Cookie, error) {
5854
domain := j.GetFQDN()
5955
return j.getSessionCookies(domain)

jamf/jamfprointegration/load_balancer_workaround.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"slices"
77
)
88

9-
// TODO migrate strings
9+
// GetSessionCookies retrieves all cookies from the current session
1010
func (j *Integration) getSessionCookies(urlString string) ([]*http.Cookie, error) {
1111
var returnList []*http.Cookie
1212
balancerValue, err := j.GetLoadBalancer(urlString)
@@ -17,7 +17,7 @@ func (j *Integration) getSessionCookies(urlString string) ([]*http.Cookie, error
1717
return returnList, nil
1818
}
1919

20-
// TODO migrate strings
20+
// GetLoadBalancer programatically always returns the most alphabetical load balancer from a session
2121
func (j *Integration) GetLoadBalancer(urlString string) (string, error) {
2222
allBalancers, err := j.getAllLoadBalancers(urlString)
2323
if err != nil {
@@ -28,7 +28,7 @@ func (j *Integration) GetLoadBalancer(urlString string) (string, error) {
2828
return chosenCookie, nil
2929
}
3030

31-
// TODO migrate strings
31+
// chooseMostAlphabeticalString returns the most alphabetical string from a list of strings
3232
func chooseMostAlphabeticalString(strings []string) string {
3333
if len(strings) == 0 {
3434
return ""

0 commit comments

Comments
 (0)