api: Make site settable via configuration files.
This works much better for working with staging, since rather than needing to tell each individual tool that you're using staging, you just specify that along with your API (which at the moment implies whether you should be using staging or prod). (imported from commit c1de8e72c24f35ef2160bce5339a5f03c6e1da95)
This commit is contained in:
parent
435c80e809
commit
417d127c98
|
@ -46,7 +46,7 @@ API_VERSTRING = "/api/v1/"
|
||||||
def generate_option_group(parser):
|
def generate_option_group(parser):
|
||||||
group = optparse.OptionGroup(parser, 'API configuration')
|
group = optparse.OptionGroup(parser, 'API configuration')
|
||||||
group.add_option('--site',
|
group.add_option('--site',
|
||||||
default='https://humbughq.com',
|
default=None,
|
||||||
help=optparse.SUPPRESS_HELP)
|
help=optparse.SUPPRESS_HELP)
|
||||||
group.add_option('--api-key',
|
group.add_option('--api-key',
|
||||||
action='store')
|
action='store')
|
||||||
|
@ -69,7 +69,7 @@ def init_from_options(options):
|
||||||
class Client(object):
|
class Client(object):
|
||||||
def __init__(self, email=None, api_key=None, config_file=None,
|
def __init__(self, email=None, api_key=None, config_file=None,
|
||||||
verbose=False, retry_on_errors=True,
|
verbose=False, retry_on_errors=True,
|
||||||
site="https://humbughq.com", client="API"):
|
site=None, client="API"):
|
||||||
if None in (api_key, email):
|
if None in (api_key, email):
|
||||||
if config_file is None:
|
if config_file is None:
|
||||||
config_file = os.path.join(os.environ["HOME"], ".humbugrc")
|
config_file = os.path.join(os.environ["HOME"], ".humbugrc")
|
||||||
|
@ -83,11 +83,16 @@ class Client(object):
|
||||||
api_key = config.get("api", "key")
|
api_key = config.get("api", "key")
|
||||||
if email is None:
|
if email is None:
|
||||||
email = config.get("api", "email")
|
email = config.get("api", "email")
|
||||||
|
if site is None:
|
||||||
|
site = config.get("api", "site", None)
|
||||||
|
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.email = email
|
self.email = email
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
if site is not None:
|
||||||
self.base_url = site
|
self.base_url = site
|
||||||
|
else:
|
||||||
|
self.base_url = "https://humbughq.com"
|
||||||
self.retry_on_errors = retry_on_errors
|
self.retry_on_errors = retry_on_errors
|
||||||
self.client_name = client
|
self.client_name = client
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue