Skip to content

Commit 4c5d694

Browse files
authored
Merge pull request #13 from ConductorOne/jirwin/no-conflict-errors-provision
Don't fail group provisioning if there isn't work to do
2 parents 76b18ef + 5a6e38f commit 4c5d694

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/connector/groups.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ func (o *groupResourceType) Grant(ctx context.Context, principal *v2.Resource, e
172172
Type: "user",
173173
}).Execute()
174174
if err != nil {
175-
l.Error("failed to add user to group", zap.Error(err), zap.String("group", entitlement.Resource.Id.Resource), zap.String("user", principal.Id.Resource))
176-
return nil, err
175+
// If the user is already a member of the group, we get a 409 and we want to return success.
176+
if resp == nil || resp.StatusCode != http.StatusConflict {
177+
l.Error("failed to add user to group", zap.Error(err), zap.String("group", entitlement.Resource.Id.Resource), zap.String("user", principal.Id.Resource))
178+
return nil, err
179+
}
177180
}
178181
defer resp.Body.Close()
179182

@@ -213,8 +216,11 @@ func (o *groupResourceType) Revoke(ctx context.Context, grant *v2.Grant) (annota
213216
Type: "user",
214217
}).Execute()
215218
if err != nil {
216-
l.Error("failed to remove user from group", zap.Error(err), zap.String("group", entitlement.Resource.Id.Resource), zap.String("user", principal.Id.Resource))
217-
return nil, err
219+
// If the user is already not a member of the group, we get a 404 and we want to return success.
220+
if resp == nil || resp.StatusCode != http.StatusNotFound {
221+
l.Error("failed to remove user from group", zap.Error(err), zap.String("group", entitlement.Resource.Id.Resource), zap.String("user", principal.Id.Resource))
222+
return nil, err
223+
}
218224
}
219225
defer resp.Body.Close()
220226

0 commit comments

Comments
 (0)