def get_installation_info(self, installation_data, access_token, installation_id): session = http.build_session() resp = session.get( "https://{}/api/v3/app/installations/{}".format( installation_data["url"], installation_id ), headers={ "Authorization": b"Bearer %s" % get_jwt( github_id=installation_data["id"], github_private_key=installation_data["private_key"], ), "Accept": "application/vnd.github.machine-man-preview+json", }, verify=installation_data["verify_ssl"], ) resp.raise_for_status() installation_resp = resp.json() resp = session.get( "https://{}/api/v3/user/installations".format(installation_data["url"]), params={"access_token": access_token}, headers={"Accept": "application/vnd.github.machine-man-preview+json"}, verify=installation_data["verify_ssl"], ) resp.raise_for_status() user_installations_resp = resp.json() # verify that user actually has access to the installation for installation in user_installations_resp["installations"]: if installation["id"] == installation_resp["id"]: return installation_resp return None
def get_installation_info(self, installation_data, access_token, installation_id): session = http.build_session() resp = session.get( u'https://{}/api/v3/app/installations/{}'.format( installation_data['url'], installation_id), headers={ 'Authorization': 'Bearer %s' % get_jwt(github_id=installation_data['id'], github_private_key=installation_data['private_key']), 'Accept': 'application/vnd.github.machine-man-preview+json', }, verify=installation_data['verify_ssl'] ) resp.raise_for_status() installation_resp = resp.json() resp = session.get( u'https://{}/api/v3/user/installations'.format(installation_data['url']), params={'access_token': access_token}, headers={'Accept': 'application/vnd.github.machine-man-preview+json'}, verify=installation_data['verify_ssl'] ) resp.raise_for_status() user_installations_resp = resp.json() # verify that user actually has access to the installation for installation in user_installations_resp['installations']: if installation['id'] == installation_resp['id']: return installation_resp return None
def get_installation_info(self, installation_data, access_token, installation_id): session = http.build_session() resp = session.get( 'https://{}/api/v3/app/installations/{}'.format( installation_data['url'], installation_id), headers={ 'Authorization': 'Bearer %s' % get_jwt(github_id=installation_data['id'], github_private_key=installation_data['private_key']), 'Accept': 'application/vnd.github.machine-man-preview+json', }, verify=False) resp.raise_for_status() installation_resp = resp.json() resp = session.get( 'https://{}/api/v3/user/installations'.format( installation_data['url']), params={'access_token': access_token}, headers={ 'Accept': 'application/vnd.github.machine-man-preview+json' }, verify=False) resp.raise_for_status() user_installations_resp = resp.json() # verify that user actually has access to the installation for installation in user_installations_resp['installations']: if installation['id'] == installation_resp['id']: return installation_resp return None
def create_token(self): return self.post( '/installations/{}/access_tokens'.format(self.external_id, ), headers={ 'Authorization': 'Bearer %s' % get_jwt(), # TODO(jess): remove this whenever it's out of preview 'Accept': 'application/vnd.github.machine-man-preview+json', }, )
def get_installation_info(self, installation_data, access_token, installation_id): headers = { # TODO(jess): remove this whenever it's out of preview "Accept": "application/vnd.github.machine-man-preview+json", } headers.update( jwt.authorization_header( get_jwt( github_id=installation_data["id"], github_private_key=installation_data["private_key"], ) ) ) with http.build_session() as session: resp = session.get( f"https://{installation_data['url']}/api/v3/app/installations/{installation_id}", headers=headers, verify=installation_data["verify_ssl"], ) resp.raise_for_status() installation_resp = resp.json() resp = session.get( f"https://{installation_data['url']}/api/v3/user/installations", headers={ "Accept": "application/vnd.github.machine-man-preview+json", "Authorization": f"token {access_token}", }, verify=installation_data["verify_ssl"], ) resp.raise_for_status() user_installations_resp = resp.json() # verify that user actually has access to the installation for installation in user_installations_resp["installations"]: if installation["id"] == installation_resp["id"]: return installation_resp return None
def get_jwt(self): return get_jwt()
def get_jwt(self): return get_jwt()
def get_jwt(self): return get_jwt(github_id=self.app_id, github_private_key=self.private_key)
def get_jwt(self): return get_jwt(github_id=self.app_id, github_private_key=self.private_key)
def get_jwt(self) -> str: return get_jwt()