
    M'                        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@                  " \RB                  RD                  \RB                  RF                  5       " S S\RH                  5      5       5       r%g)zCommand to add project-level and fleet scope-level IAM bindings and create a fleet scope RBAC role binding for an app operator.    )absolute_import)division)unicode_literalsN)encoding)projects_api)client)util)base)	resources)iam_util)labels_util)log)
properties)
console_ioc                   .    \ rS rSrSr\S 5       rS rSrg)AddAppOperatorBinding&   a
  Add project-level and fleet scope-level IAM bindings and create 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 or a custom role).

This command sets up the different permissions required for an app operator,
including usage of fleet scopes, connect gateway, logging, and metrics. The
authoritative list for adding 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 already has another binding for the scope.

## EXAMPLES

The following command:

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

* adds IAM policy binding: roles/gkehub.scopeViewer on `SCOPE`
* adds IAM policy binding: roles/gkehub.scopeViewerProjectLevel on
`PROJECT_ID`
* adds IAM policy binding: roles/logging.viewAccessor on `PROJECT_ID` with
condition where bucket corresponds to `SCOPE`
* creates fleet scope RBAC role binding: role `view` with a random ID
for group `people@google.com`.

---

The following command:

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

* adds IAM policy binding: roles/gkehub.scopeEditor on `SCOPE`
* adds IAM policy binding: roles/gkehub.scopeEditorProjectLevel on
`PROJECT_ID`
* adds IAM policy binding: roles/logging.viewAccessor on `PROJECT_ID` with
condition where bucket corresponds to `SCOPE`
* creates fleet scope RBAC role binding: role `edit` with a random ID
for user `person@google.com`.

---

The following command:

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

* adds IAM policy binding: roles/gkehub.scopeAdmin on `SCOPE`
* adds IAM policy binding: roles/gkehub.scopeEditorProjectLevel on
`PROJECT_ID`
* adds IAM policy binding: roles/logging.viewAccessor on `PROJECT_ID` with
condition where bucket corresponds to `SCOPE`
* creates fleet scope RBAC role binding: role `admin` with a random ID
for user `person@google.com`.

---

The following command:

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

* adds IAM policy binding: roles/gkehub.scopeViewer on `SCOPE`
* adds IAM policy binding: roles/gkehub.scopeEditorProjectLevel on
`PROJECT_ID`
* adds IAM policy binding: roles/logging.viewAccessor on `PROJECT_ID` with
condition where bucket corresponds to `SCOPE`
* creates fleet scope RBAC role binding: role `my-custom-role` with a random
ID for user `person@google.com`.

