-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use auth strategy for python (#28)
- Loading branch information
1 parent
3f65c2e
commit 930291a
Showing
5 changed files
with
30 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import typing | ||
from .evaluation import Evaluation | ||
from .authentication import AuthenticationStrategy | ||
|
||
|
||
class FliptClient: | ||
def __init__( | ||
self, | ||
url: str = "http://localhost:8080", | ||
client_token: typing.Optional[str] = None, | ||
jwt_token: typing.Optional[str] = None, | ||
timeout: int = 60, | ||
authentication: typing.Optional[AuthenticationStrategy] = None, | ||
): | ||
self.evaluation = Evaluation(url, client_token, jwt_token, timeout) | ||
self.evaluation = Evaluation(url, timeout, authentication) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class AuthenticationStrategy: | ||
def authenticate(self, headers: dict): | ||
raise NotImplementedError() | ||
|
||
|
||
class ClientTokenAuthentication(AuthenticationStrategy): | ||
def __init__(self, token: str): | ||
self.token = token | ||
|
||
def authenticate(self, headers: dict): | ||
headers["Authorization"] = f"Bearer {self.token}" | ||
|
||
|
||
class JWTAuthentication(AuthenticationStrategy): | ||
def __init__(self, token: str): | ||
self.token = token | ||
|
||
def authenticate(self, headers: dict): | ||
headers["Authorization"] = f"JWT {self.token}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import enum | ||
from pydantic import BaseModel, Field | ||
from typing import List, Optional | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters