Skip to content

Commit

Permalink
Merge pull request #226 from jamestoyer/fix/missing-permission-errors
Browse files Browse the repository at this point in the history
Stop 404s for permission and user "exists" requests causing errors
  • Loading branch information
alexhung authored Dec 1, 2021
2 parents d703688 + b2e18a6 commit e66cdd9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/artifactory/resource_artifactory_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package artifactory

import (
"fmt"
"net/http"

"github.com/go-resty/resty/v2"

Expand Down Expand Up @@ -197,7 +198,12 @@ func resourceGroupExists(d *schema.ResourceData, m interface{}) (bool, error) {
}

func groupExists(client *resty.Client, groupName string) (bool, error) {
_, err := client.R().Head(groupsEndpoint + groupName)
resp, err := client.R().Head(groupsEndpoint + groupName)
if err != nil && resp != nil && resp.StatusCode() == http.StatusNotFound {
// Do not error on 404s as this causes errors when the upstream user has been manually removed
return false, nil
}

return err == nil, err
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/artifactory/resource_artifactory_permission_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ func resourcePermissionTargetExists(d *schema.ResourceData, m interface{}) (bool
}

func permTargetExists(id string, m interface{}) (bool, error) {
_, err := m.(*resty.Client).R().Head(permissionsEndPoint + id)
resp, err := m.(*resty.Client).R().Head(permissionsEndPoint + id)
if err != nil && resp != nil && resp.StatusCode() == http.StatusNotFound {
// Do not error on 404s as this causes errors when the upstream permission has been manually removed
return false, nil
}

return err == nil, err
}
7 changes: 6 additions & 1 deletion pkg/artifactory/resource_artifactory_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func resourceUserExists(data *schema.ResourceData, m interface{}) (bool, error)
}

func userExists(client *resty.Client, userName string) (bool, error) {
_, err := client.R().Head("artifactory/api/security/users/" + userName)
resp, err := client.R().Head("artifactory/api/security/users/" + userName)
if err != nil && resp != nil && resp.StatusCode() == http.StatusNotFound {
// Do not error on 404s as this causes errors when the upstream user has been manually removed
return false, nil
}

return err == nil, err
}

Expand Down

0 comments on commit e66cdd9

Please sign in to comment.