Skip to content

Commit deb35a2

Browse files
committed
WIP
1 parent 29092f1 commit deb35a2

4 files changed

Lines changed: 17 additions & 43 deletions

File tree

charts/grafana/templates/_helpers.tmpl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ env:
2121
- name: DRYCC_VALKEY_URL
2222
value: "redis://:$(DRYCC_VALKEY_PASSWORD)@drycc-valkey:16379/2"
2323
{{- end }}
24-
- name: DRYCC_SERVICE_KEY
25-
valueFrom:
26-
secretKeyRef:
27-
name: controller-creds
28-
key: service-key
2924
- name: "DRYCC_CONTROLLER_URL"
3025
value: http://drycc-controller-api
3126
- name: "DRYCC_QUICKWIT_URL"

charts/grafana/templates/grafana-statefulset.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ spec:
5151
GF_LIVE_HA_ENGINE_ADDRESS=$(echo "${DRYCC_VALKEY_JSON}" |jq -r '.address')
5252
GF_LIVE_HA_ENGINE_PASSWORD=$(echo "${DRYCC_VALKEY_JSON}" |jq -r '.password')
5353
export GF_LIVE_HA_ENGINE_ADDRESS GF_LIVE_HA_ENGINE_PASSWORD
54+
DRYCC_PASSPORT_TOKEN=$(curl -s -X POST \
55+
-H "Content-Type: application/x-www-form-urlencoded" \
56+
-d "grant_type=client_credentials&client_id=$DRYCC_PASSPORT_KEY&client_secret=$DRYCC_PASSPORT_SECRET" \
57+
$DRYCC_PASSPORT_URL/o/token/ | jq -r .access_token)
58+
export DRYCC_PASSPORT_TOKEN
5459
grafana server --config /usr/share/grafana/grafana.ini --homepath /opt/drycc/grafana &
5560
GRAFANA_PID=$!
5661
echo "Waiting for Grafana to come up..."
@@ -89,6 +94,11 @@ spec:
8994
GF_LIVE_HA_ENGINE_ADDRESS=$(echo "${DRYCC_VALKEY_JSON}" |jq -r '.address')
9095
GF_LIVE_HA_ENGINE_PASSWORD=$(echo "${DRYCC_VALKEY_JSON}" |jq -r '.password')
9196
export GF_LIVE_HA_ENGINE_ADDRESS GF_LIVE_HA_ENGINE_PASSWORD
97+
DRYCC_PASSPORT_TOKEN=$(curl -s -X POST \
98+
-H "Content-Type: application/x-www-form-urlencoded" \
99+
-d "grant_type=client_credentials&client_id=$DRYCC_PASSPORT_KEY&client_secret=$DRYCC_PASSPORT_SECRET" \
100+
$DRYCC_PASSPORT_URL/o/token/ | jq -r .access_token)
101+
export DRYCC_PASSPORT_TOKEN
92102
exec grafana server --config /usr/share/grafana/grafana.ini --homepath /opt/drycc/grafana
93103
{{- end }}
94104
{{- with index .Values "resources" }}

rootfs/usr/share/grafana/oauth2/hook/grafana.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -438,37 +438,6 @@ async def _upsert_alert_configuration(org_id: int, config: str):
438438

439439

440440
async def _get_or_create_drycc_token(username, token: dict):
441-
async def _check_or_create_drycc_token(drycc_token, token):
442-
async with httpx.AsyncClient() as client:
443-
created = False if drycc_token else True
444-
if drycc_token:
445-
headers = {"Authorization": f"Token {drycc_token}"}
446-
resp = await client.get(
447-
f"{DRYCC_CONTROLLER_URL}/v2/auth/whoami", headers=headers)
448-
if resp.status_code in [401, 403]:
449-
created = True
450-
if created:
451-
headers = {"Authorization": f"Bearer {token['access_token']}"}
452-
data = (await client.post(
453-
f"{DRYCC_CONTROLLER_URL}/v2/auth/token/?alias=grafana-datasource",
454-
headers=headers, json=token)).json()
455-
drycc_token = data["token"]
456-
return created, drycc_token
457-
458-
async with await AsyncConnection.connect(os.environ.get("GF_DATABASE_URL")) as conn:
459-
async with conn.cursor() as cursor:
460-
await cursor.execute(
461-
"SELECT o_auth_id_token FROM user_auth WHERE auth_module=%s AND auth_id=%s",
462-
("authproxy", username)
463-
)
464-
row = await cursor.fetchone()
465-
drycc_token = row[0] if row else None
466-
created, drycc_token = await _check_or_create_drycc_token(drycc_token, token)
467-
if created:
468-
async with conn.cursor() as cursor:
469-
await cursor.execute(
470-
"UPDATE user_auth SET o_auth_id_token=%s WHERE auth_module=%s AND auth_id=%s",
471-
(drycc_token, "authproxy", username)
472-
)
473-
await conn.commit()
474-
return created, drycc_token
441+
# Pass through the Passport access_token directly, no need for DRF token conversion
442+
drycc_token = token.get("access_token")
443+
return True, drycc_token

rootfs/usr/share/grafana/provisioning/datasources/drycc.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ datasources:
77
uid: application_logs
88
url: $DRYCC_QUICKWIT_URL
99
jsonData:
10-
httpHeaderName1: X-Drycc-Service-Key
10+
httpHeaderName1: Authorization
1111
index: logs-*
1212
logMessageField: log
1313
secureJsonData:
14-
httpHeaderValue1: $DRYCC_SERVICE_KEY
14+
httpHeaderValue1: Bearer $DRYCC_PASSPORT_TOKEN
1515
version: 1
1616
editable: false
1717

@@ -24,8 +24,8 @@ datasources:
2424
isDefault: true
2525
jsonData:
2626
httpMethod: POST
27-
httpHeaderName1: X-Drycc-Service-Key
27+
httpHeaderName1: Authorization
2828
secureJsonData:
29-
httpHeaderValue1: $DRYCC_SERVICE_KEY
29+
httpHeaderValue1: Bearer $DRYCC_PASSPORT_TOKEN
3030
version: 1
3131
editable: false

0 commit comments

Comments
 (0)