Closed luiscoms closed 4 years ago
Hello @luiscoms,
Could you share an example with me? I tried using the ConfigServer present in the docker-compose.yml
file by sharing this files but the request did not work.
Hi @amenezes,
The above example should be work once file nginx.conf
is present on config server.
import requests
requests.get("http://localhost:8888/app_name/profile/master/nginx.conf")
<Response [200]>
Additionally, I can request the application raw file with the following request:
import requests
requests.get("http://localhost:8888/app_name/profile/master/simpleweb000-development.yml")
<Response [200]>
Ok @luiscoms now worked.
Some adjustments:
get_plaintext_file
could be renamed to get_file
._request_config
, get_config
and get_file
could be refactored to something like:def get_config(self, **kwargs) -> None:
response = self._request(self.url, **kwargs)
self._config = response.json()
def get_file(self, name: str, **kwargs) -> str:
uri = f"{self.address}/{self.app_name}/{self.profile}/{self.branch}/{name}"
response = self._request(uri, **kwargs)
return response.text
def _request(self, uri, **kwargs) -> requests.Response:
try:
response = requests.get(uri, **kwargs)
response.raise_for_status()
except requests.exceptions.HTTPError:
raise RequestFailedException(
f"Failed to request URI(path={uri}, code={response.status_code}"
)
except Exception:
logging.error("Failed to establish connection with ConfigServer.")
if self.fail_fast:
logging.info("fail_fast enabled. Terminating process.")
raise SystemExit(1)
raise ConnectionError("fail_fast disabled.")
return response
Sure, I have a question about exception handing. If request fail and fall in HTTPError like
except requests.exceptions.HTTPError:
The flag fail_fast was not considered
You're right @luiscoms it's better change this flow.
Maybe removing except requests.exceptions.HTTPError:
and change the messages from except Exception
block. For something like:
def _request(self, uri, **kwargs) -> requests.Response:
try:
response = requests.get(uri, **kwargs)
response.raise_for_status()
#except requests.exceptions.HTTPError: # remove this block
# raise RequestFailedException(
# f"Failed to request URI(path={uri}, code={response.status_code}"
# )
except Exception as ex:
logging.error(f"Failed to request: {uri}")
logging.error(ex)
if self.fail_fast:
logging.info("fail_fast enabled. Terminating process.")
raise SystemExit(1)
raise ConnectionError("fail_fast disabled.")
return response
Hi @amenezes I moved the exception handing to get_config in order to consider fail fast only on get config
As described on official documentation here, it is possible to get plaintext files from config server.
This pull request adds a method to allow this.
Ie.: