-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9233cf2
commit 91575be
Showing
11 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from typing import Any, Dict, cast | ||
|
||
import httpx | ||
from retrying import retry | ||
|
||
from ...types import Response | ||
from ...util.errors import QCSHTTPStatusError, raise_for_status | ||
from ...util.retry import DEFAULT_RETRY_ARGUMENTS | ||
|
||
|
||
def _get_kwargs( | ||
*, | ||
client: httpx.Client, | ||
) -> Dict[str, Any]: | ||
url = "{}/v1/".format(client.base_url) | ||
|
||
headers = {k: v for (k, v) in client.headers.items()} | ||
cookies = {k: v for (k, v) in client.cookies} | ||
|
||
return { | ||
"method": "get", | ||
"url": url, | ||
"headers": headers, | ||
"cookies": cookies, | ||
"timeout": client.timeout, | ||
} | ||
|
||
|
||
def _parse_response(*, response: httpx.Response) -> Any: | ||
raise_for_status(response) | ||
if response.status_code == 200: | ||
response_200 = cast(Any, response.json()) | ||
return response_200 | ||
else: | ||
raise QCSHTTPStatusError( | ||
f"Unexpected response: status code {response.status_code}", response=response, error=None | ||
) | ||
|
||
|
||
def _build_response(*, response: httpx.Response) -> Response[Any]: | ||
""" | ||
Construct the Response class from the raw ``httpx.Response``. | ||
""" | ||
return Response.build_from_httpx_response(response=response, parse_function=_parse_response) | ||
|
||
|
||
@retry(**DEFAULT_RETRY_ARGUMENTS) | ||
def sync( | ||
*, | ||
client: httpx.Client, | ||
httpx_request_kwargs: Dict[str, Any] = {}, | ||
) -> Response[Any]: | ||
"""Health Check | ||
Endpoint to return a status 200 for load balancer health checks | ||
Returns: | ||
Response[Any] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
client=client, | ||
) | ||
kwargs.update(httpx_request_kwargs) | ||
response = client.request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(response=response) | ||
|
||
|
||
@retry(**DEFAULT_RETRY_ARGUMENTS) | ||
def sync_from_dict( | ||
*, | ||
client: httpx.Client, | ||
httpx_request_kwargs: Dict[str, Any] = {}, | ||
) -> Response[Any]: | ||
|
||
kwargs = _get_kwargs( | ||
client=client, | ||
) | ||
kwargs.update(httpx_request_kwargs) | ||
response = client.request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(response=response) | ||
|
||
|
||
@retry(**DEFAULT_RETRY_ARGUMENTS) | ||
async def asyncio( | ||
*, | ||
client: httpx.AsyncClient, | ||
httpx_request_kwargs: Dict[str, Any] = {}, | ||
) -> Response[Any]: | ||
"""Health Check | ||
Endpoint to return a status 200 for load balancer health checks | ||
Returns: | ||
Response[Any] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
client=client, | ||
) | ||
kwargs.update(httpx_request_kwargs) | ||
response = await client.request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(response=response) | ||
|
||
|
||
@retry(**DEFAULT_RETRY_ARGUMENTS) | ||
async def asyncio_from_dict( | ||
*, | ||
client: httpx.AsyncClient, | ||
httpx_request_kwargs: Dict[str, Any] = {}, | ||
) -> Response[Any]: | ||
|
||
kwargs = _get_kwargs( | ||
client=client, | ||
) | ||
kwargs.update(httpx_request_kwargs) | ||
response = client.request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(response=response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters