Skip to content

Commit

Permalink
Raising NoCredentialsException on utils#find_api_key
Browse files Browse the repository at this point in the history
NoCredentialsException is a ClickException, which is handled nicely by
click, displaying the error msg and returning an exit code != 0.
  • Loading branch information
josericardo committed Jun 19, 2015
1 parent 5e96cfa commit ff7a1a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions shub/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from click import ClickException


class NoCredentialsException(ClickException):
pass
13 changes: 12 additions & 1 deletion shub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import requests

from shub.click_utils import log
from shub.exceptions import NoCredentialsException

SCRAPY_CFG_FILE = os.path.expanduser("~/.scrapy.cfg")
OS_WIN = True if os.name == 'nt' else False
Expand All @@ -28,10 +29,20 @@ def missing_modules(*modules):


def find_api_key():
"""Finds and returns the Scrapy Cloud APIKEY"""
"""Finds and returns the Scrapy Cloud APIKEY
Raises:
NoCredentialsException: if no API key is found
"""
key = os.getenv("SHUB_APIKEY")
if not key:
key = get_key_netrc()

if not key:
err = ("Your credentials haven't been defined.\n"
"Use 'shub login' or set the SHUB_APIKEY environment variable.")
raise NoCredentialsException(err)

return key


Expand Down

0 comments on commit ff7a1a8

Please sign in to comment.