o
    :F¶d™t  ã                    @   sà  d dl mZ eƒ Zd dlZd dlmZmZ d dlZd dl	Z	d dl
Zd dlZd dlmZ d dlZd dlZd dlZd dlmZ d dlmZ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# ej$ej%d ej&ej'ej(ej)ej*gZ+dZ,dZ-dZ.dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4dd „ Z5d!d"„ Z6d#d$„ Z7d%d&„ Z8ej9d'ed(e:d(d(d)d*ej;› d+ej<› d,d-ej=ed.d/d0d1ej>d2d(d3e7d3d(d4ej?› d5d6ej>d7d(d3e8d3d(d8d6ej>d9ed(e0d:d;ej>d<eeƒd3d=d>ej>d?d@ej@d(d(e/dAejA› d,dBej>dCdDdEdFdGdHej>dIe0dJdKej>dLe0dMdKej>dNd(e,dOej>dPdQejBe0dRdSej>dTdUejBe0dVdSej>dWe0dXdKej>dYejCdZd[gd\d]d^ej>d_d`ejD› dadHej>dbd(dcdOej>ddejCe+d\dejEejFdfd^ej>dgdhdHej>did(d(e.djej>dkd(e-dlej>dmd(dndOej>doejBdpd^ej>dqdrd(dsdOej>dtdud(dvej<› d,dOej>dwdxdyd(dzdOejGd{d|„ ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒZHd}d~„ ZIdd€„ ZJdd‚„ ZKdƒd„„ ZLdS )…é    )Údefault_timerN)ÚDEFAULT_LOCATIONÚDEFAULT_PROFILE)ÚSentinel)Ú__version__)Úparameter_aliasÚCommandGroupWithAlias)Úhelp_text_producer)Úcli_util)Úcli_constants)ÚOrderedDict)Úrequests)Úcli_metrics)Úcli_interactive)Úservice_mapping)Úlevela  Use a realm-specific endpoint, instead of the default region-wide endpoint.

Example::
    oci os ns get --realm-specific-endpoint

With this flag, your request will be made to a realm-specific service endpoint, such as, "https://myNamespace.objectstorage.us-phoenix-1.oci.oraclecloud.com". Use the --debug option to identify which endpoint is used for your request.

This flag has priority over the environment variable OCI_REALM_SPECIFIC_SERVICE_ENDPOINT_TEMPLATE_ENABLED.

To use this flag by default, set this flag to true in your OCI CLI-specific configuration file. For more information, see https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliconfigure.htm

If the flag is used for a service that does not support such feature, the default region-wide endpoint will be used.
a!  Complex input, such as arrays and objects, are passed in JSON format.

When passed the name of an option which takes complex input, this will print out example JSON of what needs to be passed to that option.
Example::
    oci compute instance launch --generate_param_json_input_r agent-config > example.json

    cat example.json
Output::

    {
      "areAllPluginsDisabled": true,
      "isManagementDisabled": true,
      "isMonitoringDisabled": true,
      "pluginsConfig": [
        {
          "desiredState": "string",
          "name": "string"
        },
        {
          "desiredState": "string",
          "name": "string"
        }
      ]
    }

Edit the example.json file with correct values and use it as below ::

    oci compute instance launch --agent-config file://example.json

a6  Prints out a JSON document which represents all possible options that can be provided to this command.

This JSON document can be saved to a file, modified with the appropriate option values, and then passed back via the --from-json option. This provides an alternative to typing options out on the command line.
Example::
    oci os bucket get --generate_full_command_json_input_r  > example.json
    cat example.json
Output::

    {
      "bucketName": "string",
      "fields": [
        "approximateCount|approximateSize|autoTiering"
      ],
      "ifMatch": "string",
      "ifNoneMatch": "string",
      "name": "string",
      "namespace": "string",
      "namespaceName": "string"
    }

Edit the example.json file with correct values and use it as below ::

    oci os bucket get --from-json file://example.json
