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