File: //var/opt/nydus/ops/primordial/wsgi/__pycache__/cherrytools.cpython-39.pyc
a
�,�h � @ s� d dl mZmZ d dlZd dlZd dlmZ eeedd�dd�Zeeedd�dd�Z deee ee ee dd �d
d�Z
dd
� ZdS )� )�Callable�OptionalN)�Config)�config�api�path�returnc C s t j�||� t| � dS )z�Start CherryPy running an API.
:param config: The configuration to use for CherryPy
:param api: The API callable to be started
:param path: The path under which the API should respond to requests
N)�cherrypy�tree�graft�run_cherrypy)r r r � r
�L/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/primordial/wsgi/cherrytools.py�start_cherry
s r c C s@ t j�||� | �d�}| �d�}| �d�}t| |||d� dS )a* Start CherryPy running an API on HTTPS only.
This is a backport of how ServiceGroup & DNS
verticals start.
:param config: The configuration to use for CherryPy
:param api: The API callable to be started
:param path: The path under which the API should respond to requests
Zserver_certZ
server_keyZ server_ca)� cert_path�key_path�
ca_certs_pathN)r r
r �getr )r r r � cert_fileZ pkey_fileZ
ca_certs_filer
r
r �start_cherry_https s
�r )r r r r r c C s� | � d�}tjjj�|� |tjj_| � d�}| �d�}|rh|durhtj� ||d||t
|||�d�� n| �d�}tj� ||d�� tj�� tj�� dS ) znRun CherryPy. Called by `start_cherry`.
:param config: The configuration to use for running CherryPy
�restart_triggerzserver.hostzserver.https.portN�builtin)�server.socket_host�server.socket_portzserver.ssl_modulezserver.ssl_certificatezserver.ssl_private_keyzserver.ssl_contextzserver.port)r r )
r r ZengineZ
autoreload�files�add�matchZget_intr �update�ssl_context�start�block)r r r r r Zserver_hostZ
https_portZserver_portr
r
r r - s(
�
�
r c C s* t jt jj|d�}|�| |� t j|_|S )a4 Create a server SSL context requiring client certificate authentication.
:param certificate: Path to server certificate.
:param private_key: Path to server private key.
:param ca_certs: Path to certificate authority chain against which client
certificates are validated.
)�purpose�cafile)�ssl�create_default_context�Purpose�CLIENT_AUTH�load_cert_chain�
CERT_REQUIRED�verify_mode)ZcertificateZprivate_key�ca_certs�contextr
r
r r P s �r )NNN)�typingr r r# r Zprimordial.configr �strr r r r r
r
r
r �<module> s ��#