Skip to content

Commit 55ad85f

Browse files
committed
Logging migrated to zap.SugaredLogger
hideSensitiveData reimplemented
1 parent bbc825e commit 55ad85f

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

jamf/jamfprointegration/auth.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func (j *Integration) checkRefreshToken() error {
4444

4545
if j.auth.tokenExpired() || j.auth.tokenInBuffer() || j.auth.tokenEmpty() {
4646
err = j.auth.getNewToken()
47-
4847
if err != nil {
4948
return err
5049
}

jamf/jamfprointegration/auth_basic.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import (
1010
)
1111

1212
type basicAuth struct {
13+
Sugar *zap.SugaredLogger
14+
1315
// Set
14-
baseDomain string
15-
username string
16-
password string
17-
bufferPeriod time.Duration
18-
Sugar *zap.SugaredLogger
16+
baseDomain string
17+
username string
18+
password string
19+
bufferPeriod time.Duration
20+
hideSensitiveData bool
1921

2022
// Computed
2123
// basicToken string
@@ -50,19 +52,22 @@ func (a *basicAuth) getNewToken() error {
5052
client := http.Client{}
5153

5254
completeBearerEndpoint := a.baseDomain + bearerTokenEndpoint
55+
a.Sugar.Debugf("bearer endpoint constructed: %s", completeBearerEndpoint)
56+
5357
req, err := http.NewRequest("POST", completeBearerEndpoint, nil)
5458
if err != nil {
5559
return err
5660
}
61+
a.Sugar.Debugf("bearer token request constructed: %+v", req)
5762

5863
req.SetBasicAuth(a.username, a.password)
5964

6065
resp, err := client.Do(req)
6166
if err != nil {
6267
return err
6368
}
64-
6569
defer resp.Body.Close()
70+
a.Sugar.Debugf("bearer token request made: %v", resp.StatusCode)
6671

6772
if resp.StatusCode != http.StatusOK {
6873
return fmt.Errorf("received non-OK response status: %d", resp.StatusCode)
@@ -74,6 +79,10 @@ func (a *basicAuth) getNewToken() error {
7479
return err
7580
}
7681

82+
if !a.hideSensitiveData {
83+
a.Sugar.Debug("token recieved: %+v", tokenResp)
84+
}
85+
7786
a.bearerToken = tokenResp.Token
7887
a.bearerTokenExpiryTime = tokenResp.Expires
7988
tokenDuration := time.Until(a.bearerTokenExpiryTime)

jamf/jamfprointegration/auth_oauth.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
)
1515

1616
type oauth struct {
17+
Sugar *zap.SugaredLogger
18+
1719
// Set
18-
baseDomain string
19-
clientId string
20-
clientSecret string
21-
bufferPeriod time.Duration
22-
Sugar *zap.SugaredLogger
20+
baseDomain string
21+
clientId string
22+
clientSecret string
23+
bufferPeriod time.Duration
24+
hideSensitiveData bool
2325

2426
// Computed
2527
expiryTime time.Time
@@ -46,11 +48,15 @@ func (a *oauth) getNewToken() error {
4648
data.Set("grant_type", "client_credentials")
4749

4850
oauthComlpeteEndpoint := a.baseDomain + oAuthTokenEndpoint
51+
a.Sugar.Debugf("oauth endpoint constructed: %s", oauthComlpeteEndpoint)
52+
4953
req, err := http.NewRequest("POST", oauthComlpeteEndpoint, strings.NewReader(data.Encode()))
5054
if err != nil {
5155
return err
5256
}
5357

58+
a.Sugar.Debugf("oauth token request constructed: %+v", req)
59+
5460
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
5561

5662
resp, err := client.Do(req)
@@ -77,6 +83,10 @@ func (a *oauth) getNewToken() error {
7783
return fmt.Errorf("failed to decode OAuth response: %w", err)
7884
}
7985

86+
if !a.hideSensitiveData {
87+
a.Sugar.Debug("token recieved: %+v", oauthResp)
88+
}
89+
8090
if oauthResp.AccessToken == "" {
8191
return fmt.Errorf("empty access token received")
8292
}
@@ -85,6 +95,7 @@ func (a *oauth) getNewToken() error {
8595
a.expiryTime = time.Now().Add(expiresIn)
8696
a.token = oauthResp.AccessToken
8797

98+
a.Sugar.Info("Token obtained successfully", zap.Time("Expiry", a.expiryTime))
8899
return nil
89100
}
90101

0 commit comments

Comments
 (0)