
                         N   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edz   ZddiZ e	j"                  e	j$                  j&                  e	j$                  j(                  e	j$                  j*                         G d de	j,                               Zy)z!services api-keys update command.    )absolute_import)division)unicode_literals)apikeys)services_util)base)common_flags)logzgcloud services operations zwait {0}EXAMPLESa  
        To remove all restrictions of the key:

          $ {command} projects/myproject/keys/my-key-id --clear-restrictions

        To update display name and set allowed ips as server key restrictions:

          $ {command} projects/myproject/keys/my-key-id --display-name="test name" --allowed-ips=2620:15c:2c4:203:2776:1f90:6b3b:217,104.133.8.78

        To update annotations:

          $ {command} projects/myproject/keys/my-key-id --annotations=foo=bar,abc=def

        To update key's allowed referrers restriction:

          $ {command} projects/myproject/keys/my-key-id --allowed-referrers="https://www.example.com/*,http://sub.example.com/*"

        To update key's allowed ios app bundle ids:

          $ {command} projects/myproject/keys/my-key-id --allowed-bundle-ids=my.app

        To update key's allowed android application:

          $ {command} projects/myproject/keys/my-key-id --allowed-application=sha1_fingerprint=foo1,package_name=bar1 --allowed-application=sha1_fingerprint=foo2,package_name=bar2

        To update keys' allowed api target with multiple services:

          $ {command} projects/myproject/keys/my-key-id --api-target=service=bar.service.com --api-target=service=foo.service.com

        To update keys' allowed api target with service and method:

          $ {command} projects/myproject/keys/my-key-id  --flags-file=my-flags.yaml

          The content of 'my-flags.yaml' is as following:

          ```
            - --api-target:
                service: "foo.service.com"
            - --api-target:
                service: "bar.service.com"
                methods:
                - "foomethod"
                - "barmethod"
            ```
        c                   *    e Zd ZdZed        Zd ZeZy)UpdatezUpdate an API key's metadata.c                     t        j                  | d       t        j                  | d       t        j                  |        t        j
                  j                  |        y )Nz	to update)parsersuffix)r	   key_flagdisplay_name_flagadd_key_update_argsr   
ASYNC_FLAGAddToParser)r   s    'lib/surface/services/api_keys/update.pyArgszUpdate.ArgsU   sB    <""&E$$V,OO'    c                 X   t        j                         }|j                  }|j                  j                  j                         }g }|j                  |j                         |j                               }|j                  d      r,|j                  d       t        j                  ||      |_        |j                  d      r"|j                  d       |j                  |_        |j                  d      r|j                  d       |j                  d      r|j                  d       n|j                  d      r=|j                  d       |j                  |j                   	      |j"                  _        n|j                  d
      r=|j                  d       |j'                  |j(                        |j"                  _        n|j                  d      r=|j                  d       |j-                  |j.                        |j"                  _        nW|j                  d      rF|j                  d       |j3                  t        j4                  ||            |j"                  _        |j                  d      r6|j                  d       t        j8                  ||      |j"                  _        |j=                  |j                         dj?                  |      |      }|j@                  jC                  |      }|jD                  s|jF                  rOtH        jK                  |jL                        }	tN        jP                  jS                  djK                  |	             |S tU        jV                  |jL                  t         jX                        }tU        jZ                  |       |S )zRun command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      None
    )namerestrictionsannotationsdisplay_nameclear_annotationsclear_restrictionsr   allowed_referrersz%restrictions.browser_key_restrictions)allowedReferrersallowed_ipsz$restrictions.server_key_restrictions)
allowedIpsallowed_bundle_idsz!restrictions.ios_key_restrictions)allowedBundleIdsallowed_applicationz%restrictions.android_key_restrictions)allowedApplications
api_targetzrestrictions.api_targets,)r   
updateMaskv2KeyzcAsynchronous operation is in progress... Use the following command to wait for its completion:
 {0}).r   GetClientInstanceMESSAGES_MODULECONCEPTSkeyParseV2KeyRelativeNameV2RestrictionsIsSpecifiedappendGetAnnotationsr   r   displayNameV2BrowserKeyRestrictionsr    r   browserKeyRestrictionsV2ServerKeyRestrictionsr"   serverKeyRestrictionsV2IosKeyRestrictionsr$   iosKeyRestrictionsV2AndroidKeyRestrictionsGetAllowedAndroidApplicationsandroidKeyRestrictionsGetApiTargets
apiTargets(ApikeysProjectsLocationsKeysPatchRequestjoinprojects_locations_keysPatchdoneasync_OP_WAIT_CMDformatr   r
   statusPrintr   WaitOperationGetOperationPrintOperationWithResponse)
selfargsclientmessageskey_refupdate_mask	key_protorequestopcmds
             r   Runz
Update.Run\   s    &&(F%%Hmm%%'GK!!#(2I2I2K  MI&'%44T8Di'("//i+,',-(			-	.BC8@8Y8Y!33 9Z 95	5M*AB7?7W7W'' 8X 8)	401>?4<4Q4Q!44 5R 56	112BC8@8Y8Y ' E Eh!  9Z 9!	5 
		,	'56,3,A,A(-	)??!!#88K( @ G 
	'	'	-	-g	6B77	  )

 --3VC[	: 	&&rww0D0DEb,,R0Ir   N)	__name__
__module____qualname____doc__staticmethodr   rZ   DETAILED_HELPdetailed_help r   r   r   r   O   s'     &( (@B  -r   r   N)r^   
__future__r   r   r   googlecloudsdk.api_lib.servicesr   r   googlecloudsdk.callioper   #googlecloudsdk.command_lib.servicesr	   googlecloudsdk.corer
   OP_BASE_CMDrI   r`   ReleaseTracksReleaseTrackALPHABETAGAUpdateCommandr   rb   r   r   <module>ro      s    ( &  ' 3 9 ( < #+J&,	/d T..33T5F5F5I5IK T K K r   