c                 C   s$  t j t j tj¡¡}t j t j tj¡¡}t j t j |¡¡}i i i i i dœ| _d }tjt j	v r?t j t j t j	tj ¡¡}t
jd d d}t j |¡rX| |¡ t| |ƒ |S |rlt j |¡rl| |¡ t| |ƒ |S t j |¡r~| |¡ t| |ƒ |S t j |¡r| |¡ t| |ƒ |S |S )N)Úcanned_queriesÚglobal_command_aliasÚcommand_sequence_aliasÚparameter_aliasesÚsettings)ÚinterpolationÚdefault_section)ÚosÚpathÚ
expandvarsÚ
expanduserr   ÚCLI_RC_DEFAULT_LOCATIONZCLI_RC_FALLBACK_LOCATIONÚobjZOCI_CLI_RC_FILE_ENV_VARÚenvironÚconfigparserÚConfigParserÚexistsÚreadÚ,populate_aliases_canned_queries_and_settings)ÚctxÚparamÚvalueZexpanded_rc_default_locationZexpanded_rc_fallback_locationÚfile_locationZfile_location_from_envÚparser_without_defaults© r*   ú4usr/lib/python3.10/site-packages/oci_cli/cli_root.pyÚeager_load_cli_rc_fileu   s<   û	







r,   c                 C   sB   |r||j kr|jtjv rtj|j tjv rtjtj|j  S |S ©N)ÚdefaultÚnamer   ZOCI_CLI_PARAM_TO_ENV_MAPr   r   )r%   r&   r'   r*   r*   r+   Úread_values_from_env«   s   r0   c                 C   s,   t | |ƒ t| |ƒ t| |ƒ t| |ƒ d S r-   )Úpopulate_canned_queriesÚpopulate_command_aliasesÚpopulate_parameter_aliasesÚpopulate_settings)r%   r)   r*   r*   r+   r$   ³   s   


r$   c                 C   s<   t |tjƒ}i }|r|D ]
}|d ||d < q|| jd< d S )Né   r   r   )Úget_section_without_defaultsr   Z$CLI_RC_GENERIC_SETTINGS_SECTION_NAMEr   )r%   r)   Zraw_settingsr   Zsettingr*   r*   r+   r4   º   s   r4   c                 C   s˜   t |tjƒ}i }i }|D ]3}d|d vr|d ||d < q|d  d¡}d |d d… ¡}||vr5i ||< |d || |d < q|| jd< || jd< d S )NÚ.r5   r   ú éÿÿÿÿr   r   )r6   r   Z#CLI_RC_COMMAND_ALIASES_SECTION_NAMEÚsplitÚjoinr   )r%   r)   Zraw_command_aliasesZglobal_aliasesZcommand_sequenced_aliasesÚaliasZsplit_targetZcommand_chainr*   r*   r+   r2   Å   s   
r2   c                 C   s
  t |tjƒ}i }|D ]B}|d  d¡sq
|d  d¡s5t|d ƒdkr5tjtjd |d ¡ddt	j
d |d	 |vrAg ||d	 < ||d	   |d ¡ q
|| jd
< |t_tƒ }| t | j¡¡ | t | jj¡¡ t|ƒdkrƒtjtjd |¡ddt	j
d d S d S )Nr   ú-z--é   z“Could not create an alias for {} as aliases need to be prefixed with '--' or be a single dash followed by a single letter. For example: --alias, -aÚred©Zfg©Úfiler5   r   Ú
)r6   r   Z!CLI_RC_PARAM_ALIASES_SECTION_NAMEÚ
startswithÚlenÚclickÚechoÚstyleÚformatÚsysÚstderrÚappendr   r   ÚALIASESÚsetÚupdateZshim_in_aliasesÚcommandZadd_alias_to_command_paramsÚparamsr;   )r%   r)   Zraw_parameter_aliasesZcanonical_param_to_aliasr<   Z
collisionsr*   r*   r+   r3   à   s0   ÿü
$ÿr3   c                 C   s0   t |tjƒ}|rt|ƒ| jd< d S i | jd< d S )Nr   )r6   r   Z"CLI_RC_CANNED_QUERIES_SECTION_NAMEÚdictr   )r%   r)   Zraw_canned_queriesr*   r*   r+   r1     s   r1   c                 C   s   |   |¡sg S |  |¡S r-   )Úhas_sectionÚitems)r)   Úsection_namer*   r*   r+   r6     s   

