Skip to content

Commit 7b60ea6

Browse files
intelfxstephenfin
authored andcommitted
Do not require authentication for GET requests
Fixes #40. Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
1 parent 613df41 commit 7b60ea6

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ settings are **required**:
9090

9191
https://patchwork.ozlabs.org/project/{project_name}/list/
9292

93-
You also require authentication - you can use either API tokens or a
94-
username/password combination:
93+
For read-write access, you also need authentication - you can use either API
94+
tokens or a username/password combination:
9595

9696
``pw.token``
9797
The API token for your Patchwork account.
@@ -102,6 +102,8 @@ username/password combination:
102102
``pw.password``
103103
The password for your Patchwork account.
104104

105+
If only read-only access is desired, credentials can be omitted.
106+
105107
The following settings are **optional** and may need to be set depending on
106108
your Patchwork instance's configuration:
107109

git_pw/api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ def _token_auth_str(token): # type: (str) -> str
4747
return 'Token {}'.format(token.strip())
4848

4949

50-
def _get_auth(): # type: () -> requests.auth.AuthBase
50+
def _get_auth(optional=False):
51+
# type: (bool) -> Optional[requests.auth.AuthBase]
5152
if CONF.token:
5253
return HTTPTokenAuth(CONF.token)
5354
elif CONF.username and CONF.password:
5455
return requests.auth.HTTPBasicAuth(CONF.username, CONF.password)
55-
else:
56+
elif not optional:
5657
LOG.error('Authentication information missing')
5758
LOG.error('You must configure authentication via git-config or via '
5859
'--token or --username, --password')
5960
sys.exit(1)
61+
return None
6062

6163

6264
def _get_headers(): # type: () -> Dict[str, str]
@@ -136,8 +138,8 @@ def _get(url, params=None, stream=False):
136138
# 'params' (namely a list of tuples) but it doesn't seem possible to
137139
# indicate this
138140
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
141143
rsp.raise_for_status()
142144
except requests.exceptions.RequestException as exc:
143145
_handle_error('fetch', exc)

0 commit comments

Comments
 (0)