mirror of https://github.com/zulip/zulip.git
api: Read the API key from ~/.humbug-api-key by default.
(imported from commit 309469a0955969eafd78fbdf89d9651cb530010d)
This commit is contained in:
parent
6d2b2f897a
commit
7314c12527
|
@ -6,14 +6,24 @@ import time
|
||||||
import traceback
|
import traceback
|
||||||
import urlparse
|
import urlparse
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
# Check that we have a recent enough version
|
# Check that we have a recent enough version
|
||||||
# Older versions don't provide the 'json' attribute on responses.
|
# Older versions don't provide the 'json' attribute on responses.
|
||||||
assert(requests.__version__ > '0.12')
|
assert(requests.__version__ > '0.12')
|
||||||
|
|
||||||
class HumbugAPI():
|
class HumbugAPI():
|
||||||
def __init__(self, email, api_key, verbose=False, retry_on_errors=True,
|
def __init__(self, email, api_key=None, api_key_file=None,
|
||||||
|
verbose=False, retry_on_errors=True,
|
||||||
site="https://humbughq.com", client="API"):
|
site="https://humbughq.com", client="API"):
|
||||||
|
if api_key is None:
|
||||||
|
if api_key_file is None:
|
||||||
|
api_key_file = os.path.join(os.environ["HOME"], ".humbug-api-key")
|
||||||
|
if not os.path.exists(api_key_file):
|
||||||
|
raise RuntimeError("api_key not specified and %s does not exist"
|
||||||
|
% (api_key_file,))
|
||||||
|
api_key = file(api_key_file).read().strip()
|
||||||
|
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.email = email
|
self.email = email
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
|
|
|
@ -301,13 +301,8 @@ def main(args):
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
||||||
import api.common
|
import api.common
|
||||||
me = get_current_user(repo)
|
me = get_current_user(repo)
|
||||||
api_key_file = os.path.join(os.environ["HOME"], '.humbug-api-key')
|
|
||||||
if not os.path.exists(api_key_file):
|
|
||||||
print >>sys.stderr, "You need to place your Humbug API key at %s" % (api_key_file,)
|
|
||||||
sys.exit(1)
|
|
||||||
client = api.common.HumbugAPI(email=me[me.index("<") + 1:me.index('>')],
|
client = api.common.HumbugAPI(email=me[me.index("<") + 1:me.index('>')],
|
||||||
site="https://staging.humbughq.com",
|
site="https://staging.humbughq.com",
|
||||||
api_key=file(api_key_file).read().strip(),
|
|
||||||
verbose=True)
|
verbose=True)
|
||||||
client.send_message({'type': "private",
|
client.send_message({'type': "private",
|
||||||
'to': opts.reviewers,
|
'to': opts.reviewers,
|
||||||
|
|
Loading…
Reference in New Issue