func()

in pkg/infrastructure/spRoleAssignmentManager/defaultSPRoleAssignmentManager.go [287:306]


func (r *SPRoleAssignmentManager) DetachRolesFromSP(ctx context.Context, subscription string, SPOBjectID string, role domain.Role) error {

	filter := fmt.Sprintf("assignedTo('%s')", SPOBjectID)
	resp, err := r.azAPIClient.RoleAssignmentsClient.List(ctx, filter)

	if err != nil {
		return err
	}

	roleAssignments := resp.Values()

	for _, roleAssignment := range roleAssignments {
		_, err := r.azAPIClient.RoleAssignmentsDeletionClient.DeleteByID(ctx, string(*roleAssignment.ID), nil)
		if err != nil {
			return err
		}
	}

	return nil
}