
    +                        S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
KJr  SSKJr  SS	KJr  SS	KJr  SSKJr  SS	KJr  SSKJr  SSKJr  SSKJr  \R:                  \R<                  " \R>                  R@                  \R>                  RB                  5       " S S\RD                  5      5       5       r#S r$g)zCommand to remove project-level and fleet scope-level IAM bindings and delete a fleet scope RBAC role binding for an app operator.    )absolute_import)division)unicode_literalsN)encoding)projects_api)client)util)base)	resources)iam_util)log)
properties)
console_ioc                   .    \ rS rSrSr\S 5       rS rSrg)RemoveAppOperatorBinding&   a^  Remove project-level and fleet scope-level IAM bindings and delete a fleet scope RBAC role binding for an app operator principal.

One binding consists of an app operator principal (user/group) and a role
(view/edit/admin).

This command unsets the different permissions required for an app operator,
including usage of fleet scopes, connect gateway, logging, and metrics. The
authoritative list for removing the permissions is the existing RBAC role
bindings under the specified scope.

This command can fail for the following reasons:
* The scope specified does not exist.
* The user does not have access to the specified scope.
* The principal specified does not any binding for the scope.
* The principal specified has bindings with different roles for the scope.

## EXAMPLES

The following command:

  $ {command} SCOPE --group=people@google.com --project=PROJECT_ID

assuming the group already has the `view` role:
* removes IAM policy binding: roles/gkehub.scopeViewer from `SCOPE`
* removes IAM policy binding: roles/gkehub.scopeViewerProjectLevel from
`PROJECT_ID` if the group does not have the `view` role for any other scope
under the project
* removes IAM policy binding: roles/logging.viewAccessor from `PROJECT_ID`
condition where bucket corresponds to `SCOPE`
* deletes existing fleet scope RBAC role binding: role `view` for group
`people@google.com`.

---

The following command:

  $ {command} SCOPE --user=person@google.com --project=PROJECT_ID

assuming the user already has the `edit` role:
* removes IAM policy binding: roles/gkehub.scopeEditor from `SCOPE`
* removes IAM policy binding: roles/gkehub.scopeEditorProjectLevel from
`PROJECT_ID` if the user does not have the `edit`/`admin` role for any other
scope under the project
* removes IAM policy binding: roles/logging.viewAccessor from `PROJECT_ID`
condition where bucket corresponds to `SCOPE`
* deletes existing fleet scope RBAC role binding: role `edit` for user
`person@google.com`.

---

The following command:

  $ {command} SCOPE --user=person@google.com --project=PROJECT_ID

assuming the user already has a custom role:
* removes IAM policy binding: roles/gkehub.scopeViewer from `SCOPE`
* removes IAM policy binding: roles/gkehub.scopeEditorProjectLevel from
`PROJECT_ID`  if the user does not have the `edit`/`admin` role for any other
scope under the project
* removes IAM policy binding: roles/logging.viewAccessor from `PROJECT_ID`
condition where bucket corresponds to `SCOPE`
* deletes existing fleet scope RBAC role binding: role `admin` for user
`person@google.com`.

---

The following command:

  $ {command} SCOPE --user=person@google.com --project=PROJECT_ID

assuming the user already has the `admin` role:
* removes IAM policy binding: roles/gkehub.scopeAdmin from `SCOPE`
* removes IAM policy binding: roles/gkehub.scopeEditorProjectLevel from
`PROJECT_ID`  if the user does not have the `edit`/`admin` role for any other
scope under the project
* removes IAM policy binding: roles/logging.viewAccessor from `PROJECT_ID`
condition where bucket corresponds to `SCOPE`
* deletes existing fleet scope RBAC role binding: role `admin` for user
`person@google.com`.
c                     [         R                  " US[        R                  U R	                  5          SSS9  UR                  SS9nUR                  S[        SS9  UR                  S	[        S
S9  g )NSCOPEz@Name of the fleet scope for removing IAM and RBAC role bindings.T)
scope_helprequired)r   z--userzUser for the role binding.)typehelpz--groupzGroup for the role binding.)r   AddScopeResourceArgapi_utilVERSION_MAPReleaseTrackadd_mutually_exclusive_groupadd_argumentstr)clsparsergroups      Alib/surface/container/fleet/scopes/remove_app_operator_binding.pyArgsRemoveAppOperatorBinding.Argsz   s    !!S--/0N ///>E	)  
 
