Skip to content

Commit 16bd11b

Browse files
committed
Web3 auth header support for get_user and journal calls
1 parent 7219cdb commit 16bd11b

File tree

4 files changed

+158
-45
lines changed

4 files changed

+158
-45
lines changed

bugout/app.py

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,25 @@ def create_user(
6262
)
6363

6464
def get_user(
65-
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
65+
self,
66+
token: Union[str, uuid.UUID],
67+
timeout: float = REQUESTS_TIMEOUT,
68+
auth_type: str = data.AuthType.bearer.name,
6669
) -> data.BugoutUser:
6770
self.user.timeout = timeout
68-
return self.user.get_user(token=token)
71+
return self.user.get_user(token=token, auth_type=data.AuthType[auth_type])
6972

7073
def get_user_by_id(
7174
self,
7275
token: Union[str, uuid.UUID],
7376
user_id: Union[str, uuid.UUID],
7477
timeout: float = REQUESTS_TIMEOUT,
78+
auth_type: str = data.AuthType.bearer.name,
7579
) -> data.BugoutUser:
7680
self.user.timeout = timeout
77-
return self.user.get_user_by_id(token=token, user_id=user_id)
81+
return self.user.get_user_by_id(
82+
token=token, user_id=user_id, auth_type=data.AuthType[auth_type]
83+
)
7884

