Skip to content

Commit fd727e6

Browse files
committed
Get application user with web3 signature
1 parent 16bd11b commit fd727e6

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

bugout/app.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,31 @@ def create_user(
6464
def get_user(
6565
self,
6666
token: Union[str, uuid.UUID],
67+
application_id: Optional[Union[str, uuid.UUID]] = None,
6768
timeout: float = REQUESTS_TIMEOUT,
6869
auth_type: str = data.AuthType.bearer.name,
6970
) -> data.BugoutUser:
7071
self.user.timeout = timeout
71-
return self.user.get_user(token=token, auth_type=data.AuthType[auth_type])
72+
return self.user.get_user(
73+
token=token,
74+
application_id=application_id,
75+
auth_type=data.AuthType[auth_type],
76+
)
7277

7378
def get_user_by_id(
7479
self,
7580
token: Union[str, uuid.UUID],
7681
user_id: Union[str, uuid.UUID],
82+
application_id: Optional[Union[str, uuid.UUID]] = None,
7783
timeout: float = REQUESTS_TIMEOUT,
7884
auth_type: str = data.AuthType.bearer.name,
7985
) -> data.BugoutUser:
8086
self.user.timeout = timeout
8187
return self.user.get_user_by_id(
82-
token=token, user_id=user_id, auth_type=data.AuthType[auth_type]
88+
token=token,
89+
user_id=user_id,
90+
application_id=application_id,
91+
auth_type=data.AuthType[auth_type],
8392
)
8493

8594
def find_user(

bugout/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@
1212
raise Exception(
1313
f"Could not parse BUGOUT_REQUESTS_TIMEOUT environment variable as int: {REQUESTS_TIMEOUT_RAW}"
1414
)
15+
16+
# Web3 signature
17+
BUGOUT_APPLICATION_ID_HEADER = os.environ.get(
18+
"BUGOUT_APPLICATION_ID_HEADER", "x-bugout-application-id"
19+
)

bugout/user.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .calls import make_request
55
from .data import AuthType, BugoutToken, BugoutUser, BugoutUserTokens, Method, TokenType
66
from .exceptions import InvalidUrlSpec, TokenInvalidParameters
7-
from .settings import REQUESTS_TIMEOUT
7+
from .settings import REQUESTS_TIMEOUT, BUGOUT_APPLICATION_ID_HEADER
88

99

1010
class User:
@@ -52,25 +52,33 @@ def create_user(
5252
return BugoutUser(**result)
5353

5454
def get_user(
55-
self, token: Union[str, uuid.UUID], auth_type: AuthType = AuthType.bearer
55+
self,
56+
token: Union[str, uuid.UUID],
57+
application_id: Optional[Union[str, uuid.UUID]] = None,
58+
auth_type: AuthType = AuthType.bearer,
5659
) -> BugoutUser:
5760
get_user_path = "user"
5861
headers = {
5962
"Authorization": f"{auth_type.value} {token}",
6063
}
64+
if auth_type == AuthType.web3 and application_id is not None:
65+
headers[BUGOUT_APPLICATION_ID_HEADER] = str(application_id)
6166
result = self._call(method=Method.get, path=get_user_path, headers=headers)
6267
return BugoutUser(**result)
6368

6469
def get_user_by_id(
6570
self,
6671
token: Union[str, uuid.UUID],
6772
user_id: Union[str, uuid.UUID],
73+
application_id: Optional[Union[str, uuid.UUID]] = None,
6874
auth_type: AuthType = AuthType.bearer,
6975
) -> BugoutUser:
7076
get_user_by_id_path = f"user/{user_id}"
7177
headers = {
7278
"Authorization": f"{auth_type.value} {token}",
7379
}
80+
if auth_type == AuthType.web3 and application_id is not None:
81+
headers[BUGOUT_APPLICATION_ID_HEADER] = str(application_id)
7482
result = self._call(
7583
method=Method.get, path=get_user_by_id_path, headers=headers
7684
)

0 commit comments

Comments
 (0)