*      c           
      	   UR                   nUc2  [        R                  R                  R                   R	                  5       n[
        R                  " U5      n[        R                  " U R                  5       S9nUR                  R                  R                  5       nUR                  5       nUR                  5       n[        R                   " UR"                  UR$                  5      n/ n	Sn
UR'                  X&5      nU H  nUR"                  UR"                  :X  d  M  UR$                  UR$                  :X  d  M;  U
(       d!  [        R(                  " UR*                  5      n
OlU
[        R(                  " UR*                  5      :w  aH  [,        R.                  " SR1                  UU
[        R(                  " UR*                  5      U5      5          g U	R3                  U5        M     U	(       d&  [,        R.                  " SR1                  X5      5        g [        R4                  " U
5      n[        R6                  " U
5      nSnUR9                  U5      nU H  nUR:                  U:X  a  M  UR'                  U[<        R>                  " UR:                  5      5      nS/SS/SS/S	.nU HI  nURA                  U
SS/5       H.  n[C        UUUR"                  UR$                  5      (       d  M,  S
nM0     MK     M     [D        RF                  " 5       (       am  SR1                  X5      nU(       a  USR1                  XU5      -  nOUSR1                  X5      -  nUSR1                  X&X5      -  n[D        RH                  " USS
S9  U(       d=  [J        RL                  " UUU5        [,        RN                  " SR1                  U5      5        [        RP                  " X&5      n[R        RT                  " U[R        RV                  5        [J        RX                  " UUSUS5        [,        RN                  " S5        UR[                  U5      n[R        R\                  " UUU5        UR_                  UU5        [,        RN                  " S5        [a        U	5      S:  a&  [,        Rb                  " SR1                  XU5      5        U	 H  nURe                  UR:                  5        M      g )N)release_track z`{}` has more than one role (`{}` and `{}`) for scope `{}` via existing RBAC role bindings. Please remove unexpected bindings invdividually and retry.zK`{}` does not have any role for scope `{}` via existing RBAC role bindings.Fvieweditadmin)r*   r+   r,   TzAThe command:
  * removes IAM policy binding: `{}` from scope `{}`z}
  * does *not* remove IAM policy binding: `{}` from project `{}` as `{}` needs the binding for other scope(s) in the projectz7
  * removes IAM policy binding: `{}` from project `{}`z
  * removes IAM policy binding: `roles/logging.viewAccessor` from project `{}` with a condition where the bucket corresponds to scope `{}`
  * deletes existing fleet scope RBAC role binding: role `{}` for `{}`zDo you want to continue)messageprompt_stringcancel_on_noz&Removed project-level binding for `{}`zroles/logging.viewAccessorzJRemoved conditional project-level binding for `roles/logging.viewAccessor`zRemoved scope-level IAM binding   zgMore than one RBAC role binding found for `{}` with role `{}` under scope `{}`; deleting all of them...)3projectr   VALUEScoreGetprojects_utilParseProjectr   FleetClientr   CONCEPTSscopeParseNameRelativeNamescopes_utilIamMemberFromRbacuserr"   ListScopeRBACRoleBindingsScopeRbacRoleStringroler   errorformatappendIamScopeLevelScopeRoleFromRbac IamProjectLevelScopeRoleFromRbac
ListScopesnamer	   ResourceIdFromPathgetbindings_matchr   	CanPromptPromptContinuer   RemoveIamPolicyBindingPrintScopeLogViewConditionr   ValidateConditionArgumentCONDITION_FORMAT_EXCEPTION#RemoveIamPolicyBindingWithConditionGetScopeIamPolicyRemoveBindingFromIamPolicySetScopeIamPolicylenwarningDeleteScopeRBACRoleBinding)selfargsr1   project_reffleetclient	scope_argscope_id
scope_path
iam_membermatching_scope_rrbsrB   
scope_rrbs	scope_rrbiam_scope_level_roleiam_project_level_role,another_scope_needs_project_level_permissionscopesr9   roles_to_checkr
prompt_msg	conditionscope_iam_policys                          r#   RunRemoveAppOperatorBinding.Run   s,   llG!!&&..224g,,W5K$$43D3D3FGK##))+I~~H'')J..tyy$**EJD66wIJ		499	$DJJ)F00@$[44Y^^DD
))**0&11)..A	+	 ""9-!  " 	iivj3 &EEdK(II$O 490##G,F	z	!88
4**5::6j ( 7#G$n ")##D67*;<AIq$))TZZ@@;?8 = " & 
N6&1  
6KV*Z@	

 	FMM&	


  fWA	j 1 8))


 
 
ii
2
9
9$ 11'DI&&866 44$ II	(
 #44Z@''
 !!*.>?II/0
!#	kk1172 )	,,Y^^< )r&    N)	__name__
__module____qualname____firstlineno____doc__classmethodr$   ro   __static_attributes__rq   r&   r#   r   r   &   s#    Ob  ,K=r&   r   c                     [         R                  " U[        R                  " U R                  5      S   [         R
                  5      =(       a%    U R                  U:H  =(       a    U R                  U:H  $ )NpredefinedRole)researchr   MessageToPyValuerB   
IGNORECASEr?   r"   )re   rB   r?   r"   s       r#   rL   rL     s[    ii


#
#INN
34D
E
-- #
 ..D
 # //U
"r&   )%rv   
__future__r   r   r   r{   apitools.base.pyr   +googlecloudsdk.api_lib.cloudresourcemanagerr   &googlecloudsdk.api_lib.container.fleetr   r	   r   googlecloudsdk.callioper
   *googlecloudsdk.command_lib.container.fleetr   1googlecloudsdk.command_lib.container.fleet.scopesr=   googlecloudsdk.command_lib.iamr   #googlecloudsdk.command_lib.projectsr5   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   DefaultUniverseOnlyReleaseTracksr   ALPHABETADeleteCommandr   rL   rq   r&   r#   <module>r      s    I &  ' 	 % D 9 C ( @ ; Q 3 E # * 2 D%%++T->->-C-CDt=t11 t= E t=n	r&   