Skip to content

Commit 5367690

Browse files
committed
tidying and todos added
1 parent 0e42703 commit 5367690

File tree

7 files changed

+34
-39
lines changed

7 files changed

+34
-39
lines changed

jamfprointegration/auth_basic.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type basicAuthResponse struct {
3131

3232
// Operations
3333

34+
// TODO comment
35+
// TODO migrate strings
3436
func (a *basicAuth) getNewToken() error {
3537
client := http.Client{}
3638

@@ -39,12 +41,14 @@ func (a *basicAuth) getNewToken() error {
3941
if err != nil {
4042
return err
4143
}
44+
4245
req.SetBasicAuth(a.username, a.password)
4346

4447
resp, err := client.Do(req)
4548
if err != nil {
4649
return err
4750
}
51+
4852
defer resp.Body.Close()
4953

5054
if resp.StatusCode != http.StatusOK {
@@ -66,20 +70,24 @@ func (a *basicAuth) getNewToken() error {
6670
return nil
6771
}
6872

73+
// TODO comment
6974
func (a *basicAuth) getTokenString() string {
7075
return a.bearerToken
7176
}
7277

78+
// TODO comment
7379
func (a *basicAuth) getExpiryTime() time.Time {
7480
return a.bearerTokenExpiryTime
7581
}
7682

7783
// Utils
7884

85+
// TODO comment
7986
func (a *basicAuth) tokenExpired() bool {
8087
return a.bearerTokenExpiryTime.Before(time.Now())
8188
}
8289

90+
// TODO comment
8391
func (a *basicAuth) tokenInBuffer() bool {
8492
if time.Until(a.bearerTokenExpiryTime) <= a.bufferPeriod {
8593
return true
@@ -88,6 +96,7 @@ func (a *basicAuth) tokenInBuffer() bool {
8896
return false
8997
}
9098

99+
// TODO comment
91100
func (a *basicAuth) tokenEmpty() bool {
92101
if a.bearerToken == "" {
93102
return true

jamfprointegration/auth_oauth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type OAuthResponse struct {
3636

3737
// Operations
3838

39+
// TODO migrate strings
3940
func (a *oauth) getNewToken() error {
4041
client := http.Client{}
4142
data := url.Values{}
@@ -87,30 +88,35 @@ func (a *oauth) getNewToken() error {
8788
return nil
8889
}
8990

91+
// TODO migrate strings
9092
func (a *oauth) getTokenString() string {
9193
return a.token
9294
}
9395

96+
// TODO migrate strings
9497
func (a *oauth) getExpiryTime() time.Time {
9598
return a.expiryTime
9699
}
97100

98101
// Utils
99102

103+
// TODO migrate strings
100104
func (a *oauth) tokenExpired() bool {
101105
if a.expiryTime.Before(time.Now()) {
102106
return true
103107
}
104108
return false
105109
}
106110

111+
// TODO migrate strings
107112
func (a *oauth) tokenInBuffer() bool {
108113
if time.Until(a.expiryTime) <= a.bufferPeriod {
109114
return true
110115
}
111116
return false
112117
}
113118

119+
// TODO migrate strings
114120
func (a *oauth) tokenEmpty() bool {
115121
return a.token == ""
116122
}

jamfprointegration/builders.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/deploymenttheory/go-api-http-client/logger"
77
)
88

9+
// TODO migrate strings
910
func BuildIntegrationWithOAuth(jamfBaseDomain string, logger logger.Logger, bufferPeriod time.Duration, clientId string, clientSecret string) (*Integration, error) {
1011
integration := Integration{
1112
BaseDomain: jamfBaseDomain,
@@ -19,6 +20,7 @@ func BuildIntegrationWithOAuth(jamfBaseDomain string, logger logger.Logger, buff
1920
return &integration, err
2021
}
2122

23+
// TODO migrate strings
2224
func BuildIntegrationWithBasicAuth(jamfBaseDomain string, logger logger.Logger, bufferPeriod time.Duration, username string, password string) (*Integration, error) {
2325
integration := Integration{
2426
BaseDomain: jamfBaseDomain,
@@ -32,29 +34,27 @@ func BuildIntegrationWithBasicAuth(jamfBaseDomain string, logger logger.Logger,
3234
return &integration, err
3335
}
3436

37+
// TODO migrate strings
3538
func (j *Integration) BuildOAuth(clientId string, clientSecret string, bufferPeriod time.Duration) {
3639
authInterface := oauth{
37-
// args
3840
clientId: clientId,
3941
clientSecret: clientSecret,
4042
bufferPeriod: bufferPeriod,
41-
42-
// integration
43-
baseDomain: j.BaseDomain,
44-
Logger: j.Logger,
43+
baseDomain: j.BaseDomain,
44+
Logger: j.Logger,
4545
}
4646

4747
j.auth = &authInterface
4848
}
4949

50+
// TODO migrate strings
5051
func (j *Integration) BuildBasicAuth(username string, password string, bufferPeriod time.Duration) {
5152
authInterface := basicAuth{
5253
username: username,
5354
password: password,
5455
bufferPeriod: bufferPeriod,
55-
56-
logger: j.Logger,
57-
baseDomain: j.BaseDomain,
56+
logger: j.Logger,
57+
baseDomain: j.BaseDomain,
5858
}
5959

6060
j.auth = &authInterface

jamfprointegration/helpers.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,12 @@ func ParseISO8601_Date(dateStr string) (time.Time, error) {
1616

1717
// SafeOpenFile opens a file safely after validating and resolving its path.
1818
func SafeOpenFile(filePath string) (*os.File, error) {
19-
// Clean the file path to remove any ".." or similar components that can lead to directory traversal
2019
cleanPath := filepath.Clean(filePath)
2120

22-
// Resolve the clean path to an absolute path and ensure it resolves any symbolic links
2321
absPath, err := filepath.EvalSymlinks(cleanPath)
2422
if err != nil {
2523
return nil, fmt.Errorf("unable to resolve the absolute path: %s, error: %w", filePath, err)
2624
}
2725

28-
// Optionally, check if the absolute path is within a permitted directory (omitted here for brevity)
29-
// Example: allowedPathPrefix := "/safe/directory/"
30-
// if !strings.HasPrefix(absPath, allowedPathPrefix) {
31-
// return nil, fmt.Errorf("access to the file path is not allowed: %s", absPath)
32-
// }
33-
34-
// Open the file if the path is deemed safe
3526
return os.Open(absPath)
3627
}

jamfprointegration/interface.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,40 @@ type Integration struct {
1818

1919
// Info
2020

21+
// TODO migrate strings
2122
func (j *Integration) Domain() string {
2223
return j.BaseDomain
2324
}
2425

26+
// TODO migrate strings
2527
func (j *Integration) GetAuthMethodDescriptor() string {
2628
return j.AuthMethodDescriptor
2729
}
2830

2931
// Utilities
3032

33+
// TODO migrate strings
3134
func (j *Integration) CheckRefreshToken() error {
3235
return j.checkRefreshToken()
3336
}
3437

38+
// TODO migrate strings
3539
func (j *Integration) PrepRequestParamsAndAuth(req *http.Request) error {
3640
err := j.prepRequest(req)
3741
return err
3842
}
3943

44+
// TODO migrate strings
4045
func (j *Integration) PrepRequestBody(body interface{}, method string, endpoint string) ([]byte, error) {
4146
return j.marshalRequest(body, method, endpoint)
4247
}
4348

49+
// TODO migrate strings
4450
func (j *Integration) MarshalMultipartRequest(fields map[string]string, files map[string]string) ([]byte, string, error) {
4551
return j.marshalMultipartRequest(fields, files)
4652
}
4753

54+
// TODO migrate strings
4855
func (j *Integration) GetSessionCookies() ([]*http.Cookie, error) {
4956
domain := j.Domain()
5057
return j.getSessionCookies(domain)

jamfprointegration/load_balancer_workaround.go

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

9+
// TODO migrate strings
910
func (j *Integration) getSessionCookies(urlString string) ([]*http.Cookie, error) {
1011
var returnList []*http.Cookie
1112
balancerValue, err := j.GetLoadBalancer(urlString)
@@ -16,6 +17,7 @@ func (j *Integration) getSessionCookies(urlString string) ([]*http.Cookie, error
1617
return returnList, nil
1718
}
1819

20+
// TODO migrate strings
1921
func (j *Integration) GetLoadBalancer(urlString string) (string, error) {
2022
allBalancers, err := j.getAllLoadBalancers(urlString)
2123
if err != nil {
@@ -26,6 +28,7 @@ func (j *Integration) GetLoadBalancer(urlString string) (string, error) {
2628
return chosenCookie, nil
2729
}
2830

31+
// TODO migrate strings
2932
func chooseMostAlphabeticalString(strings []string) string {
3033
if len(strings) == 0 {
3134
return ""
@@ -41,6 +44,7 @@ func chooseMostAlphabeticalString(strings []string) string {
4144
return mostAlphabeticalStr
4245
}
4346

47+
// TODO migrate strings
4448
func (j *Integration) getAllLoadBalancers(urlString string) (*[]string, error) {
4549

4650
var outList []string

jamfprointegration/urls.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,3 @@ package jamfprointegration
66
func (j *Integration) GetBaseDomain() string {
77
return j.BaseDomain
88
}
9-
10-
// ConstructAPIResourceEndpoint constructs the full URL for a Jamf API resource endpoint path and logs the URL.
11-
// It uses the instance name to construct the full URL.
12-
// func (j *Integration) ConstructAPIResourceEndpoint(endpoint string, log logger.Logger) string {
13-
// url := fmt.Sprintf("https://%s%s%s", j.InstanceName, j.GetBaseDomain(), endpoint)
14-
// j.Logger.Debug(fmt.Sprintf("Constructed %s API resource endpoint URL", APIName), zap.String("URL", url))
15-
// return url
16-
// }
17-
18-
// // ConstructAPIAuthEndpoint constructs the full URL for a Jamf API auth endpoint path and logs the URL.
19-
// // It uses the instance name to construct the full URL.
20-
// func (j *Integration) GetBearerAuthEndpoint(log logger.Logger) string {
21-
// url := fmt.Sprintf("https://%s%s%s", j.InstanceName, j.BaseDomain, BearerTokenEndpoint)
22-
// j.Logger.Debug(fmt.Sprintf("Constructed %s API authentication URL", APIName), zap.String("URL", url))
23-
// return url
24-
// }
25-
26-
// func (j *Integration) GetOAuthEndpoint(log logger.Logger) string {
27-
// url := fmt.Sprintf("https://%s%s%s", j.InstanceName, j.BaseDomain, OAuthTokenEndpoint)
28-
// j.Logger.Debug(fmt.Sprintf("Constructed %s API authentication URL", APIName), zap.String("URL", url))
29-
// return url
30-
// }

0 commit comments

Comments
 (0)