r6   c              
   C   s(  |sd S t ƒ }t dt¡ d¡}zt tj¡}| 	¡  W n• tj
jy; } zt t d¡ |¡¡ W Y d }~n×d }~w tj
jyY } zt t d¡ |¡¡ W Y d }~n¹d }~w tj
jyw } zt t d¡ |¡¡ W Y d }~n›d }~w tj
jy• }	 zt t d¡ |	¡¡ W Y d }	~	n}d }	~	w ty± }
 zt t d¡ |
¡¡ W Y d }
~
nad }
~
ww t d|j d	¡tj¡}|D ]}|d ||d
  ¡ < qÀ||vrâtjtjd |¡ddtjd n,d}| ¡ D ]%}||krÿ|rût t d |¡¡¡ t ¡  d}t |¡ t || ¡ qèt ¡  d S )Nú^(\d+(?:\.\d+)+)*r5   z(Unable to access Github. HTTP Error : {}z-Unable to access Github. Error Connecting: {}z*Unable to access Github. Timeout Error: {}zUnable to access Github. {}zUnexpected error. {}zJ^(\d+(?:\.\d+)+) +- +\d{4}-\d{2}-\d{2}\r?\n((?:(?!\d+\.\d).*(?:\r?\n|$))*)zutf-8r   zVersion {} not foundr?   r@   rA   Tz,Version {} is up to date with latest releaseF)r   ÚreÚsearchr   Úgroupr   Úgetr   ZCHANGE_LOG_URLÚraise_for_statusÚ
exceptionsÚ	HTTPErrorrF   rG   rH   rI   ÚConnectionErrorÚTimeoutÚRequestExceptionÚ	ExceptionÚfindallÚcontentÚdecodeÚMÚstriprJ   rK   ÚkeysÚexit)r%   r&   r'   ZodÚversionÚresponseÚerrhÚerrcÚerrtÚerrÚeÚmatchesÚmatchZversion_up_to_dateÚkeyr*   r*   r+   Úfind_latest_release_info  sL   "€"€"€"€"€ÿ"
rs   c              
   C   sò  |sd S t  dt¡ d¡}d}zt tj¡}| ¡  | 	¡ d d }W nŸ tj
jyD } zt t d¡ |¡¡ d}W Y d }~n²d }~w tj
jyd } zt t d¡ |¡¡ d}W Y d }~n’d }~w tj
jy„ }	 zt t d	¡ |	¡¡ d}W Y d }	~	nrd }	~	w tj
jy¤ }
 zt t d
