我正在尝试使用 gitlab ci 中的 for 循环删除对谷歌云函数的某个权限。
for i in ${!CFS[@]}; do
gcloud functions remove-iam-policy-binding ${API_VERSION}-${CFS[$i]} --member=${MEMBER} --role=${ROLE}
done
问题是,如果资源没有给定的角色,对于成员,我会收到错误消息。
ERROR: (gcloud.functions.remove-iam-policy-binding) Policy binding with the specified member and role not found!
。
我想通过在执行 remove-iam-policy-binding
gcloud 命令之前检查成员是否在资源上具有给定角色来避免这种情况。有没有办法在删除成员之前检查给定资源上的成员是否存在权限?
答案 0 :(得分:1)
我能够使用 gcloud functions get-iam-policy
并过滤我想要的权限和角色来实现这一点。如果为给定用户设置了角色,那么我将其删除。
for mem in $(gcloud functions get-iam-policy ${CFS[$i]} --flatten="bindings[].members" --filter="bindings.role:roles/cloudfunctions.invoker" --format="value(bindings.members)")
do
echo $mem
gcloud functions remove-iam-policy-binding ${CFS[$i]} --member=$mem --role="roles/cloudfunctions.invoker"
done