
                         x   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d
lmZ dZedz   ZddiZe	j$                   e	j&                  e	j(                  j*                  e	j(                  j,                  e	j(                  j.                         G d de	j0                                      Zy)z!services api-keys create command.    )absolute_import)division)unicode_literals)apikeys)services_util)base)common_flags)log)
propertieszgcloud services operations zwait {0}EXAMPLESa  
        To create a key with display name and allowed IPs specified:

          $ {command} --display-name="test name" --allowed-ips=2620:15c:2c4:203:2776:1f90:6b3b:217,104.133.8.78

        To create a key with annotations:

         $ {command} --annotations=foo=bar,abc=def

        To create a key with user-specified key ID:

          $ {command} --key-id="my-key-id"

        To create a key with allowed referrers restriction:

          $ {command} --allowed-referrers="https://www.example.com/*,http://sub.example.com/*"

        To create a key with allowed IOS app bundle IDs:

          $ {command} --allowed-bundle-ids=my.app

        To create a key with allowed Android application:

          $ {command} --allowed-application=sha1_fingerprint=foo1,package_name=bar.foo --allowed-application=sha1_fingerprint=foo2,package_name=foo.bar

        To create a key with allowed API targets (service name only):

          $ {command} --api-target=service=bar.service.com --api-target=service=foo.service.com

        To create a key with service account:

          $ {command} --service-account=my-service-account

        To create a key with allowed API targets (service and methods are
        specified):

          $ {command} --flags-file=my-flags.yaml

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

        ```
        - --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)CreatezCreate an API key.c                     t        j                  | d       t        j                  |        t        j                  | d       t        j                  |        t
        j                  j                  |        y )Nz	to create)parsersuffix)r	   display_name_flagadd_key_create_argskey_id_flagservice_account_flagr   
ASYNC_FLAGAddToParser)r   s    'lib/surface/services/api_keys/create.pyArgszCreate.ArgsY   sP    ""&E$$V,F;?%%f-OO'    c                    t         j                  j                  j                  j	                         }t        j                         }|j                  }|j                  |j                               }|j                  d      r|j                  |_        |j                  d      r,|j                  |j                        |j                  _        n|j                  d      r,|j#                  |j$                        |j                  _        n|j                  d      r,|j)                  |j*                        |j                  _        nF|j                  d	      r5|j/                  t        j0                  ||      
      |j                  _        |j                  d      r%t        j4                  ||      |j                  _        |j                  d      rt        j8                  ||      |_        |j                  d      r|j<                  |_        |j                  d      r2|jA                  t        jB                  |      ||jD                        }n&|jA                  t        jB                  |      |      }|jF                  jI                  |      }|jJ                  s|jL                  rOtN        jQ                  |jR                        }tT        jV                  jY                  djQ                  |             |S t[        j\                  |jR                  t
        j^                        }t[        j`                  |       |S )zRun command.

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

    Returns:
      None
    )restrictionsdisplay_nameallowed_referrers)allowedReferrersallowed_ips)
allowedIpsallowed_bundle_ids)allowedBundleIdsallowed_application)allowedApplications
api_targetannotationsservice_accountkey_id)parentv2KeykeyId)r*   r+   zcAsynchronous operation is in progress... Use the following command to wait for its completion:
 {0})1r   VALUEScoreproject	GetOrFailr   GetClientInstanceMESSAGES_MODULEV2KeyV2RestrictionsIsSpecifiedr   displayNameV2BrowserKeyRestrictionsr   r   browserKeyRestrictionsV2ServerKeyRestrictionsr    serverKeyRestrictionsV2IosKeyRestrictionsr"   iosKeyRestrictionsV2AndroidKeyRestrictionsGetAllowedAndroidApplicationsandroidKeyRestrictionsGetApiTargets
apiTargetsGetAnnotationsr'   r(   serviceAccountEmail)ApikeysProjectsLocationsKeysCreateRequestGetParentResourceNamer)   projects_locations_keysr   doneasync_OP_WAIT_CMDformatnamer
   statusPrintr   WaitOperationGetOperationPrintOperationWithResponse)	selfargs
project_idclientmessages	key_protorequestopcmds	            r   Runz
Create.Runa   s    ""''//99;J&&(F%%HH,C,C,EFI'"//i+,

+
+#55 ,  3
 
		-	(

*
*d6F6F
*
G 2 
		.	/2:2O2O22 3P 3i/ 
		/	0

+
+")"G"G# ,  3 %*1*?*?h*Oi'&%44T8Di)*&*&:&:i#!BB..z: C g BB..z:) C g 
	'	'	.	.w	7B77	  )

  &s	

 	&&rww0D0DEb,,R0Ir   N)	__name__
__module____qualname____doc__staticmethodr   rZ   _DETAILED_HELPdetailed_help r   r   r   r   R   s'    
 ( (DJ !-r   r   N)r^   
__future__r   r   r   googlecloudsdk.api_lib.servicesr   r   googlecloudsdk.callioper   #googlecloudsdk.command_lib.servicesr	   googlecloudsdk.corer
   r   OP_BASE_CMDrI   r`   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAGACreateCommandr   rb   r   r   <module>rp      s    ( &  ' 3 9 ( < # *+J& 1 1h T..33T5F5F5I5IP!T P! P!r   