
    =                     p    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	efd
Zd Zy)z3Calls cloud run service of a Google Cloud Function.    )absolute_import)division)unicode_literals)util)config_helper)	call_util)storeimpersonate_service_accountc                     d}t        j                  |dd      }t        j                  ||        t        j                  |      }|j
                  }|S )a  Generate an expiring Google-signed OAuth2 identity token.

  Args:
    impersonate_service_account: bool, whether to enable a service account
      impersonationwhen generating the token.

  Returns:
    token: str, expiring Google-signed OAuth2 identity token
  NT)allow_account_impersonationuse_google_auth)is_impersonated_credential)r	   LoadRefreshr   
Credentialid_token)r
   accountcred
credentialtokens        ;lib/googlecloudsdk/command_lib/functions/v2/call/command.pyGenerateIdTokenr      sU     ' 
"&	
$ --1LM''-* 

%	,    c                    t        j                  |      }|j                  }| j                  j                  j                         }|j                  j                  |j                  |j                                     }t        j                  | |d|       |j                  j                  }t        | j                  d            }ddj!                  |      i}t        j"                  || |      S )z Call a v2 Google Cloud Function.)release_track)namev2r
   Authorizationz	Bearer {})extra_headers)v2_api_utilGetClientInstanceMESSAGES_MODULECONCEPTSr   Parseprojects_locations_functionsGet2CloudfunctionsProjectsLocationsFunctionsGetRequestRelativeNamer   UpdateHttpTimeoutserviceConfigurir   IsSpecifiedformatMakePostRequest)	argsr   	v2_clientv2_messagesfunction_reffunctioncloud_run_urir   auth_headers	            r   Runr6   >   s    ++-H)))+##))+, 3377DD((* E ,-( dHdMB((,,-
$**+HI
J% +"4"4U";<+		"	"T
6 6r   N)F)__doc__
__future__r   r   r   #googlecloudsdk.api_lib.functions.v2r   r    !googlecloudsdk.command_lib.configr   $googlecloudsdk.command_lib.functionsr   googlecloudsdk.core.credentialsr	   boolr   r6    r   r   <module>r?      s1    : &  ' C ; : 1   F6r   