Skip to content

Commit

Permalink
Merge branch 'main' into tyler/multiclass-detector-support
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-romero authored Oct 7, 2024
2 parents 3bb271c + 18578a3 commit 1fa2abd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def _verify_connectivity(self) -> None:
try:
# a simple query to confirm that the endpoint & API token are working
self.whoami()
if self._user_is_privileged():
logger.warning(
"WARNING: The current user has elevated permissions. Please verify such permissions are necessary"
" for your current operation"
)
except UnauthorizedException as e:
msg = (
f"Invalid API token '{self.api_token_prefix}...' connecting to endpoint "
Expand Down Expand Up @@ -202,6 +207,14 @@ def whoami(self) -> str:
obj = self.user_api.who_am_i()
return obj["username"]

def _user_is_privileged(self) -> bool:
"""
Return a boolean indicating whether the user is privileged.
Privleged users have elevated permissions, so care should be taken when using a privileged account.
"""
obj = self.user_api.who_am_i()
return obj["is_superuser"] or obj["is_staff"]

def get_detector(self, id: Union[str, Detector]) -> Detector: # pylint: disable=redefined-builtin
"""
Get a detector by id
Expand Down
9 changes: 9 additions & 0 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
from model import Detector, ImageQuery


def pytest_configure(config):
# Run environment check before tests
gl = Groundlight()
if gl._user_is_privileged():
raise Exception(
"ERROR: You are running tests with a privileged user. Please run tests with a non-privileged user."
)


@pytest.fixture(name="gl")
def fixture_gl() -> Groundlight:
"""Creates a Groundlight client object for testing."""
Expand Down

0 comments on commit 1fa2abd

Please sign in to comment.