Skip to content

Commit

Permalink
Add flag for HTTP retries to CLI tool (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
borchero authored Apr 7, 2023
1 parent 870d70e commit bc99296
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/quetz_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
from typing import Optional

import fire
from requests.adapters import HTTPAdapter, Retry

from quetz_client.client import QuetzClient


def get_client(
*, url: Optional[str] = None, token: Optional[str] = None, insecure: bool = False
*,
url: Optional[str] = None,
token: Optional[str] = None,
insecure: bool = False,
retry: bool = False,
) -> QuetzClient:
"""
CLI tool to interact with a Quetz server.
Expand All @@ -24,11 +29,26 @@ def get_client(
insecure: bool
Allow quetz-client to perform "insecure" SSL connections.
retry: bool
Allow to retry requests on transient errors and 5xx server
respones.
"""
# Initialize the client
url = url or os.environ["QUETZ_SERVER_URL"]
token = token or os.environ["QUETZ_API_KEY"]
client = QuetzClient.from_token(url, token)

# Configure the client with additional flags passed to the CLI
client.session.verify = not insecure
if retry:
# Retry a total of 10 times, starting with an initial backoff of one second.
retry_config = Retry(
total=10, status_forcelist=range(500, 600), backoff_factor=1
)
adapter = HTTPAdapter(max_retries=retry_config)
client.session.mount(url, adapter)

return client


Expand Down

0 comments on commit bc99296

Please sign in to comment.