¡ |
¡¡ d}W Y d }
~
nRd }
~
w tyÂ } zt t d¡ |¡¡ d}W Y d }~n4d }~ww t |¡ dd„ | d¡D ƒ}dd„ | d¡D ƒ}||k ròt tjd ||tj¡dd¡ d}t |¡ d S )NrV   r5   r   Úinfori   z&Unable to access Pypi. HTTP Error : {}r>   z+Unable to access Pypi. Error Connecting: {}z(Unable to access Pypi. Timeout Error: {}zUnable to access Pypi. {}zUnexpected Error. {}c                 S   ó   g | ]}t |ƒ‘qS r*   ©Úint©Ú.0Úxr*   r*   r+   Ú
<listcomp>X  ó    z/find_latest_release_version.<locals>.<listcomp>r7   c                 S   ru   r*   rv   rx   r*   r*   r+   r{   Y  r|   ziYou are using OCI CLI version {}, however version {} is available. You should consider upgrading using {}r?   r@   )rW   rX   r   rY   r   rZ   r   ZOCI_CLI_PYPI_URLr[   Újsonr\   r]   rF   rG   rH   rI   r^   r_   r`   ra   r:   ZUPGRADING_CLI_DOCUMENTATIONrJ   rh   )r%   r&   r'   Zcurrent_versionZ	exit_coderj   Zlatest_versionrk   rl   rm   rn   ro   Zcurrent_version_listZlatest_version_listr*   r*   r+   Úfind_latest_release_version=  sP   €€€€€þ
ÿÿr~   ZociT)Zallow_interspersed_argsZignore_unknown_optionsaÞ  Oracle Cloud Infrastructure command line interface, with support for Audit, Block Volume,
Compute, Database, IAM, Load Balancing, Networking, DNS, File Storage, Email Delivery and Object Storage Services.

Most commands must specify a service, followed by a resource type and then an action. For example, to list users (where
$T contains the OCID of the current tenant):

  oci iam user list --compartment-id $T

Output is in JSON format.

For information on configuration, see z.

Enable our interactive features to guide you through command usage:

  oci -i

For information on interactive features, see r7   )r/   ÚclsZinvoke_without_commandZcontext_settingsÚhelpz-vz	--versionz%(version)s)Úmessagez--release-infoFzhPrints ChangeLog difference between current installed version and latest released version. Please visit z for more info)Úis_flagÚshow_defaultÚcallbackZexpose_valueÚis_eagerr€   z--latest-versionzPrints latest released version.z--config-filezThe path to the config file.)r.   rƒ   r„   r€   z	--profilezÇThe profile in the config file to load. This profile will also be used to locate any default parameter values which have been specified in the OCI CLI-specific configuration file.  [default: DEFAULT])r.   rƒ   r€   z--cli-rc-filez--defaults-fileaH  The path to the OCI CLI-specific configuration file, containing parameter default values and other configuration information such as command aliases and predefined queries.

The --defaults-file option is deprecated and you should use the --cli-rc-file option instead.

For more information about the cli configuration file, see )r.   rƒ   r…   r„   r€   z--opc-request-idz--opc-client-request-idz--request-idÚ
request_idz/The request id to use for tracking the request.)r€   z--regionzkThe region to make calls against.  For a list of valid region names use the command: "oci iam region list".)r„   r€   z
--endpointa(  The value to use as the service endpoint, including any required API version path. For example: "https://iaas.us-phoenix-1.oracle.com/20160918". This will override the default service endpoint / API version path. Note: The --region parameter is the recommended way of targeting different regions.z--realm-specific-endpoint)r‚   r€   z--connection-timeoutÚconnection_timeoutz¦The value of the connection timeout in seconds to make establish connection from sdk to services. This will override the default connection timeout value of 10 secs. )Útyper„   r€   z--read-timeoutÚread_timeoutzšThe value of the read timeout in seconds to wait for service calls to send response to sdk. This will override the default read timeout value of 60 secs. z--cert-bundlezThe full path to a CA certificate bundle to be used for SSL verification. This will override the default CA certificate bundle.z--outputr}   Útable)Úchoicesz$The output format. [Default is json])rˆ   r€   z--querya`  JMESPath query [http://jmespath.org/] to run on the response JSON before output.

Queries can be entered directly on the command line or referenced from the [OCI_CLI_COMMAND_ALIASES] section of your configuration file by using the syntax query://<query_name>, for example query://get_id_and_name

For more information, see the Using Queries section at rC   z--raw-outputzoIf the output of a given query is a single string value, this will return the string without surrounding quotesz--authz²The type of auth to use for the API request. By default the API key in your config file will be used.  This value can also be provided in the {auth_env_var} environment variable.)Zauth_env_varz--auth-purposezBThe The auth purpose which can be used in conjunction with --auth.z"--generate-full-command-json-input)r‚   r…   r€   z--generate-param-json-input)r…   r€   z
--no-retryz*Disable retry logic for calls to services.z--max-retrieszœMaximum number of retry calls to be made to the service. For most commands, 5 attempts will be made. For operations with binary bodies, retries are disabledz-dz--debugz"Show additional debug information.z-iz--cli-auto-promptzƒUse the interactive features for autocompletion and quick view of command reference.

