"""Module containing helpers for dealing with GitHub Apps.
https://developer.github.com/apps/building-github-apps/
"""
import time
from jwcrypto import jwk
from jwcrypto import jwt
from . import models
from . import users
TEN_MINUTES_AS_SECONDS = 10 * 60
DEFAULT_JWT_TOKEN_EXPIRATION = TEN_MINUTES_AS_SECONDS
APP_PREVIEW_HEADERS = {
"Accept": "application/vnd.github.machine-man-preview+json"
}
class App(models.GitHubCore):
"""An object representing a GitHub App.
.. versionadded:: 1.2.0
.. seealso::
`GitHub Apps`_
Documentation for Apps on GitHub
`GitHub Apps API Documentation`_
API documentation of what's available about an App.
This object has the following attributes:
.. attribute:: created_at
A :class:`~datetime.datetime` object representing the day and time
the App was created.
.. attribute:: description
The description of the App provided by the owner.
.. attribute:: external_url
The URL provided for the App by the owner.
.. attribute:: html_url
The HTML URL provided for the App by the owner.
.. attribute:: id
The unique identifier for the App. This is useful in cases where you
may want to authenticate either as an App or as a specific
installation of an App.
.. attribute:: name
The display name of the App that the user sees.
.. attribute:: node_id
A base64-encoded blob returned by the GitHub API for who knows what
reason.
.. attribute:: owner
A :class:`~github3.users.ShortUser` object representing the GitHub
user who owns the App.
.. attribute:: updated_at
A :class:`~datetime.datetime` object representing the day and time
the App was last updated.
.. _GitHub Apps:
https://developer.github.com/apps/
.. _GitHub Apps API Documentation:
https://developer.github.com/v3/apps/
"""
CUSTOM_HEADERS = {
"Accept": "application/vnd.github.machine-man-preview+json"
}
def _update_attributes(self, json):
self.created_at = self._strptime(json["created_at"])
self.description = json["description"]
self.external_url = json["external_url"]
self.html_url = json["html_url"]
self.id = json["id"]
self.name = json["name"]
self.node_id = json["node_id"]
self.owner = users.ShortUser(json["owner"], self)
self.updated_at = self._strptime(json["updated_at"])
_, slug = json["html_url"].rsplit("/", 1)
self._api = self.url = self._build_url("apps", slug)
def _repr(self):
return '