-
-
Notifications
You must be signed in to change notification settings - Fork 60
Adding utility functions for GitHub App #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I'm planning to prepare an online GitHub App tutorial and I'm kinda wanting for this to be included to gidgethub in time before I record the tutorial. I will try to find time to write the tests this weekend. |
4193ec9 to
457776d
Compare
- add get_jwt - add get_installation_access_token - add PyJWT and cryptography dependencies, needed to construct JWT Hoping for inclusion in 4.1.0 Closes gidgethub#71
Black formatting
|
If possible I'd like to have this released soon. I need this functionality for MY PyCon tutorial that is due onApril 24. (But it would be great if I can record my tutorial this weekend 🙏🏻) |
brettcannon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of little things I trust you to touch up before merging. 😄
gidgethub/app.py
Outdated
|
|
||
| async def get_installation_access_token( | ||
| gh: GitHubAPI, *, installation_id: str, app_id: str, private_key: str | ||
| ) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is calling a specific endpoint that has an expected value, maybe we should type this as Dict[str, str]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns whatever gh.post returns, which is Any. When I tried to change this to Dict[str, str], it complained because it doesn't match gh.post's return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you probably would have to cast it.
|
BTW once you get this landed and the release out I want to set this project up on github.com/brettcannon/release-often so that we automate releases. 😁 (I would do it now but I haven't tested it against a flit project yet and I don't want to hold you up for your tutorial.) |
| from gidgethub.abc import GitHubAPI | ||
|
|
||
|
|
||
| def get_jwt(*, app_id: str, private_key: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that there are other endpoints that require JWT, so I changed this from private to public. I've also adjusted the documentation.
tests/test_app.py
Outdated
| import pytest | ||
|
|
||
| from gidgethub import ( | ||
| app as gh_app, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason app is clashing with pytest-tornasync fixture, so I had to rename this to gh_app in tests.
I could also call the module apps instead of app if that's better? (just like actions with s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming it 'apps' is fine by me.
|
@brettcannon mind re-reviewing one last time? I made |
gidgethub/app.py
Outdated
| """Obtain a GitHub App's installation access token. | ||
| Return a dictionary containing access token and expiration time. | ||
| Doc: https://developer.github.com/v3/apps/#create-a-new-installation-token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """Obtain a GitHub App's installation access token. | |
| Return a dictionary containing access token and expiration time. | |
| Doc: https://developer.github.com/v3/apps/#create-a-new-installation-token | |
| """Obtain a GitHub App's installation access token. | |
| Returns a dictionary containing access token and expiration time | |
| (https://developer.github.com/v3/apps/#create-a-new-installation-token). |
| requires = [ | ||
| "uritemplate>=3.0.1", | ||
| "PyJWT>=1.7.1", | ||
| "cryptography>=2.9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a direct dependency, why do you specify it here?
| requires = ["uritemplate>=3.0.1"] | ||
| requires = [ | ||
| "uritemplate>=3.0.1", | ||
| "PyJWT>=1.7.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #116 to track this.
| from gidgethub.abc import GitHubAPI | ||
|
|
||
|
|
||
| def get_jwt(*, app_id: str, private_key: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In octomachinery, I used to have it as a function but then I implemented an object that represents a private key with fingerprint pinning and it turned out that it's handy to have it as a method:
https://github.com/sanitizers/octomachinery/blob/6b41c1df510f8bbf090ea290941261396e2cb559/octomachinery/github/models/private_key.py
Hoping for inclusion in 4.1.0, and to get early feedback
Closes #71