o
    :Fd                  
   @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZmZ ejdddd	ejd
dddejde	g ddddejde	jde	jj dejde	jde	jj deje jejdd Zdd ZdS )    N)cli)cli_util)custom_types)RetryStrategyBuilderDEFAULT_RETRY_STRATEGYretry_checkerszraw-requesta  Makes a raw request against an OCI service based on a provided URI, HTTP method and payload. This operation currently only supports JSON payloads.
This operation will output a JSON structure that looks like:


    {
        "data": <a JSON array or object containing the parsed response body>,
        "headers": <a JSON object where each header is a key and the value is the header value>,
        "status": <the HTTP status code and reason, e.g. '200 OK', '404 Not Found'>
    }
z*Makes a raw request against an OCI service)helpZ
short_helpz--target-uriTz#The URI to make the request against)requiredr   z--http-method)ZDELETEZGETHEADZPOSTZPUTZPATCHzThe HTTP method to use)typer	   r   z--request-bodyz)Data to send in the body of the request. )r   r   z--request-headersz3Additional headers to send as part of the request. c                 C   s   t | |||| d S )N)_make_raw_request)ctx
target_urihttp_methodrequest_bodyrequest_headers r   ;usr/lib/python3.10/site-packages/oci_cli/raw_request_cli.pymake_raw_request   s   r   c              	   C   s  | j d r
td| j d dkrtd| j d r!dtjjj_t	| }d}|d ur?|
 dkr?td	|d
d}t|}i }|rKtd|d
d}t}	| j d rht j| j d djddjtjdd }	| j d rrtj }	t| Q}
|	j|
j||||d}d|j|jdd |j  D d}z| }|r|!||d< n||d< W n t"y   |j#|d< Y nw t$t%| W d    d S 1 sw   Y  d S )NZendpointz>The --endpoint parameter cannot be specified with this commandoutputtablez:The table output format is not supported with this commanddebug    r   Zcamelize_keysFr   max_attempts)r   iX  )Ztotal_elapsed_time_secondsT)Zservice_error_retry_configZservice_error_retry_on_any_5xxZno_retry)methodurldataheadersz{} {}c                 S   s   i | ]\}}||qS r   r   ).0keyvaluer   r   r   
<dictcomp>\   s    z%_make_raw_request.<locals>.<dictcomp>)statusr   r   )&objclickZ
UsageErrorsixZmovesZhttp_clientZHTTPConnectionZ
debuglevelr   Z$get_jmespath_expression_from_contextstripZparse_json_parameterjsondumpsr   r   Zadd_max_attemptsZadd_total_elapsed_timeZadd_service_error_checkr   ZRETRYABLE_STATUSES_AND_CODESZget_retry_strategyociretryZNoneRetryStrategyZbuild_raw_requests_sessionZmake_retrying_callZrequestformatZstatus_codereasonr   itemssearch
ValueErrortextprintZpretty_print_format)r   r   r   r   r   Zjmespath_expressionZparsed_request_bodyZrequest_body_as_dictZadditional_headersZretry_strategyZrequests_sessionresponseZresult_dictZdict_from_response_bodyr   r   r   r   %   s`   









	"r   )r%   r(   r*   Z	six.movesr&   Zoci_cli.cli_rootr   oci_clir   r   Z	oci.retryr   r   r   commandoptionZCliCaseInsensitiveChoiceZCLI_COMPLEX_TYPEZcli_complex_typeZCOMPLEX_TYPE_HELPhelp_optionZpass_contextZwrap_exceptionsr   r   r   r   r   r   <module>   s(   	
