Skip to content

Commit 8f7c411

Browse files
authored
Merge pull request #58 from bugout-dev/auth-endpoint
Auth endpoint for users
2 parents 19d4b83 + af4d962 commit 8f7c411

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

.isort.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[settings]
2+
profile = black
3+
multi_line_output = 3

bugout/__init__.py

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

99
__email__ = "[email protected]"
1010
__license__ = "MIT"
11-
__version__ = "0.2.16"
11+
__version__ = "0.2.17"
1212

1313
__all__ = (
1414
"__author__",

bugout/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ def spire_ping(self) -> Dict[str, str]:
4141
return ping(self.spire_api_url)
4242

4343
# User handlers
44+
def auth(
45+
self,
46+
token: Union[str, uuid.UUID],
47+
timeout: float = REQUESTS_TIMEOUT,
48+
auth_type: str = data.AuthType.bearer.name,
49+
**kwargs: Dict[str, Any],
50+
):
51+
self.user.timeout = timeout
52+
return self.user.auth(
53+
token=token,
54+
auth_type=data.AuthType[auth_type],
55+
**kwargs,
56+
)
57+
4458
def create_user(
4559
self,
4660
username: Optional[str] = None,

bugout/data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class BugoutGroup(BaseModel):
9797
id: uuid.UUID
9898
group_name: Optional[str] = Field(alias="name")
9999
autogenerated: bool
100+
parent: Optional[uuid.UUID] = None
101+
application_id: Optional[uuid.UUID] = None
100102

101103

102104
class BugoutGroupUser(BaseModel):
@@ -105,6 +107,12 @@ class BugoutGroupUser(BaseModel):
105107
user_type: str
106108
autogenerated: Optional[bool] = None
107109
group_name: Optional[str] = None
110+
parent: Optional[uuid.UUID] = None
111+
application_id: Optional[uuid.UUID] = None
112+
113+
114+
class BugoutUserWithGroups(BugoutUser):
115+
groups: List[BugoutGroupUser] = Field(default_factory=list)
108116

109117

110118
class BugoutUserGroups(BaseModel):

bugout/jobs.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@
44
"""
55

66
import argparse
7-
from datetime import datetime
8-
from enum import Enum
97
import json
108
import os
9+
from datetime import datetime
10+
from enum import Enum
11+
from typing import Callable, List, Optional
12+
1113
import requests # type: ignore
12-
from typing import Callable, Optional, List
1314

1415
from .app import Bugout
15-
from .data import (
16-
AuthType,
17-
BugoutSearchResultWithEntryID,
18-
BugoutSearchResult,
19-
BugoutSearchResult,
20-
)
16+
from .data import AuthType, BugoutSearchResult, BugoutSearchResultWithEntryID
2117
from .journal import SearchOrder
2218
from .settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, REQUESTS_TIMEOUT
2319

24-
2520
DEFAULT_CONTEXT_TYPE = "job"
2621
DEFAULT_SUCCESS_TAG = "job:success"
2722
DEFAULT_FAILURE_TAG = "job:failure"

bugout/resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from .calls import make_request
66
from .data import (
77
BugoutResource,
8-
BugoutResources,
9-
Method,
108
BugoutResourceHolder,
119
BugoutResourceHolders,
10+
BugoutResources,
11+
Method,
1212
)
1313
from .exceptions import InvalidUrlSpec
1414
from .settings import REQUESTS_TIMEOUT

bugout/user.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
from typing import Any, Dict, List, Optional, Union
33

44
from .calls import make_request
5-
from .data import AuthType, BugoutToken, BugoutUser, BugoutUserTokens, Method, TokenType
5+
from .data import (
6+
AuthType,
7+
BugoutToken,
8+
BugoutUser,
9+
BugoutUserTokens,
10+
BugoutUserWithGroups,
11+
Method,
12+
TokenType,
13+
)
614
from .exceptions import InvalidUrlSpec, TokenInvalidParameters
7-
from .settings import REQUESTS_TIMEOUT, BUGOUT_APPLICATION_ID_HEADER
15+
from .settings import BUGOUT_APPLICATION_ID_HEADER, REQUESTS_TIMEOUT
816

917

1018
class User:
@@ -26,6 +34,20 @@ def _call(self, method: Method, path: str, **kwargs):
2634
return result
2735

2836
# User module
37+
def auth(
38+
self,
39+
token: Union[str, uuid.UUID],
40+
auth_type: AuthType = AuthType.bearer,
41+
**kwargs: Dict[str, Any],
42+
) -> BugoutUserWithGroups:
43+
headers = {
44+
"Authorization": f"{auth_type.value} {token}",
45+
}
46+
if "headers" in kwargs.keys():
47+
headers.update(kwargs["headers"])
48+
result = self._call(method=Method.get, path="auth", headers=headers)
49+
return BugoutUserWithGroups(**result)
50+
2951
def create_user(
3052
self,
3153
username: Optional[str] = None,

0 commit comments

Comments
 (0)