예제 #1
0
 def get_file(self, filename: str, **kwargs: dict) -> str:
     """Request a file from the config server."""
     uri = f"{self.address}/{self.app_name}/{self.profile}/{self.branch}/{filename}"
     try:
         response = http.get(uri, **kwargs)
     except Exception:
         raise RequestFailedException(f"Failed to request URI: {uri}")
     return response.text
예제 #2
0
 def get_file(self, filename: str, **kwargs: dict) -> str:
     uri = f"{self.address}/{self.app_name}/{self.profile}/{self.branch}/{filename}"
     logger.debug(f"URI to request file: {uri}")
     try:
         response = self._request(uri, **kwargs)
     except Exception:
         logger.error(f"Failed to request URI: {uri}")
         raise RequestFailedException(f"Failed to request URI: {uri}")
     return response.text
예제 #3
0
 def request_token(self, client_auth: HTTPBasicAuth, data: dict) -> None:
     try:
         response = http.post(self.access_token_uri,
                              auth=client_auth,
                              data=data)
     except MissingSchema:
         raise RequestFailedException("Access token URI it's empty")
     except HTTPError:
         raise RequestTokenException(
             "Failed to retrieve oauth2 access_token.")
     self.token = response.json().get("access_token")
     logger.info("Access token successfully obtained.")
예제 #4
0
 def decrypt(
     self,
     value: str,
     path: str = "/decrypt",
     headers: dict = {"Content-Type": "text/plain"},
     **kwargs: dict,
 ) -> str:
     """Request a decryption from a value to the config server.."""
     try:
         response = http.post(
             uri=f"{self.address}{path}", data=value, headers=headers, **kwargs
         )
     except Exception:
         raise RequestFailedException(f"Failed to request URI: {self.address}{path}")
     return response.text
예제 #5
0
 def request_token(self, client_auth: HTTPBasicAuth, data: dict) -> None:
     try:
         response = requests.post(self.access_token_uri,
                                  auth=client_auth,
                                  data=data)
         if response.ok:
             self._token = response.json().get("access_token")
             logger.info("Access token successfully obtained.")
             logger.debug(f"access_token: {self._token}")
         else:
             raise RequestTokenException(
                 "Failed to retrieve oauth2 access_token. "
                 f"HTTP Response code: {response.status_code}.")
     except requests.exceptions.MissingSchema as err:
         logger.error(err)
         raise RequestFailedException("Access token URI it's empty")