Skip to content

Commit

Permalink
Merge pull request #3 from kenchan0130/feature/retryable
Browse files Browse the repository at this point in the history
Support retry with 404 status in classic api
  • Loading branch information
kenchan0130 committed May 10, 2023
2 parents 66f9cb5 + 74cc485 commit 4384502
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions classic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package classic

import (
"fmt"
"net/http"
"net/url"
"path"

Expand Down Expand Up @@ -56,3 +57,8 @@ func NewClient(serverURL string) (*Client, error) {

return c, nil
}

// RetryOn404ConsistencyFailureFunc can be used to retry a request when a 404 response is received
func RetryOn404ConsistencyFailureFunc(resp *http.Response) bool {
return resp != nil && resp.StatusCode == http.StatusNotFound
}
2 changes: 2 additions & 0 deletions classic/computer_extension_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func (s *ComputerExtensionAttributesService) Delete(ctx context.Context, compute
func (s *ComputerExtensionAttributesService) Get(ctx context.Context, computerExtensionAttributeID int) (*ComputerExtensionAttribute, *jamf.Response, error) {
resp, _, err := s.client.Get(ctx, jamf.GetHttpRequestInput{
ValidStatusCodes: []int{http.StatusOK},
// The API may return a 404, e.g., when a resource is just created.
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
Uri: jamf.Uri{
Entity: path.Join(computerExtensionAttributesPath, "id", fmt.Sprint(computerExtensionAttributeID)),
},
Expand Down
2 changes: 2 additions & 0 deletions classic/computer_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ func (s *ComputerGroupsService) Delete(ctx context.Context, computerGroupID int)
func (s *ComputerGroupsService) Get(ctx context.Context, computerGroupID int) (*ComputerGroup, *jamf.Response, error) {
resp, _, err := s.client.Get(ctx, jamf.GetHttpRequestInput{
ValidStatusCodes: []int{http.StatusOK},
// The API may return a 404, e.g., when a resource is just created.
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
Uri: jamf.Uri{
Entity: path.Join(computerGroupsPath, "id", fmt.Sprint(computerGroupID)),
},
Expand Down
2 changes: 2 additions & 0 deletions classic/osx_configuration_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func (s *OSXConfigurationProfilesService) Delete(ctx context.Context, osxConfigu
func (s *OSXConfigurationProfilesService) Get(ctx context.Context, osxConfigurationProfileID int) (*OSXConfigurationProfile, *jamf.Response, error) {
resp, _, err := s.client.Get(ctx, jamf.GetHttpRequestInput{
ValidStatusCodes: []int{http.StatusOK},
// The API may return a 404, e.g., when a resource is just created.
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
Uri: jamf.Uri{
Entity: path.Join(osxConfigurationProfilesPath, "id", fmt.Sprint(osxConfigurationProfileID)),
},
Expand Down
2 changes: 2 additions & 0 deletions classic/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func (s *PackagesService) Delete(ctx context.Context, packageID int) (*jamf.Resp
func (s *PackagesService) Get(ctx context.Context, packageID int) (*Package, *jamf.Response, error) {
resp, _, err := s.client.Get(ctx, jamf.GetHttpRequestInput{
ValidStatusCodes: []int{http.StatusOK},
// The API may return a 404, e.g., when a resource is just created.
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
Uri: jamf.Uri{
Entity: path.Join(packagesPath, "id", fmt.Sprint(packageID)),
},
Expand Down

0 comments on commit 4384502

Please sign in to comment.