Skip to content

Commit

Permalink
Merge pull request #58 from bugout-dev/auth-endpoint
Browse files Browse the repository at this point in the history
Auth endpoint for users
  • Loading branch information
kompotkot authored Aug 14, 2024
2 parents 19d4b83 + af4d962 commit 8f7c411
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile = black
multi_line_output = 3
2 changes: 1 addition & 1 deletion bugout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__email__ = "[email protected]"
__license__ = "MIT"
__version__ = "0.2.16"
__version__ = "0.2.17"

__all__ = (
"__author__",
Expand Down
14 changes: 14 additions & 0 deletions bugout/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ def spire_ping(self) -> Dict[str, str]:
return ping(self.spire_api_url)

# User handlers
def auth(
self,
token: Union[str, uuid.UUID],
timeout: float = REQUESTS_TIMEOUT,
auth_type: str = data.AuthType.bearer.name,
**kwargs: Dict[str, Any],
):
self.user.timeout = timeout
return self.user.auth(
token=token,
auth_type=data.AuthType[auth_type],
**kwargs,
)

def create_user(
self,
username: Optional[str] = None,
Expand Down
8 changes: 8 additions & 0 deletions bugout/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class BugoutGroup(BaseModel):
id: uuid.UUID
group_name: Optional[str] = Field(alias="name")
autogenerated: bool
parent: Optional[uuid.UUID] = None
application_id: Optional[uuid.UUID] = None


class BugoutGroupUser(BaseModel):
Expand All @@ -105,6 +107,12 @@ class BugoutGroupUser(BaseModel):
user_type: str
autogenerated: Optional[bool] = None
group_name: Optional[str] = None
parent: Optional[uuid.UUID] = None
application_id: Optional[uuid.UUID] = None


class BugoutUserWithGroups(BugoutUser):
groups: List[BugoutGroupUser] = Field(default_factory=list)


class BugoutUserGroups(BaseModel):
Expand Down
15 changes: 5 additions & 10 deletions bugout/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
"""

import argparse
from datetime import datetime
from enum import Enum
import json
import os
from datetime import datetime
from enum import Enum
from typing import Callable, List, Optional

import requests # type: ignore
from typing import Callable, Optional, List

from .app import Bugout
from .data import (
AuthType,
BugoutSearchResultWithEntryID,
BugoutSearchResult,
BugoutSearchResult,
)
from .data import AuthType, BugoutSearchResult, BugoutSearchResultWithEntryID
from .journal import SearchOrder
from .settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, REQUESTS_TIMEOUT


DEFAULT_CONTEXT_TYPE = "job"
DEFAULT_SUCCESS_TAG = "job:success"
DEFAULT_FAILURE_TAG = "job:failure"
Expand Down
4 changes: 2 additions & 2 deletions bugout/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from .calls import make_request
from .data import (
BugoutResource,
BugoutResources,
Method,
BugoutResourceHolder,
BugoutResourceHolders,
BugoutResources,
Method,
)
from .exceptions import InvalidUrlSpec
from .settings import REQUESTS_TIMEOUT
Expand Down
26 changes: 24 additions & 2 deletions bugout/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
from typing import Any, Dict, List, Optional, Union

from .calls import make_request
from .data import AuthType, BugoutToken, BugoutUser, BugoutUserTokens, Method, TokenType
from .data import (
AuthType,
BugoutToken,
BugoutUser,
BugoutUserTokens,
BugoutUserWithGroups,
Method,
TokenType,
)
from .exceptions import InvalidUrlSpec, TokenInvalidParameters
from .settings import REQUESTS_TIMEOUT, BUGOUT_APPLICATION_ID_HEADER
from .settings import BUGOUT_APPLICATION_ID_HEADER, REQUESTS_TIMEOUT


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

# User module
def auth(
self,
token: Union[str, uuid.UUID],
auth_type: AuthType = AuthType.bearer,
**kwargs: Dict[str, Any],
) -> BugoutUserWithGroups:
headers = {
"Authorization": f"{auth_type.value} {token}",
}
if "headers" in kwargs.keys():
headers.update(kwargs["headers"])
result = self._call(method=Method.get, path="auth", headers=headers)
return BugoutUserWithGroups(**result)

def create_user(
self,
username: Optional[str] = None,
Expand Down

0 comments on commit 8f7c411

Please sign in to comment.