8000 Add decorator for new methods requiring app creds · mikewaters/github3.py@d46ae36 · GitHub
[go: up one dir, main page]

Skip to content

Commit d46ae36

Browse files
committed
Add decorator for new methods requiring app creds
1 parent 13b1d46 commit d46ae36

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

github3/decorators.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ def auth_wrapper(self, *args, **kwargs):
6767
return auth_wrapper
6868

6969

70+
def requires_app_credentials(func):
71+
"""Require client_id and client_secret to be associated.
72+
73+
This is used to note and enforce which methods require a client_id and
74+
client_secret to be used.
75+
76+
"""
77+
@wraps(func)
78+
def auth_wrapper(self, *args, **kwargs):
79+
if hasattr(self, '_session') and self._session.params:
80+
return func(self, *args, **kwargs)
81+
else:
82+
from github3.models import GitHubError
83+
# Mock a 401 response
84+
r = generate_fake_error_response(
85+
'{"message": "Requires username/password authentication"}'
86+
)
87+
raise GitHubError(r)
88+
89+
return auth_wrapper
90+
91+
7092
def generate_fake_error_response(msg, status_code=401, encoding='utf-8'):
7193
r = Response()
7294
r.status_code = status_code

0 commit comments

Comments
 (0)
0