7985
def find_user(
8086
self,
@@ -470,49 +476,68 @@ def create_journal(
470476
name: str,
471477
journal_type: Optional[Union[str, data.JournalTypes]] = None,
472478
timeout: float = REQUESTS_TIMEOUT,
479+
auth_type: str = data.AuthType.bearer.name,
473480
) -> data.BugoutJournal:
474481
self.journal.timeout = timeout
475482
if journal_type is None:
476483
journal_type = data.JournalTypes.DEFAULT
477484
return self.journal.create_journal(
478-
token=token, name=name, journal_type=data.JournalTypes(journal_type)
485+
token=token,
486+
name=name,
487+
journal_type=data.JournalTypes(journal_type),
488+
auth_type=data.AuthType[auth_type],
479489
)
480490

481491
def list_journals(
482-
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
492+
self,
493+
token: Union[str, uuid.UUID],
494+
timeout: float = REQUESTS_TIMEOUT,
495+
auth_type: str = data.AuthType.bearer.name,
483496
) -> data.BugoutJournals:
484497
self.journal.timeout = timeout
485-
return self.journal.list_journals(token=token)
498+
return self.journal.list_journals(
499+
token=token, auth_type=data.AuthType[auth_type]
500+
)
486501

487502
def get_journal(
488503
self,
489504
token: Union[str, uuid.UUID],
490505
journal_id: Union[str, uuid.UUID],
491506
timeout: float = REQUESTS_TIMEOUT,
507+
auth_type: str = data.AuthType.bearer.name,
492508
) -> data.BugoutJournal:
493509
self.journal.timeout = timeout
494-
return self.journal.get_journal(token=token, journal_id=journal_id)
510+
return self.journal.get_journal(
511+
token=token, journal_id=journal_id, auth_type=data.AuthType[auth_type]
512+
)
495513

496514
def update_journal(
497515
self,
498516
token: Union[str, uuid.UUID],
499517
journal_id: Union[str, uuid.UUID],
500518
name: str,
501519
timeout: float = REQUESTS_TIMEOUT,
520+
auth_type: str = data.AuthType.bearer.name,
502521
) -> data.BugoutJournal:
503522
self.journal.timeout = timeout
504523
return self.journal.update_journal(
505-
token=token, journal_id=journal_id, name=name
524+
token=token,
525+
journal_id=journal_id,
526+
name=name,
527+
auth_type=data.AuthType[auth_type],
506528
)
507529

508530
def delete_journal(
509531
self,
510532
token: Union[str, uuid.UUID],
511533
journal_id: Union[str, uuid.UUID],
512534
timeout: float = REQUESTS_TIMEOUT,
535+
auth_type: str = data.AuthType.bearer.name,
513536
) -> data.BugoutJournal:
514537
self.journal.timeout = timeout
515-
return self.journal.delete_journal(token=token, journal_id=journal_id)
538+
return self.journal.delete_journal(
539+
token=token, journal_id=journal_id, auth_type=data.AuthType[auth_type]
540+
)
516541

517542
# Journal entries
518543
def create_entry(
@@ -526,6 +551,7 @@ def create_entry(
526551
context_id: Optional[str] = None,
527552
context_type: Optional[str] = None,
528553
timeout: float = REQUESTS_TIMEOUT,
554+
auth_type: str = data.AuthType.bearer.name,
529555
) -> data.BugoutJournalEntry:
530556
self.journal.timeout = timeout
531557
return self.journal.create_entry(
@@ -537,6 +563,7 @@ def create_entry(
537563
context_url=context_url,
538564
context_id=context_id,
539565
context_type=context_type,
566+
auth_type=data.AuthType[auth_type],
540567
)
541568

542569
def create_entries_pack(
@@ -545,6 +572,7 @@ def create_entries_pack(
545572
journal_id: Union[str, uuid.UUID],
546573
entries: List[Dict[str, Any]],
547574
timeout: float = REQUESTS_TIMEOUT,
575+
auth_type: str = data.AuthType.bearer.name,
548576
) -> data.BugoutJournalEntries:
549577
self.journal.timeout = timeout
550578
entries_obj = data.BugoutJournalEntriesRequest(
@@ -554,6 +582,7 @@ def create_entries_pack(
554582
token=token,
555583
journal_id=journal_id,
556584
entries=entries_obj,
585+
auth_type=data.AuthType[auth_type],
557586
)
558587

559588
def get_entry(
@@ -562,31 +591,42 @@ def get_entry(
562591
journal_id: Union[str, uuid.UUID],
563592
entry_id: Union[str, uuid.UUID],
564593
timeout: float = REQUESTS_TIMEOUT,
594+
auth_type: str = data.AuthType.bearer.name,
565595
) -> data.BugoutJournalEntry:
566596
self.journal.timeout = timeout
567597
return self.journal.get_entry(
568-
token=token, journal_id=journal_id, entry_id=entry_id
598+
token=token,
599+
journal_id=journal_id,
600+
entry_id=entry_id,
601+
auth_type=data.AuthType[auth_type],
569602
)
570603

571604
def get_entries(
572605
self,
573606
token: Union[str, uuid.UUID],
574607
journal_id: Union[str, uuid.UUID],
575608
timeout: float = REQUESTS_TIMEOUT,
609+
auth_type: str = data.AuthType.bearer.name,
576610
) -> data.BugoutJournalEntries:
577611
self.journal.timeout = timeout
578-
return self.journal.get_entries(token=token, journal_id=journal_id)
612+
return self.journal.get_entries(
613+
token=token, journal_id=journal_id, auth_type=data.AuthType[auth_type]
614+
)
579615

580616
def get_entry_content(
581617
self,
582618
token: Union[str, uuid.UUID],
583619
journal_id: Union[str, uuid.UUID],
584620
entry_id: Union[str, uuid.UUID],
585621
timeout: float = REQUESTS_TIMEOUT,
622+
auth_type: str = data.AuthType.bearer.name,
586623
) -> data.BugoutJournalEntryContent:
587624
self.journal.timeout = timeout
588625
return self.journal.get_entry_content(
589-
token=token, journal_id=journal_id, entry_id=entry_id
626+
token=token,
627+
journal_id=journal_id,
628+
entry_id=entry_id,
629+
auth_type=data.AuthType[auth_type],
590630
)
591631

592632
def update_entry_content(
@@ -599,6 +639,7 @@ def update_entry_content(
599639
timeout: float = REQUESTS_TIMEOUT,
600640
tags: Optional[List[str]] = None,
601641
tags_action: TagsAction = TagsAction.merge,
642+
auth_type: str = data.AuthType.bearer.name,
602643
) -> data.BugoutJournalEntryContent:
603644
self.journal.timeout = timeout
604645
return self.journal.update_entry_content(
@@ -609,6 +650,7 @@ def update_entry_content(
609650
content=content,
610651
tags=tags,
611652
tags_action=tags_action,
653+
auth_type=data.AuthType[auth_type],
612654
)
613655

614656
def delete_entry(
@@ -617,10 +659,14 @@ def delete_entry(
617659
journal_id: Union[str, uuid.UUID],
618660
entry_id: Union[str, uuid.UUID],
619661
timeout: float = REQUESTS_TIMEOUT,
662+
auth_type: str = data.AuthType.bearer.name,
620663
) -> data.BugoutJournalEntry:
621664
self.journal.timeout = timeout
622665
return self.journal.delete_entry(
623-
token=token, journal_id=journal_id, entry_id=entry_id
666+
token=token,
667+
journal_id=journal_id,
668+
entry_id=entry_id,
669+
auth_type=data.AuthType[auth_type],
624670
)
625671

626672
# Tags
@@ -640,10 +686,15 @@ def create_tags(
640686
entry_id: Union[str, uuid.UUID],
641687
tags: List[str],
642688
timeout: float = REQUESTS_TIMEOUT,
689+
auth_type: str = data.AuthType.bearer.name,
643690
) -> List[Any]:
644691
self.journal.timeout = timeout
645692
return self.journal.create_tags(
646-
token=token, journal_id=journal_id, entry_id=entry_id, tags=tags
693+
token=token,
694+
journal_id=journal_id,
695+
entry_id=entry_id,
696+
tags=tags,
697+
auth_type=data.AuthType[auth_type],
647698
)
648699

649700
def get_tags(
@@ -652,10 +703,14 @@ def get_tags(
652703
journal_id: Union[str, uuid.UUID],
653704
entry_id: Union[str, uuid.UUID],
654705
timeout: float = REQUESTS_TIMEOUT,
706+
auth_type: str = data.AuthType.bearer.name,
655707
) -> data.BugoutJournalEntryTags:
656708
self.journal.timeout = timeout
657709
return self.journal.get_tags(
658-
token=token, journal_id=journal_id, entry_id=entry_id
710+
token=token,
711+
journal_id=journal_id,
712+
entry_id=entry_id,
713+
auth_type=data.AuthType[auth_type],
659714
)
660715

661716
def update_tags(
@@ -665,10 +720,15 @@ def update_tags(
665720
entry_id: Union[str, uuid.UUID],
666721
tags: List[str],
667722
timeout: float = REQUESTS_TIMEOUT,
723+
auth_type: str = data.AuthType.bearer.name,
668724
) -> List[Any]:
669725
self.journal.timeout = timeout
670726
return self.journal.update_tags(
671-
token=token, journal_id=journal_id, entry_id=entry_id, tags=tags
727+
token=token,
728+
journal_id=journal_id,
729+
entry_id=entry_id,
730+
tags=tags,
731+
auth_type=data.AuthType[auth_type],
672732
)
673733

674734
def delete_tag(
@@ -678,10 +738,15 @@ def delete_tag(
678738
entry_id: Union[str, uuid.UUID],
679739
tag: str,
680740
timeout: float = REQUESTS_TIMEOUT,
741+
auth_type: str = data.AuthType.bearer.name,
681742
) -> data.BugoutJournalEntryTags:
682743
self.journal.timeout = timeout
683744
return self.journal.delete_tag(
684-
token=token, journal_id=journal_id, entry_id=entry_id, tag=tag
745+
token=token,
746+
journal_id=journal_id,
747+
entry_id=entry_id,
748+
tag=tag,
749+
auth_type=data.AuthType[auth_type],
685750
)
686751

687752
# Search
@@ -696,10 +761,19 @@ def search(
696761
content: bool = True,
697762
timeout: float = REQUESTS_TIMEOUT,
698763
order: SearchOrder = SearchOrder.DESCENDING,
764+
auth_type: str = data.AuthType.bearer.name,
699765
) -> data.BugoutSearchResults:
700766
self.journal.timeout = timeout
701767
return self.journal.search(
702-
token, journal_id, query, filters, limit, offset, content, order=order
768+
token,
769+
journal_id,
770+
query,
771+
filters,
772+
limit,
773+
offset,
774+
content,
775+
order=order,
776+
auth_type=data.AuthType[auth_type],
703777
)
704778

705779
# Public

bugout/data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)