
    ,                         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 d
 Zd Zd Zd Zd Zy)z%Utils for Fleet memberships commands.    )absolute_import)division)unicode_literals)base)
exceptions)api_util)	resources)errorsc                 2    ~ ~|j                   dz   |_         |S )zSet the appropriate request path in project attribute for initializeHub requests.

  Args:
    ref: reference to the membership object.
    args: command line arguments.
    request: API request to be issued

  Returns:
    modified request
  z/locations/global/memberships)projectrefargsrequests      Blib/googlecloudsdk/command_lib/container/fleet/memberships/util.pySetInitProjectPathr      s     
4OO&EE'/	.    c                    ~ |j                   j                  d      }|dk(  rt        d|j                   z        |j                  d      r&|j                   d| dz   |j                  z   |_         |S |j                   d| dz   |_         |S )zSet parent collection with location for created resources.

  Args:
    ref: reference to the membership object.
    args: command line arguments.
    request: API request to be issued

  Returns:
    modified request
  /zInvalid parent collection: %slocationNz/-)parentrfind
ValueErrorIsKnownAndSpecifiedr   )r   r   r   indexs       r   SetParentCollectionr   +   s     

..

s
#%
b[
4w~~E
FF	j)^^FU+c1DMMAGN 
. ^^FU+d2GN	.r   c                     ~ |j                  d      rMt        j                  |      rt        j                  |      |_        |S t        j
                  |      |_        |S t        j                  dd      )zSet membership location for requested resource.

  Args:
    ref: reference to the membership object.
    args: command line arguments.
    request: API request to be issued

  Returns:
    modified request
  
membership
MEMBERSHIPz(membership is required for this command.)r   r	   MembershipLocationSpecifiedMembershipResourceNamenameSearchMembershipResourcecalliope_exceptionsRequiredArgumentExceptionr   s      r   SetMembershipLocationr'   C   st     
	l+,,T255d;gl 
. 77=gl
 
. 
7
7@B Br   c                 `   ~ t        j                  |      rt        j                  |      }nt        j                  |      }|j                  j                         }t        j                  ||      }g }dx}}|j                  d      r"|j                  d       |j                  d      }|t        j
                  j                  k7  r3|j                  d      r"|j                  d       |j                  d      }|j                  d      s"|j                  d      s|j                  d      r|j                  d	       d
j                  |      }t        j                  |||||||j                  d      |j                  d      |j                  d      ddd|j                  d            }	|	S )zExecute update membership request.

  Args:
    ref: API response from update membership call
    args: command line arguments.

  Returns:
    response
  Nexternal_id
externalId
infra_typeinfrastructureTypeclear_labelsupdate_labelsremove_labelslabels,async)	r)   r+   r-   r.   r/   
issuer_url	oidc_jwksapi_server_version
async_flag)r	   r!   r"   r$   calliope_commandReleaseTrackr   GetMembershipGetValueappendcalliope_baseGAjoinUpdateMembership)
r   r   r#   release_trackobjupdate_fieldsr)   r+   update_maskresponses
             r   ExecuteUpdateMembershipRequestrE   \   sw    
**40++D1D--d3D ''446-t]3#-!!+
	]]=!&--.Km003339-.|,J	]]>"dmm'--8"'+&&
	==0MM/2MM/2w')( 
/r   c                     |dv rdndj                  |      }| r| dk(  rdj                  |      S d| v rdj                  |      S d| v rd	j                  |      S t        j                  d
      )a  Get the appropriate Connect Gateway endpoint.

  This function checks the environment endpoint overide configuration for
  Fleet and uses it to determine which Connect Gateway endpoint to use.
  The overridden Fleet value will look like
  https://autopush-gkehub.sandbox.googleapis.com/.

  When there is no override set, this command will return a Connect Gateway
  prod endpoint. When an override is set, an appropriate non-prod endpoint
  will be provided instead.

  For example, when the overridden value looks like
  https://autopush-gkehub.sandbox.googleapis.com/,
  the function will return
  autopush-connectgateway.sandbox.googleapis.com.

  Regional prefixes are supported via the location argument. For example, when
  the overridden value looks like
  https://autopush-gkehub.sandbox.googleapis.com/ and location is passed in as
  "us-west1", the function will return
  us-west1-autopush-connectgateway.sandbox.googleapis.com.

  Args:
    endpoint_override: The URL set as the API endpoint override for 'gkehub'.
      None if the override is not set.
    location: The location against which the command is supposed to run. This
      will be used to dynamically modify the service name to a location-specific
      value. If this is the value 'global' or None, a global service name is
      returned.

  Returns:
    The service name to use for this command invocation, optionally modified
    to target a specific location.

  Raises:
    UnknownApiEndpointOverrideError if the Fleet API endpoint override is not
    one of the standard values.
  )globalN z{}-zhttps://gkehub.googleapis.com/z{}connectgateway.googleapis.comzautopush-gkehubz0{}autopush-connectgateway.sandbox.googleapis.comzstaging-gkehubz/{}staging-connectgateway.sandbox.googleapis.comgkehub)formatr
   UnknownApiEndpointOverrideError)endpoint_overrider   prefixs      r   GetConnectGatewayServiceNamerN      s    R --25<<3I&
	>	> -33F;;--=DDVLL,,<CCFKK

0
0
::r   N)__doc__
__future__r   r   r   googlecloudsdk.callioper   r<   r   r%   *googlecloudsdk.command_lib.container.fleetr   r	   6googlecloudsdk.command_lib.container.fleet.membershipsr
   r   r   r'   rE   rN    r   r   <module>rU      s<    , &  ' 9 E ? @ I 020f5;r   