For any tailored IAM permissions required when using a custom role, the user
or group can separately be granted additional IAM permissions on the project.
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  UR                  SS9nUR                  S/ SQSS9  UR                  S[        SS9  [        R                  " U5        g )NSCOPEz>Name of the fleet scope for adding 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.z--role)admineditviewz;Predefined role to assign to principal (admin, edit, view).)choicesr   z--custom-rolez#Custom role to assign to principal.)
r   AddScopeResourceArgapi_utilVERSION_MAPReleaseTrackadd_mutually_exclusive_groupadd_argumentstrr   AddCreateLabelsFlags)clsparsergrouproledefs       >lib/surface/container/fleet/scopes/add_app_operator_binding.pyArgsAddAppOperatorBinding.Argsu   s    !!S--/0L ///>E	)  
 
*  
 1141@G)J  
 2  
 $$V,    c                 4	   UR                   nUc2  [        R                  R                  R                   R	                  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UR"                  bA  [        R$                  " UR"                  5      n[        R&                  " UR"                  5      n	O@[        R$                  " UR(                  5      n[        R&                  " UR(                  5      n	UR"                  n
UR+                  X%5      nU H  nUR                  UR                  :X  d  M  UR                   UR                   :X  d  M;  UR(                  R,                  (       a2  [.        R0                  " UR(                  5      S   R3                  5       nOUR(                  R4                  n[6        R8                  " SR;                  UUUUR<                  5      5          g    U
(       a  U
nOUR(                  n[>        R@                  " 5       (       a(  [>        RB                  " SR;                  UUUUUU	S9SSS9  [D        RF                  " U5      n[H        RJ                  " UUU	5        [        RL                  " X%5      n[N        RP                  " U[N        RR                  5        [H        RT                  " UUS	U5        [6        RV                  " S
5        URY                  U5      n[N        RZ                  " [\        R^                  " U R                  5       5      R`                  UUU5        URc                  UU5        [6        RV                  " S5        US-   SRe                  [g        S5       Vs/ s H  n[h        Rj                  " S5      PM     sn5      -   n[l        Rn                  " URp                  S9nURs                  URt                  Rv                  Rx                  S 5      R{                  5       nUR}                  UUR(                  U
UR                  UR                   US9$ s  snf )N)release_trackpredefinedRolezQ`{}` already has role `{}` for scope `{}` via an existing RBAC role binding: `{}`ag  The command:
  * adds IAM policy binding: `{scope_role}` on scope `{scope}`
  * adds IAM policy binding: `{proj_role}` on project `{proj}`
  * adds IAM policy binding: `roles/logging.viewAccessor` on project `{proj}` with a condition where the bucket corresponds to scope `{scope}`
  * creates a fleet scope RBAC role binding: role `{arg_role}` for `{member}`)scopeprojarg_rolemember
scope_role	proj_rolezDo you want to continueT)messageprompt_stringcancel_on_nozroles/logging.viewAccessorz Added project-level IAM bindingszAdded scope-level IAM bindingz/rbacrolebindings/    abcdef0123456789)	additions)namerolecustom_roleuserr(   labels)?projectr   VALUEScoreGetr   FleetClientr!   CONCEPTSr1   ParseNameRelativeNamescopes_utilIamMemberFromRbacrA   r(   r@   IamScopeLevelScopeRoleFromRbac IamProjectLevelScopeRoleFromRbacr?   ListScopeRBACRoleBindingsr0   r   MessageToPyValuelower
customRoler   errorformatr>   r   	CanPromptPromptContinueprojects_utilParseProjectr   AddIamPolicyBindingScopeLogViewConditionr   ValidateConditionArgumentCONDITION_FORMAT_EXCEPTION AddIamPolicyBindingWithConditionPrintGetScopeIamPolicyAddBindingToIamPolicyr   GetMessagesModuleBindingSetScopeIamPolicyjoinrangerandomchoicer   DiffrB   ApplymessagesRBACRoleBindingLabelsValue	GetOrNoneCreateScopeRBACRoleBinding)selfargsrC   fleetclient	scope_argscope_id
scope_path
iam_memberiam_scope_level_roleiam_project_level_roler@   
scope_rrbsexisting_rrbprinted_roleproject_ref	conditionscope_iam_policy_	scope_rrblabels_diffrB   s                        r*   RunAddAppOperatorBinding.Run   s   llG!!&&..224g$$43D3D3FGK##))+I~~H'')J..tyy$**EJ #(GG


  +KK


  )GG
))  +KK
))  ""K66wIJ"			dii	'L,>,>$**,L++!22<3D3DEEG  &**55,		""(&!!	#	
 	% #*  lYYl #F '#12 #  2%*  ,,W5K$$
 11'DI&&866 11$	 II01"44Z@""""4#4#4#67??	 !!*.>?II-. 	
	
''eBiHi6==!34iH
I	J 
 ""T[[9K,,88$ik  11YYYYjj 2   Is    R
 N)	__name__
__module____qualname____firstlineno____doc__classmethodr+   r   __static_attributes__r   r-   r*   r   r   &   s$    JX  -  -Dwr-   r   )&r   
__future__r   r   r   rg   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.scopesrL   googlecloudsdk.command_lib.iamr   #googlecloudsdk.command_lib.projectsrX   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   DefaultUniverseOnlyReleaseTracksr!   ALPHABETACreateCommandr   r   r-   r*   <module>r      s    F &  '  % D 9 C ( @ Q 3 E < # * 2 D%%++T->->-C-CDgD.. g E gr-   