AnswerDotAI / AnswerDotAI/ghapi
How to specify that headers must be regenerated.
- Lingua principale
- Python
- Stelle
- 685
- Fork
- 70
- Merge medio
- 1m
- PR unite (30g)
- 2
Descrizione
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?
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia tracciando il modo in cui le richieste GhApi raggiungono la chiamata di livello inferiore invece di GhApi.__call__, usando la sottoclasse mostrata e IatManager.headers() come punti di ingresso. Determina dove vengono assemblati gli header delle richieste e se possono essere aggiornati per ogni richiesta; il lavoro è completato quando un'app GitHub a esecuzione prolungata può usare header con token di accesso dell'installazione appena generati senza ricreare manualmente GhApi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- github, python
- Ambito
- api, authentication
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100