Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ajermaky committed Apr 30, 2024
1 parent 01445a9 commit a8f6641
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 179 deletions.
4 changes: 2 additions & 2 deletions lib/go/edgecontext/oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func (o OAuthClient) ID() string {
//
// For example, use:
//
// if client.IsType("third_party")
// if client.IsType("third_party")
//
// Instead of:
//
// if !client.IsType("first_party")
// if !client.IsType("first_party")
func (o OAuthClient) IsType(types ...string) bool {
clientType := AuthenticationToken(o).OAuthClientType
for _, t := range types {
Expand Down
9 changes: 9 additions & 0 deletions lib/go/edgecontext/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (s Service) Name() (name string, ok bool) {
return
}

// OnBehalfOfID returns the ID of the user on whose behalf the service is acting.
//
// If it's not coming from an authenticated service,
// ("", false) will be returned.
func (s Service) OnBehalfOfID() (id string, ok bool) {
if s.isService() {
token := AuthenticationToken(s)
Expand All @@ -41,6 +45,10 @@ func (s Service) OnBehalfOfID() (id string, ok bool) {
return
}

// OnBehalfOfRoles returns the roles of the user on whose behalf the service is acting.
//
// If it's not coming from an authenticated service,
// (nil, false) will be returned.
func (s Service) OnBehalfOfRoles() (roles []string, ok bool) {
if s.isService() {
token := AuthenticationToken(s)
Expand All @@ -52,6 +60,7 @@ func (s Service) OnBehalfOfRoles() (roles []string, ok bool) {
return
}

// IsElevatedAccess returns whether the service requested elevated access.
func (s Service) IsElevatedAccess() bool {
if s.isService() {
return AuthenticationToken(s).ServiceRequestedElevatedAccess
Expand Down
9 changes: 3 additions & 6 deletions lib/py/reddit_edgecontext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from baseplate.lib.edgecontext import EdgeContextFactory as BaseEdgeContextFactory
from baseplate.lib.secrets import SecretsStore
from jwt.algorithms import get_default_algorithms
from thrift import TSerialization
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAcceleratedFactory

from reddit_edgecontext.thrift.ttypes import Device as TDevice
from reddit_edgecontext.thrift.ttypes import Geolocation as TGeolocation
from reddit_edgecontext.thrift.ttypes import Locale as TLocale
Expand All @@ -28,6 +25,8 @@
from reddit_edgecontext.thrift.ttypes import Request as TRequest
from reddit_edgecontext.thrift.ttypes import RequestId as TRequestId
from reddit_edgecontext.thrift.ttypes import Session as TSession
from thrift import TSerialization
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAcceleratedFactory


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -537,9 +536,7 @@ def request_id(self) -> RequestId:
@cached_property
def locale(self) -> Locale:
""":py:class:`~reddit_edgecontext.Locale` object for the current context."""
return Locale(
locale_code=self._t_request.locale.locale_code,
)
return Locale(locale_code=self._t_request.locale.locale_code)

@cached_property
def _t_request(self) -> TRequest:
Expand Down
187 changes: 24 additions & 163 deletions lib/py/reddit_edgecontext/thrift/ttypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions lib/py/tests/edge_context_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import unittest

from baseplate.testing.lib.secrets import FakeSecretsStore

from reddit_edgecontext import EdgeContextFactory
from reddit_edgecontext import InvalidAuthenticationToken
from reddit_edgecontext import NoAuthenticationError
Expand Down Expand Up @@ -135,10 +134,7 @@ def test_validated_service_authentication_token(self):
payload = {
"sub": "service/test-service",
"exp": 1574458470,
"obo": {
"aid": "t2_deadbeef",
"roles": ["admin"],
},
"obo": {"aid": "t2_deadbeef", "roles": ["admin"]},
"sea": True,
}

Expand Down Expand Up @@ -208,9 +204,7 @@ def test_create_empty_context(self):
self.assertEqual(
request_context._header,
# loid
b"\x0c\x00" # STRUCT
b"\x01" # tag number
b"\x00" # END STRUCT
b"\x0c\x00" b"\x01" b"\x00" # STRUCT # tag number # END STRUCT
# session
b"\x0c\x00\x02\x00"
# device
Expand Down

0 comments on commit a8f6641

Please sign in to comment.