Skip to content

Commit ef5b50a

Browse files
authored
Merge pull request #19 from bugout-dev/humbug-availability
Humbug integration compatibility
2 parents ed47a69 + 6daceb4 commit ef5b50a

4 files changed

Lines changed: 44 additions & 11 deletions

File tree

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.1.6"
10+
__version__ = "0.1.7"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ def delete_user(
121121
self,
122122
token: Union[str, uuid.UUID],
123123
user_id: Union[str, uuid.UUID],
124-
password: str,
124+
password: Optional[str] = None,
125125
timeout: float = REQUESTS_TIMEOUT,
126+
**kwargs: Dict[str, Any],
126127
) -> data.BugoutUser:
127128
self.user.timeout = timeout
128-
return self.user.delete_user(token=token, user_id=user_id, password=password)
129+
return self.user.delete_user(
130+
token=token, user_id=user_id, password=password, **kwargs
131+
)
129132

130133
# Token handlers
131134
def create_token(
@@ -134,11 +137,22 @@ def create_token(
134137
self.user.timeout = timeout
135138
return self.user.create_token(username=username, password=password)
136139

140+
def create_token_restricted(
141+
self,
142+
token: Union[str, uuid.UUID],
143+
timeout: float = REQUESTS_TIMEOUT,
144+
) -> data.BugoutToken:
145+
self.user.timeout = timeout
146+
return self.user.create_token_restricted(token=token)
147+
137148
def revoke_token(
138-
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
149+
self,
150+
token: Union[str, uuid.UUID],
151+
target_token: Optional[Union[str, uuid.UUID]] = None,
152+
timeout: float = REQUESTS_TIMEOUT,
139153
) -> uuid.UUID:
140154
self.user.timeout = timeout
141-
return self.user.revoke_token(token=token)
155+
return self.user.revoke_token(token=token, target_token=target_token)
142156

143157
def revoke_token_by_id(
144158
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT

bugout/data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class BugoutToken(BaseModel):
5757
active: bool
5858
token_type: Optional[str]
5959
note: Optional[str]
60+
restricted: Optional[bool]
6061
created_at: datetime
6162
updated_at: datetime
6263

bugout/user.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,18 @@ def delete_user(
142142
self,
143143
token: Union[str, uuid.UUID],
144144
user_id: Union[str, uuid.UUID],
145-
password: str,
145+
password: Optional[str] = None,
146+
**kwargs: Dict[str, Any],
146147
) -> BugoutUser:
147148
delete_user_path = f"user/{user_id}"
148-
data = {
149-
"password": password,
150-
}
149+
data = {}
150+
if password is not None:
151+
data.update({"password": password})
151152
headers = {
152153
"Authorization": f"Bearer {token}",
153154
}
155+
if "headers" in kwargs.keys():
156+
headers.update(kwargs["headers"])
154157
result = self._call(
155158
method=Method.delete, path=delete_user_path, headers=headers, data=data
156159
)
@@ -166,13 +169,28 @@ def create_token(self, username: str, password: str) -> BugoutToken:
166169
result = self._call(method=Method.post, path=create_token_path, data=data)
167170
return BugoutToken(**result)
168171

169-
def revoke_token(self, token: Union[str, uuid.UUID]) -> uuid.UUID:
172+
def create_token_restricted(self, token: Union[str, uuid.UUID]) -> BugoutToken:
173+
create_token_path = "token/restricted"
174+
headers = {
175+
"Authorization": f"Bearer {token}",
176+
}
177+
result = self._call(method=Method.post, path=create_token_path, headers=headers)
178+
return BugoutToken(**result)
179+
180+
def revoke_token(
181+
self,
182+
token: Union[str, uuid.UUID],
183+
target_token: Optional[Union[str, uuid.UUID]] = None,
184+
) -> uuid.UUID:
170185
revoke_token_path = "token"
171186
headers = {
172187
"Authorization": f"Bearer {token}",
173188
}
189+
data = {}
190+
if target_token is not None:
191+
data.update({"target_token": target_token})
174192
result = self._call(
175-
method=Method.delete, path=revoke_token_path, headers=headers
193+
method=Method.delete, path=revoke_token_path, headers=headers, data=data
176194
)
177195
return result
178196

0 commit comments

Comments
 (0)