8000 Encapsulate more logic within reusable functions · swinton/github-app-demo.py@ee9c264 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

Commit ee9c264

Browse files
committed
Encapsulate more logic within reusable functions
1 parent f19e2bd commit ee9c264

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

auth.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,25 @@ def __call__(self, r):
3939
r.headers['Authorization'] = 'bearer {}'.format(self.generate_token())
4040
return r
4141

42-
with open(os.environ['PRIVATE_KEY_FILE']) as fp:
43-
private_pem = fp.read()
4442

45-
authorization = JWTAuth(
46-
iss=os.environ['APP_ID'],
47-
key=private_pem)
43+
def read_private_key():
44+
with open(os.environ['PRIVATE_KEY_FILE']) as fp:
45+
private_key = fp.read()
46+
return private_key
4847

49-
response = requests.get('https://api.github.com/app',
50-
auth=authorization,
51-
headers=dict(accept='application/vnd.github.machine-man-preview+json'))
5248

53-
# Print the response
54-
print(response.json())
49+
def authenticate():
50+
authorization = JWTAuth(
51+
iss=os.environ['APP_ID'],
52+
key=read_private_key())
53+
54+
response = requests.get('https://api.github.com/app',
55+
auth=authorization,
56+
headers=dict(accept='application/vnd.github.machine-man-preview+json'))
57+
58+
return response
59+
60+
61+
if __name__ == '__main__':
62+
import pprint
63+
pprint.pprint(authenticate().json())

0 commit comments

Comments
 (0)
0