
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJr  SSK	J
r
  SS	K	Jr  SS
KJr  SrSr\S0rS rSS jrS rg)z1Utilities used by gcloud functions call commands.    )absolute_import)division)unicode_literalsN)base)parser_extensions)
properties)requests)timeszContent-Type)idsourcespecversiontype
dataschemasubjecttimeapplication/jsonc                 &   0 nSn[        U R                  5       5       HF  u  p4UR                  5       nUS:X  a  UnM  U[        ;   a	  XASU-   '   M2  US:X  a
  XA[        '   MB  XAU'   MH     [        U;  a	  SU[        '   [
        R                  " U5      U4$ )a  Convert CloudEvents structured format to binary format.

Args:
  request_data_json: dict, the parsed request body data

Returns:
  cloudevent_data: str, the CloudEvent expected data with attributes in header
  cloudevent_headers: dict, the CloudEvent headers
Ndatazce-datacontenttyper   )listitemslower_FIELDS_CONTENT_TYPEjsondumps)request_data_jsoncloudevent_headerscloudevent_datakeyvaluenormalized_keys         5lib/googlecloudsdk/command_lib/functions/call_util.py_StructuredToBinaryDatar$   +   s     /*0023jcYY[No	7	"16~-.	,	,*/'+0( 4 ,,(:}%	O	$&8	88    c                    Sn[         nUR                  (       a  UR                  n[         nO<UR                  (       a+  [        [        R
                  " UR                  5      5      u  p4U(       a*  [        UR                  5       UR                  5       -  5      n[        R                  " 5       nUR                  U UUS9nUR                  5         UR                  $ )a   Makes an HTTP Post Request to the specified url with data and headers from args.

Args:
  url: The URL to send the post request to
  args: The arguments from the command line parser
  extra_headers: Extra headers to add to the HTTP post request

Returns:
  str: The HTTP response content
N)urlr   headers)_DEFAULT_HEADERSr   cloud_eventr$   r   loadsdictr   core_requests
GetSessionpostraise_for_statuscontent)r'   argsextra_headersrequest_datar(   requests_sessionresponses          r#   MakePostRequestr7   I   s     ,'	YY99LG3

4##$&L 7==?]%8%8%::;G"--/""
 # ( 			r%   c                    U[         R                  R                  [         R                  R                  4;   Ga  US:X  a  SOSnU R                  (       a  [        U R                  5      nOUS:X  aG  UR                  (       a6  [        [        R                  " UR                  SS9R                  S-   5      nOTUS:X  aN  UR                  (       a=  UR                  R                  (       a"  [        UR                  R                  5      S-   n[        R                  R                  R                  R                  U5        gg)	zUpdate core/http_timeout using args and function timeout.

Args:
  args: The arguments from the command line parser
  function: function definition
  api_version: v1 or v2
  release_track: ALPHA, BETA, or GA
v1i  i  s)default_suffix   v2N)r   ReleaseTrackALPHABETAtimeoutintr
   ParseDurationtotal_secondsserviceConfigtimeoutSecondsr   VALUEScorehttp_timeoutSet)r2   functionapi_versionrelease_trackrA   s        r#   UpdateHttpTimeoutrN   k   s     t((..0A0A0F0FGG D(cdG||DLL!g		!1!1


sMg 	t""""11H**99:R?g''++G4# Hr%   )N)__doc__
__future__r   r   r   r   googlecloudsdk.callioper   r   googlecloudsdk.corer   r	   r-   googlecloudsdk.core.utilr
   r   r   r)   r$   r7   rN    r%   r#   <module>rU      sQ    8 &  '  ( 5 * 9 *  "#56 9<D5r%   