patroni.request module
Facilities for handling communication with Patroni’s REST API.
- class patroni.request.HTTPSConnectionPool(host: str, port: int | None = None, timeout: _TYPE_TIMEOUT | None = _TYPE_DEFAULT.token, maxsize: int = 1, block: bool = False, headers: Mapping[str, str] | None = None, retries: Retry | bool | int | None = None, _proxy: Url | None = None, _proxy_headers: Mapping[str, str] | None = None, key_file: str | None = None, cert_file: str | None = None, cert_reqs: int | str | None = None, key_password: str | None = None, ca_certs: str | None = None, ssl_version: int | str | None = None, ssl_minimum_version: ssl.TLSVersion | None = None, ssl_maximum_version: ssl.TLSVersion | None = None, assert_hostname: str | Literal[False] | None = None, assert_fingerprint: str | None = None, ca_cert_dir: str | None = None, **conn_kw: Any)
Bases:
HTTPSConnectionPool
- class patroni.request.PatroniRequest(config: Config | Dict[str, Any], insecure: bool | None = None)
Bases:
objectWrapper for performing requests to Patroni’s REST API.
Prepares the request manager with the configured settings before performing the request.
- __init__(config: Config | Dict[str, Any], insecure: bool | None = None) None
Create a new
PatroniRequestinstance with given config.- Parameters:
config – Patroni YAML configuration.
insecure –
how to deal with SSL certs verification:
If
Trueit will perform REST API requests without verifying SSL certs; orIf
Falseit will perform REST API requests and verify SSL certs; orIf
Noneit will behave according to the value ofctl.insecureconfiguration; orIf none of the above applies, then it falls back to
False.
- _apply_pool_param(param: str, value: Any) None
Configure param as value in the request manager.
- Parameters:
param – name of the setting to be changed.
value – new value for param. If
None,0,False, and similar values, then explicit param declaration is removed, in which case it takes its default value, if any.
- _apply_ssl_file_param(config: Config | Dict[str, Any], name: str) str | None
Apply a given SSL related param to the request manager.
- Parameters:
config – Patroni YAML configuration.
name –
prefix of the Patroni SSL related setting name. Currently, supports these:
cert: gets translated tocertfilekey: gets translated tokeyfile
Will attempt to fetch the requested key first from
ctlsection.
- Returns:
value of
ctl.*name*fileif present,Noneotherwise.
- static _get_ctl_value(config: Config | Dict[str, Any], name: str, default: Any = None) Any | None
Get value of name setting from the
ctlsection of the config.- Parameters:
config – Patroni YAML configuration.
name – name of the setting value to be retrieved.
- Returns:
value of
ctl.*name*if present,Noneotherwise.
- static _get_restapi_value(config: Config | Dict[str, Any], name: str) Any | None
Get value of name setting from the
restapisection of the config.- Parameters:
config – Patroni YAML configuration.
name – name of the setting value to be retrieved.
- Returns:
value of
restapi -> *name*if present,Noneotherwise.
- reload_config(config: Config | Dict[str, Any]) None
Apply config to request manager.
Configure these HTTP headers for requests:
authorization: based on Patroni’ CTL or REST API authentication config;user-agent: based onpatroni.utils.USER_AGENT.
Also configure SSL related settings for requests:
ca_certsis configured ifctl.cacertorrestapi.cafileis available;cert,keyandkey_passwordare configured ifctl.certfileis available.
- Parameters:
config – Patroni YAML configuration.
- request(method: str, url: str, body: Any | None = None, **kwargs: Any) HTTPResponse
Perform an HTTP request.
- Parameters:
method – the HTTP method to be used, e.g.
GET.url – the URL to be requested.
body – anything to be used as the request body.
kwargs – keyword arguments to be passed to
urllib3.PoolManager.request().
- Returns:
the response returned upon request.
- patroni.request.get(url: str, verify: bool = True, **kwargs: Any) HTTPResponse
Perform an HTTP GET request.
Note
It uses
PatroniRequestso all relevant configuration is applied before processing the request.- Parameters:
url – full URL for this GET request.
verify – if it should verify SSL certificates when processing the request.
- Returns:
the response returned from the request.