AnswerDotAI / AnswerDotAI/ghapi

How to specify that headers must be regenerated.

Open
#126 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
685
Forks
70
Avg merge
1m
Merged PRs (30d)
2

Description

I've have a GitHub app which uses a jwt that can expire. Ultimately, I generate an installation access token that can also expire and I am trying to use `ghapi` with that installation access token.

I was hoping that I could subclass `GhApi.__call__` to dynamically generate my access token, but this does not seem to work.

```python
jwtm = JwtManager(app_id, private_key)
iatm = IatManager(jwtm)
token = iatm.token(installation_id)
gh_host = baseurl()

class GhApi(ghapi_all.GhApi):
def __call__(self, path, verb=None, headers=None, route=None, query=None, data=None):
headers = headers or {}
headers.update(iatm.headers(installation_id))
super().__call__(path, verb, headers, route, query, data)

api = GhApi(
owner=owner,
repo=repo,
token=token,
debug=debug,
limit_cb=limit_cb,
gh_host=gh_host,
)
```

IatManager.headers() will generate a new jwt token whenever it is expired and then will use this to generate an access token for the specified installation id. The headers it generates look like this:
```python
In [5]: iatm.headers(2)
Out[5]:
{'Authorization': 'token ghs_randomstuffhere',
'Accept': 'application/vnd.github.v3+json'}
```
The reason that this did not work is that ultimately `GhApi.__call__` is not what was called. Rather it was some lower level thing. Any suggestion on how I can use `ghapi` for a long-running GitHub app where the headers need to be dynamically updated in time?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.