@@ -47,16 +47,18 @@ def _token_auth_str(token): # type: (str) -> str
47
47
return 'Token {}' .format (token .strip ())
48
48
49
49
50
- def _get_auth (): # type: () -> requests.auth.AuthBase
50
+ def _get_auth (optional = False ):
51
+ # type: (bool) -> Optional[requests.auth.AuthBase]
51
52
if CONF .token :
52
53
return HTTPTokenAuth (CONF .token )
53
54
elif CONF .username and CONF .password :
54
55
return requests .auth .HTTPBasicAuth (CONF .username , CONF .password )
55
- else :
56
+ elif not optional :
56
57
LOG .error ('Authentication information missing' )
57
58
LOG .error ('You must configure authentication via git-config or via '
58
59
'--token or --username, --password' )
59
60
sys .exit (1 )
61
+ return None
60
62
61
63
62
64
def _get_headers (): # type: () -> Dict[str, str]
@@ -136,8 +138,8 @@ def _get(url, params=None, stream=False):
136
138
# 'params' (namely a list of tuples) but it doesn't seem possible to
137
139
# indicate this
138
140
rsp = requests .get (
139
- url , auth = _get_auth (), headers = _get_headers (), stream = stream ,
140
- params = params ) # type: ignore
141
+ url , auth = _get_auth (optional = True ), headers = _get_headers (),
142
+ stream = stream , params = params ) # type: ignore
141
143
rsp .raise_for_status ()
142
144
except requests .exceptions .RequestException as exc :
143
145
_handle_error ('fetch' , exc )
0 commit comments