* Get rid of installation token (for OSS installations) This is done by being required to supply the grafana API URL as an environment variable on the backend. Additionally, optionally an OnCall API URL environment variable can be passed in to the frontend (this basically allows completely skipping the need to configure anything). - deduplicated a lot of the sync logic on the frontend + made error message more useful and consistent - Split PluginConfigPage component into several subcomponents (making it easier to test each individual component) - Moved RootWithLoader (from plugin/GrafanaPluginRootPage) into its own subcomponent (making it easier to test) - Added tests for pre-existing components that were touched: - PluginConfigPage component (and its new subcomponents) - state/plugin and state/rootBaseStore functions - apps.grafana_plugin django app Helm changes: - add GRAFANA_API_URL to oncall.env - some yaml autoformatting changes - remove reference to python manage.py issue_invite_for_the_frontend --override Co-authored-by: Joey Orlando <joseph.t.orlando@gmail.com>
29 lines
1 KiB
Python
29 lines
1 KiB
Python
import json
|
|
import logging
|
|
|
|
from django.views import View
|
|
from rest_framework import permissions
|
|
from rest_framework.authentication import get_authorization_header
|
|
from rest_framework.request import Request
|
|
|
|
from apps.auth_token.exceptions import InvalidToken
|
|
from apps.grafana_plugin.helpers.gcom import check_token
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class PluginTokenVerified(permissions.BasePermission):
|
|
|
|
# The grafana plugin can either use a token from gcom or one generated internally by oncall
|
|
# Tokens from gcom will be prefixed with gcom: otherwise they will be treated as local
|
|
def has_permission(self, request: Request, view: View) -> bool:
|
|
token_string = get_authorization_header(request).decode()
|
|
context = json.loads(request.headers.get("X-Instance-Context"))
|
|
try:
|
|
auth_token = check_token(token_string, context)
|
|
if auth_token:
|
|
return True
|
|
except InvalidToken:
|
|
logger.warning(f"Invalid token used: {context}")
|
|
|
|
return False
|