
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ  G d
 de	j                        Zy)z1Command to update Membership Binding information.    )absolute_import)division)unicode_literals)client)util)base)	resources)labels_utilc                   &    e Zd ZdZed        Zd Zy)Updatea  Update the Binding in a Membership.

  This command can fail for the following reasons:
  * The Membership specified does not exist.
  * The Binding does not exist in the Membership.
  * The caller does not have permission to access the Membership/Binding.
  * The Scope specified does not exist.
  * The caller did not specify the location (--location) if referring to
  location other than global.

  ## EXAMPLES

  To update the binding `BINDING_NAME` in global membership `MEMBERSHIP_NAME`
  in the active project:

    $ {command} BINDING_NAME --membership=MEMBERSHIP_NAME

  To update a Binding `BINDING_NAME` associated with regional membership
  `MEMBERSHIP_NAME`, provide the location LOCATION_NAME for the Membership where
  the Binding belongs along with membership name and associated
  Scope `SCOPE_NAME`.

  $ {command} BINDING_NAME --membership=MEMBERSHIP_NAME --scope=SCOPE_NAME
    --location=LOCATION_NAME

  c                 2   t        j                  |t        j                  | j	                            d       |j                  d      }t        j                  |dt        j                  | j	                            d|       t        j                  |       y )NzrName of the Membership Binding to be updated.Must comply with RFC 1123 (up to 63 characters, alphanumeric and '-'))api_versionbinding_helpT)requiredz--scopez*The Fleet Scope to bind the membership to.)	flag_namer   
scope_helpgroup)	r	   AddMembershipBindingResourceArgr   VERSION_MAPReleaseTrackadd_mutually_exclusive_groupAddScopeResourceArgr
   AddUpdateLabelsFlags)clsparserr   s      :lib/surface/container/fleet/memberships/bindings/update.pyArgszUpdate.Args8   s    --$$S%5%5%78$	 ///>E!!$$S%5%5%78? $$V,    c                    t        j                  | j                               }g }|j                  t	        j
                  |            }t        j                  j                  |      }|j                  |j                  j                  j                  |j                        j                         }|r|j                  d       dD ]%  }|j!                  |      s|j                  |       ' d }|j"                  j$                  j'                         2|j"                  j$                  j'                         j)                         }|sy |j+                  t	        j
                  |      ||dj-                  |            S )N)release_tracklabels)fleetscope,)r#   r!   mask)r   FleetClientr   GetMembershipBindingr	   MembershipBindingResourceNamer
   DiffFromUpdateArgsApplymessagesMembershipBindingLabelsValuer!   	GetOrNoneappendIsKnownAndSpecifiedCONCEPTSr#   ParseRelativeNameUpdateMembershipBindingjoin)	selfargsfleetclientr%   current_bindinglabels_diff
new_labelsflagr#   s	            r   Runz
Update.RunM   sC   $$43D3D3FGKD!66//5O
 ""11$7K""..:: ik  
kk("		!	!$	'D # E}}  ".mm!!'')668e..//5XXd^	 /  r   N)__name__
__module____qualname____doc__classmethodr   r>    r   r   r   r      s     6 - -(r   r   N)rB   
__future__r   r   r   &googlecloudsdk.api_lib.container.fleetr   r   googlecloudsdk.callioper   *googlecloudsdk.command_lib.container.fleetr	   $googlecloudsdk.command_lib.util.argsr
   UpdateCommandr   rD   r   r   <module>rK      s6    8 &  ' 9 7 ( @ <NT Nr   