Skip to content

Make bearer auth per session instead of per request #6

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

Merged
merged 1 commit into from
May 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions reportportal_client/service.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import requests
from requests.auth import AuthBase

from .model import (EntryCreatedRS, OperationCompletionRS)


class BearerAuth(AuthBase):
"""Attaches HTTP Bearer Authentication to the given Request object."""
def __init__(self, token):
self.token = token

def __call__(self, r):
r.headers["Authorization"] = "bearer {0}".format(self.token)
return r


class ReportPortalService(object):
"""Service class with report portal event callbacks."""

Expand All @@ -35,8 +24,9 @@ def __init__(self, endpoint, project, token, api_base=None):
self.base_url = self.uri_join(self.endpoint,
self.api_base,
self.project)

self.session = requests.Session()
self.session.auth = BearerAuth(self.token)
self.session.headers["Authorization"] = "bearer {0}".format(self.token)

@staticmethod
def uri_join(*uri_parts):
Expand Down