For information on interactive features, see ú-?ú-hú--helpzLFor detailed help on the individual OCI CLI command, enter <command> --help.c                 C   sê  t jtjj_|r|rt d¡‚| js"tjt	j
v s"|s"t| ƒ t ¡  t|ƒtttƒƒkrQtjt	j
v r9t	j
tj }nd| jv rOtj| jd v rO| jd tj }nt}|d u r}tjt	j
v r}t	j
tj tv rjt	j
tj }ntjdjt	j
tj d t¡ddd‚i d|“d	|“d
|“d|“d|“d|“d|“d|“d|“d|“d|	“d|
“d|“d|“d|“d|“d|“|||dœ¥}| js¿|| _n| j |¡ t| ||ƒ |rïd| jd< t| ƒrït  | j di ¡ tjd¡¡sït  | tj!d g¡ t"j# $d| jd ¡ t%| jd< zt j&| j }t' (|¡}| )¡  W n
 t*y   Y nw t+ƒ s!|r*t, -| ¡ |  ¡  | jd rqd d l.}t /| .¡ ¡ t /d! | 0¡ ¡¡ t /d" | 1¡ ¡¡ t /d# | 2¡ ¡¡ t	j
D ]}|d$v shd%|v rot3d& |¡ƒ q\d S d S )'NzJThe option --max-retries is not applicable when using the --no-retry flag.r   z4invalid choice: {arg_value}. (choose from {choices})z, )Ú	arg_valuer‹   ZOCI_CLI_AUTH)Z
param_hintÚconfig_fileÚprofileÚcli_rc_filer†   ÚregionÚendpointÚrealm_specific_endpointr‡   r‰   Úcert_bundleÚoutputÚqueryÚ
raw_outputÚ generate_full_command_json_inputÚgenerate_param_json_inputÚdebugÚno_retry)ÚauthÚauth_purposeZmax_attemptsTr€   Fr5   ZNUM_INVOCATIONSZ
start_timer   zSystem name: {}zSystem release : {}zSystem version: {}
)Z
http_proxyZ
HTTP_PROXYZhttps_proxyZHTTPS_PROXYZno_proxyZNO_PROXYZREQUESTS_CA_BUNDLEZOCI_zenv {} is set)4r
   Zupdate_click_help_messagerF   r\   Z
UsageErrorZshowZinvoked_subcommandr   ÚOCI_CLI_AUTO_PROMPT_ENV_VARr   r   Ú	echo_helprJ   rh   Ústrr   r   ZOCI_CLI_PROFILE_ENV_VARr   Z+CLI_RC_GENERIC_SETTINGS_DEFAULT_PROFILE_KEYÚOCI_CLI_AUTH_ENV_VARÚOCI_CLI_AUTH_CHOICESZBadParameterrI   r;   rO   Úload_default_valuesÚis_top_level_helpZparse_booleanrZ   Z&CLI_RC_GENERIC_SETTINGS_USE_CLICK_HELPr	   Zrender_help_textÚargvr   ZMetricsZupdate_metricÚstartZ!SUBCOMMAND_TO_SERVICE_INIT_MODULEÚ	importlibÚimport_moduleÚinitra   Úcli_auto_prompt_envr   Zstart_interactive_shellÚplatformrG   ÚsystemÚreleaseri   Úprint)r%   r   r‘   r’   r†   r“   r”   r•   r–   r—   r˜   r™   rž   rŸ   r   Zmax_retriesrš   r›   rœ   Zcli_auto_promptr‡   r‰   r€   Zinitial_dictZsubcommand_init_module_nameZsubcommand_init_moduler­   Úenvr*   r*   r+   Úclib  s°   E
&ÿþýüûúùø	÷
öõôóòñðïì
&

ÿ

