Ignore false-positive E231 error
... and refactor the logic to generate request url. Change-Id: Ic39b7b70a3a1260e0dc281408ba49f8b9ec21c47
This commit is contained in:
@@ -68,9 +68,12 @@ class PrometheusAPIClient(object):
|
|||||||
def set_basic_auth(self, auth_user, auth_password):
|
def set_basic_auth(self, auth_user, auth_password):
|
||||||
self._session.auth = (auth_user, auth_password)
|
self._session.auth = (auth_user, auth_password)
|
||||||
|
|
||||||
|
def _get_url(self, endpoint):
|
||||||
|
scheme = 'https' if self._session.verify else 'http'
|
||||||
|
return f"{scheme}://{self._host}/api/v1/{endpoint}" # noqa: E231
|
||||||
|
|
||||||
def _get(self, endpoint, params=None):
|
def _get(self, endpoint, params=None):
|
||||||
url = (f"{'https' if self._session.verify else 'http'}://"
|
url = self._get_url(endpoint)
|
||||||
f"{self._host}/api/v1/{endpoint}")
|
|
||||||
resp = self._session.get(url, params=params,
|
resp = self._session.get(url, params=params,
|
||||||
headers={'Accept': 'application/json'})
|
headers={'Accept': 'application/json'})
|
||||||
if resp.status_code != requests.codes.ok:
|
if resp.status_code != requests.codes.ok:
|
||||||
@@ -82,8 +85,7 @@ class PrometheusAPIClient(object):
|
|||||||
return decoded
|
return decoded
|
||||||
|
|
||||||
def _post(self, endpoint, params=None):
|
def _post(self, endpoint, params=None):
|
||||||
url = (f"{'https' if self._session.verify else 'http'}://"
|
url = self._get_url(endpoint)
|
||||||
f"{self._host}/api/v1/{endpoint}")
|
|
||||||
resp = self._session.post(url, params=params,
|
resp = self._session.post(url, params=params,
|
||||||
headers={'Accept': 'application/json'})
|
headers={'Accept': 'application/json'})
|
||||||
if resp.status_code != requests.codes.ok:
|
if resp.status_code != requests.codes.ok:
|
||||||
|
@@ -68,7 +68,7 @@ def get_prometheus_client():
|
|||||||
if host is None or port is None:
|
if host is None or port is None:
|
||||||
raise ConfigurationError("Can't find prometheus host and "
|
raise ConfigurationError("Can't find prometheus host and "
|
||||||
"port configuration.")
|
"port configuration.")
|
||||||
client = PrometheusAPIClient(f"{host}:{port}")
|
client = PrometheusAPIClient(f"{host}:{port}") # noqa: E231
|
||||||
if ca_cert is not None:
|
if ca_cert is not None:
|
||||||
client.set_ca_cert(ca_cert)
|
client.set_ca_cert(ca_cert)
|
||||||
return client
|
return client
|
||||||
|
Reference in New Issue
Block a user