Skip to content

Commit

Permalink
set default grafana_url if GRAFANA_API_URL set
Browse files Browse the repository at this point in the history
override GrafanaAPIClient url if GRAFANA_API_URL set

override GrafanaAPIClient url if GRAFANA_API_URL set

override GrafanaAPIClient url if GRAFANA_API_URL set

set default grafana_url if GRAFANA_API_URL set
  • Loading branch information
juriku authored and juri committed Aug 28, 2024
1 parent c475a15 commit 792240a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions engine/apps/grafana_plugin/helpers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import time
import typing
from urllib.parse import urljoin
from urllib.parse import urljoin, urlparse

import requests
from django.conf import settings
Expand Down Expand Up @@ -94,7 +94,10 @@ def __call__(self, *args, **kwargs) -> requests.Response:

class APIClient:
def __init__(self, api_url: str, api_token: str) -> None:
self.api_url = api_url
if settings.SELF_HOSTED_SETTINGS["GRAFANA_API_URL"] is not None:
self.api_url = settings.SELF_HOSTED_SETTINGS["GRAFANA_API_URL"]
if urlparse(self.api_url).path and not self.api_url.endswith('/'):
self.api_url += '/'
self.api_token = api_token

def api_head(self, endpoint: str, body: typing.Optional[typing.Dict] = None, **kwargs) -> APIClientResponse[_RT]:
Expand Down Expand Up @@ -243,9 +246,9 @@ def get_users_permissions(self) -> typing.Optional[UserPermissionsDict]:

return all_users_permissions

def is_rbac_enabled_for_organization(self) -> tuple[bool, bool]:
def is_rbac_enabled_for_organization(self) -> bool:
_, resp_status = self.api_head(self.USER_PERMISSION_ENDPOINT)
return resp_status["connected"], resp_status["status_code"] >= status.HTTP_500_INTERNAL_SERVER_ERROR
return resp_status["connected"]

def get_users(self, rbac_is_enabled_for_org: bool, **kwargs) -> GrafanaUsersWithPermissions:
users_response, _ = self.api_get("api/org/users", **kwargs)
Expand Down

0 comments on commit 792240a

Please sign in to comment.