€ør²   c                   C   s"   t jtjv rtj t j¡ dS dS )NTF)r   r    r   r   Úpopr*   r*   r*   r+   r¬   
  s   r¬   c                 C   s|   t tjƒdkr	dS g }t | jj¡D ]\}}t|tj	ƒr#| 
||f¡ q|D ]}|d tjd kr;tjd dv r; dS q&dS )Né   Fr   r5   r>   )rŒ   r   rŽ   T)rE   rJ   r§   ÚsixZ	iteritemsrP   ÚcommandsÚ
isinstancerF   ÚGrouprL   )r%   Ztop_level_command_tuplesÚcmd_nameÚcmd_objZ	cmd_tupler*   r*   r+   r¦     s   € €r¦   c                 C   sh   t j t j |¡¡}i | jd< t j |¡r0tjd d}| |¡ ||v r2t	| 
|¡ƒ| jd< d S d S d S )NZdefault_values_from_file)r   )r   r   r   r   r   r"   r    r!   r#   rR   rT   )r%   r’   r‘   r(   Úparserr*   r*   r+   r¥   !  s   

ür¥   c              	   C   sŠ  |   ¡ }tjd|dd}|d  d¡}|d |d  }g }i }|D ]"}t|ƒdkr6| ¡  d d¡d tv r6q!| t| ¡  d d¡ƒ¡ q!d}tt 	¡ dd	„ d
D ]$\}}||d kri|re| 
||i¡ g }|d }| |t| d f¡ qP| 
||i¡ tj|| jd | ¡ D ]:}	tj ¡ }
|
 |	¡ |
 d¡ |
 ¡  |
 ¡  |
 ||	 ¡ W d   ƒ n1 s³w   Y  tj|
 ¡ | jd qˆd S )Nz(Commands:
)r5   )Úmaxsplitr>   rC   r   Ú c                 S   s   | d d S )Nr5   r>   r*   )Úitemr*   r*   r+   Ú<lambda>?  s    zecho_help.<locals>.<lambda>)rr   )Úcolorz

)Zget_helprW   r:   rE   rf   r   rL   ÚtupleÚsortedrT   rO   rF   rG   rÀ   rg   Z
formattingZHelpFormatterÚwriteÚindentZindentationZwrite_dlÚgetvalue)r%   Z	help_textZhelp_text_commandsZcommand_listZ
group_dictrP   Zcurrent_groupZservice_keyZservice_valueZ
group_nameÚ	formatterr*   r*   r+   r¡   -  s<   $



ÿùr¡   )MZtimeitr   Ztimerr¨   rJ   Z
oci.configr   r   rF   r    Úos.pathr   ÚloggingZoci.utilr   rµ   r©   rW   Zoci_cli.versionr   Zoci_cli.aliasingr   r   Úoci_clir	   r
   r   Úcollectionsr   Zoci._vendorr   r   Úinteractiver   Zoci_cli.service_mappingr   ÚbasicConfigÚWARNZOCI_CLI_AUTH_API_KEYZOCI_CLI_AUTH_INSTANCE_PRINCIPALZOCI_CLI_AUTH_SESSION_TOKENZOCI_CLI_AUTH_INSTANCE_OBO_USERZOCI_CLI_AUTH_RESOURCE_PRINCIPALr¤   ZREALM_SPECIFIC_ENDPOINT_HELPZGENERATE_PARAM_JSON_HELPZGENERATE_FULL_COMMAND_JSON_HELPr,   r0   r$   r4   r2   r3   r1   r6   rs   r~   rP   rR   ZOCI_CONFIG_DOCUMENTATIONZINTERACTIVE_CLI_DOCUMENTATIONZversion_optionÚoptionZGITHUB_CHANGELOGr   ZCLI_CONFIG_DOCUMENTATIONZINTZChoiceZINPUT_OUTPUT_DOCUMENTATIONrI   r£   Zpass_contextr²   r¬   r¦   r¥   r¡   r*   r*   r*   r+   Ú<module>   sÈ   6'	&
%

öðþÿÿÿþþüýÿ
ü 
þ>e