Skip to content

Commit d28278f

Browse files
authored
Merge pull request #39 from bugout-dev/web3-users
Signature user creation and Web3 auth header support for get_user and journal calls
2 parents a54c9a5 + fd727e6 commit d28278f

File tree

9 files changed

+214
-75
lines changed

9 files changed

+214
-75
lines changed

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.20"
10+
__version__ = "0.2.1"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 108 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from typing import Any, Dict, List, Optional, Union
21
import uuid
2+
from typing import Any, Dict, List, Optional, Union
33

44
from . import data
55
from .calls import ping
66
from .group import Group
77
from .humbug import Humbug
88
from .journal import Journal, SearchOrder, TagsAction
99
from .resource import Resource
10-
from .user import User
1110
from .settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, REQUESTS_TIMEOUT
11+
from .user import User
1212

1313

1414
class Bugout:
@@ -43,9 +43,10 @@ def spire_ping(self) -> Dict[str, str]:
4343
# User handlers
4444
def create_user(
4545
self,
46-
username: str,
47-
email: str,
48-
password: str,
46+
username: Optional[str] = None,
47+
email: Optional[str] = None,
48+
password: Optional[str] = None,
49+
signature: Optional[str] = None,
4950
application_id: Optional[Union[str, uuid.UUID]] = None,
5051
timeout: float = REQUESTS_TIMEOUT,
5152
**kwargs: Dict[str, Any],
@@ -55,24 +56,40 @@ def create_user(
5556
username=username,
5657
email=email,
5758
password=password,
59+
signature=signature,
5860
application_id=application_id,
5961
**kwargs,
6062
)
6163

6264
def get_user(
63-
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
65+
self,
66+
token: Union[str, uuid.UUID],
67+
application_id: Optional[Union[str, uuid.UUID]] = None,
68+
timeout: float = REQUESTS_TIMEOUT,
69+
auth_type: str = data.AuthType.bearer.name,
6470
) -> data.BugoutUser:
6571
self.user.timeout = timeout
66-
return self.user.get_user(token=token)
72+
return self.user.get_user(
73+
token=token,
74+
application_id=application_id,
75+
auth_type=data.AuthType[auth_type],
76+
)
6777

6878
def get_user_by_id(
6979
self,
7080
token: Union[str, uuid.UUID],
7181
user_id: Union[str, uuid.UUID],
82+
application_id: Optional[Union[str, uuid.UUID]] = None,
7283
timeout: float = REQUESTS_TIMEOUT,
84+
auth_type: str = data.AuthType.bearer.name,
7385
) -> data.BugoutUser:
7486
self.user.timeout = timeout
75-
return self.user.get_user_by_id(token=token, user_id=user_id)
87+
return self.user.get_user_by_id(
88+
token=token,
89+
user_id=user_id,
90+
application_id=application_id,
91+
auth_type=data.AuthType[auth_type],
92+
)
7693

7794
def find_user(
7895
self,
@@ -468,49 +485,68 @@ def create_journal(
468485
name: str,
469486
journal_type: Optional[Union[str, data.JournalTypes]] = None,
470487
timeout: float = REQUESTS_TIMEOUT,
488+
auth_type: str = data.AuthType.bearer.name,
471489
) -> data.BugoutJournal:
472490
self.journal.timeout = timeout
473491
if journal_type is None:
474492
journal_type = data.JournalTypes.DEFAULT
475493
return self.journal.create_journal(
476-
token=token, name=name, journal_type=data.JournalTypes(journal_type)
494+
token=token,
495+
name=name,
496+
journal_type=data.JournalTypes(journal_type),
497+
auth_type=data.AuthType[auth_type],
477498
)
478499

479500
def list_journals(
480-
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
501+
self,
502+
token: Union[str, uuid.UUID],
503+
timeout: float = REQUESTS_TIMEOUT,
504+
auth_type: str = data.AuthType.bearer.name,
481505
) -> data.BugoutJournals:
482506
self.journal.timeout = timeout
483-
return self.journal.list_journals(token=token)
507+
return self.journal.list_journals(
508+
token=token, auth_type=data.AuthType[auth_type]
509+
)
484510

485511
def get_journal(
486512
self,
487513
token: Union[str, uuid.UUID],
488514
journal_id: Union[str, uuid.UUID],
489515
timeout: float = REQUESTS_TIMEOUT,
516+
auth_type: str = data.AuthType.bearer.name,
490517
) -> data.BugoutJournal:
491518
self.journal.timeout = timeout
492-
return self.journal.get_journal(token=token, journal_id=journal_id)
519+
return self.journal.get_journal(
520+
token=token, journal_id=journal_id, auth_type=data.AuthType[auth_type]
521+
)
493522

494523
def update_journal(
495524
self,
496525
token: Union[str, uuid.UUID],
497526
journal_id: Union[str, uuid.UUID],
498527
name: str,
499528
timeout: float = REQUESTS_TIMEOUT,
529+
auth_type: str = data.AuthType.bearer.name,
500530
) -> data.BugoutJournal:
501531
self.journal.timeout = timeout
502532
return self.journal.update_journal(
503-
token=token, journal_id=journal_id, name=name
533+
token=token,
534+
journal_id=journal_id,
535+
name=name,
536+
auth_type=data.AuthType[auth_type],
504537
)
505538

506539
def delete_journal(
507540
self,
508541
token: Union[str, uuid.UUID],
509542
journal_id: Union[str, uuid.UUID],
510543
timeout: float = REQUESTS_TIMEOUT,
544+
auth_type: str = data.AuthType.bearer.name,
511545
) -> data.BugoutJournal:
512546
self.journal.timeout = timeout
513-
return self.journal.delete_journal(token=token, journal_id=journal_id)
547+
return self.journal.delete_journal(
548+
token=token, journal_id=journal_id, auth_type=data.AuthType[auth_type]
549+
)
514550

515551
# Journal entries
516552
def create_entry(
@@ -524,6 +560,7 @@ def create_entry(
524560
context_id: Optional[str] = None,
525561
context_type: Optional[str] = None,
526562
timeout: float = REQUESTS_TIMEOUT,
563+
auth_type: str = data.AuthType.bearer.name,
527564
) -> data.BugoutJournalEntry:
528565
self.journal.timeout = timeout
529566
return self.journal.create_entry(
@@ -535,6 +572,7 @@ def create_entry(
535572
context_url=context_url,
536573
context_id=context_id,
537574
context_type=context_type,
575+
auth_type=data.AuthType[auth_type],
538576
)
539577

540578
def create_entries_pack(
@@ -543,6 +581,7 @@ def create_entries_pack(
543581
journal_id: Union[str, uuid.UUID],
544582
entries: List[Dict[str, Any]],
545583
timeout: float = REQUESTS_TIMEOUT,
584+
auth_type: str = data.AuthType.bearer.name,
546585
) -> data.BugoutJournalEntries:
547586
self.journal.timeout = timeout
548587
entries_obj = data.BugoutJournalEntriesRequest(
@@ -552,6 +591,7 @@ def create_entries_pack(
552591
token=token,
553592
journal_id=journal_id,
554593
entries=entries_obj,
594+
auth_type=data.AuthType[auth_type],
555595
)
556596

557597
def get_entry(
@@ -560,31 +600,42 @@ def get_entry(
560600
journal_id: Union[str, uuid.UUID],
561601
entry_id: Union[str, uuid.UUID],
562602
timeout: float = REQUESTS_TIMEOUT,
603+
auth_type: str = data.AuthType.bearer.name,
563604
) -> data.BugoutJournalEntry:
564605
self.journal.timeout = timeout
565606
return self.journal.get_entry(
566-
token=token, journal_id=journal_id, entry_id=entry_id
607+
token=token,
608+
journal_id=journal_id,
609+
entry_id=entry_id,
610+
auth_type=data.AuthType[auth_type],
567611
)
568612

569613
def get_entries(
570614
self,
571615
token: Union[str, uuid.UUID],
572616
journal_id: Union[str, uuid.UUID],
573617
timeout: float = REQUESTS_TIMEOUT,
618+
auth_type: str = data.AuthType.bearer.name,
574619
) -> data.BugoutJournalEntries:
575620
self.journal.timeout = timeout
576-
return self.journal.get_entries(token=token, journal_id=journal_id)
621+
return self.journal.get_entries(
622+
token=token, journal_id=journal_id, auth_type=data.AuthType[auth_type]
623+
)
577624

578625
def get_entry_content(
579626
self,
580627
token: Union[str, uuid.UUID],
581628
journal_id: Union[str, uuid.UUID],
582629
entry_id: Union[str, uuid.UUID],
583630
timeout: float = REQUESTS_TIMEOUT,
631+
auth_type: str = data.AuthType.bearer.name,
584632
) -> data.BugoutJournalEntryContent:
585633
self.journal.timeout = timeout
586634
return self.journal.get_entry_content(
587-
token=token, journal_id=journal_id, entry_id=entry_id
635+
token=token,
636+
journal_id=journal_id,
637+
entry_id=entry_id,
638+
auth_type=data.AuthType[auth_type],
588639
)
589640

590641
def update_entry_content(
@@ -597,6 +648,7 @@ def update_entry_content(
597648
timeout: float = REQUESTS_TIMEOUT,
598649
tags: Optional[List[str]] = None,
599650
tags_action: TagsAction = TagsAction.merge,
651+
auth_type: str = data.AuthType.bearer.name,
600652
) -> data.BugoutJournalEntryContent:
601653
self.journal.timeout = timeout
602654
return self.journal.update_entry_content(
@@ -607,6 +659,7 @@ def update_entry_content(
607659
content=content,
608660
tags=tags,
609661
tags_action=tags_action,
662+
auth_type=data.AuthType[auth_type],
610663
)
611664

612665
def delete_entry(
@@ -615,10 +668,14 @@ def delete_entry(
615668
journal_id: Union[str, uuid.UUID],
616669
entry_id: Union[str, uuid.UUID],
617670
timeout: float = REQUESTS_TIMEOUT,
671+
auth_type: str = data.AuthType.bearer.name,
618672
) -> data.BugoutJournalEntry:
619673
self.journal.timeout = timeout
620674
return self.journal.delete_entry(
621-
token=token, journal_id=journal_id, entry_id=entry_id
675+
token=token,
676+
journal_id=journal_id,
677+
entry_id=entry_id,
678+
auth_type=data.AuthType[auth_type],
622679
)
623680

624681
# Tags
@@ -638,10 +695,15 @@ def create_tags(
638695
entry_id: Union[str, uuid.UUID],
639696
tags: List[str],
640697
timeout: float = REQUESTS_TIMEOUT,
698+
auth_type: str = data.AuthType.bearer.name,
641699
) -> List[Any]:
642700
self.journal.timeout = timeout
643701
return self.journal.create_tags(
644-
token=token, journal_id=journal_id, entry_id=entry_id, tags=tags
702+
token=token,
703+
journal_id=journal_id,
704+
entry_id=entry_id,
705+
tags=tags,
706+
auth_type=data.AuthType[auth_type],
645707
)
646708

647709
def get_tags(
@@ -650,10 +712,14 @@ def get_tags(
650712
journal_id: Union[str, uuid.UUID],
651713
entry_id: Union[str, uuid.UUID],
652714
timeout: float = REQUESTS_TIMEOUT,
715+
auth_type: str = data.AuthType.bearer.name,
653716
) -> data.BugoutJournalEntryTags:
654717
self.journal.timeout = timeout
655718
return self.journal.get_tags(
656-
token=token, journal_id=journal_id, entry_id=entry_id
719+
token=token,
720+
journal_id=journal_id,
721+
entry_id=entry_id,
722+
auth_type=data.AuthType[auth_type],
657723
)
658724

659725
def update_tags(
@@ -663,10 +729,15 @@ def update_tags(
663729
entry_id: Union[str, uuid.UUID],
664730
tags: List[str],
665731
timeout: float = REQUESTS_TIMEOUT,
732+
auth_type: str = data.AuthType.bearer.name,
666733
) -> List[Any]:
667734
self.journal.timeout = timeout
668735
return self.journal.update_tags(
669-
token=token, journal_id=journal_id, entry_id=entry_id, tags=tags
736+
token=token,
737+
journal_id=journal_id,
738+
entry_id=entry_id,
739+
tags=tags,
740+
auth_type=data.AuthType[auth_type],
670741
)
671742

672743
def delete_tag(
@@ -676,10 +747,15 @@ def delete_tag(
676747
entry_id: Union[str, uuid.UUID],
677748
tag: str,
678749
timeout: float = REQUESTS_TIMEOUT,
750+
auth_type: str = data.AuthType.bearer.name,
679751
) -> data.BugoutJournalEntryTags:
680752
self.journal.timeout = timeout
681753
return self.journal.delete_tag(
682-
token=token, journal_id=journal_id, entry_id=entry_id, tag=tag
754+
token=token,
755+
journal_id=journal_id,
756+
entry_id=entry_id,
757+
tag=tag,
758+
auth_type=data.AuthType[auth_type],
683759
)
684760

685761
# Search
@@ -694,10 +770,19 @@ def search(
694770
content: bool = True,
695771
timeout: float = REQUESTS_TIMEOUT,
696772
order: SearchOrder = SearchOrder.DESCENDING,
773+
auth_type: str = data.AuthType.bearer.name,
697774
) -> data.BugoutSearchResults:
698775
self.journal.timeout = timeout
699776
return self.journal.search(
700-
token, journal_id, query, filters, limit, offset, content, order=order
777+
token,
778+
journal_id,
779+
query,
780+
filters,
781+
limit,
782+
offset,
783+
content,
784+
order=order,
785+
auth_type=data.AuthType[auth_type],
701786
)
702787

703788
# Public

bugout/data.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import uuid
12
from datetime import datetime
23
from enum import Enum, unique
34
from typing import Any, Dict, List, Optional, Set
4-
import uuid
55

66
from pydantic import BaseModel, Field
77

@@ -33,6 +33,11 @@ class HolderType(Enum):
3333
group = "group"
3434

3535

36+
class AuthType(Enum):
37+
bearer = "Bearer"
38+
web3 = "Web3"
39+
40+
3641
class JournalTypes(Enum):
3742
DEFAULT = "default"
3843
HUMBUG = "humbug"
@@ -43,6 +48,7 @@ class BugoutUser(BaseModel):
4348
username: str
4449
email: Optional[str]
4550
normalized_email: Optional[str]
51+
web3_address: Optional[str]
4652
verified: Optional[bool]
4753
autogenerated: Optional[bool]
4854
application_id: Optional[uuid.UUID]

0 commit comments

Comments
 (0)