def apply_iam_bindings_patch(current_policy, bindings_patch, action):
  """
  Patches the current policy with the supplied patch.
  action can be add or remove.
  """
  for item in bindings_patch['bindings']:
    members = item['members']
    roles = item['roles']
    for role in roles:
      if role not in current_policy.keys():
        current_policy[role] = set()
      if action == "add":
        current_policy[role].update(members)
      else:
        current_policy[role].difference_update(members)
  return current_policy