From 86951c714370d9d5f181a06e51d2b5890c3479f2 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Tue, 20 Jan 2026 17:55:57 +0100 Subject: [PATCH 1/2] chore: add "Bearer" prefix to authorization headers [ENG-6467] [ENG-6467](https://stacklet.atlassian.net/browse/ENG-6467) ### what add the "Bearer" type prefix for authorization headers using the token ### why it's more standard ### testing tested against sandbox ### docs n/a --- stacklet/client/platform/commands/cube.py | 14 ++++++++++---- stacklet/client/platform/executor.py | 2 +- tests/test_graphql.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/stacklet/client/platform/commands/cube.py b/stacklet/client/platform/commands/cube.py index fbad67b..4baba60 100644 --- a/stacklet/client/platform/commands/cube.py +++ b/stacklet/client/platform/commands/cube.py @@ -63,12 +63,15 @@ def _run_query(ctx, query): context = StackletContext(ctx.obj["config"], ctx.obj["raw_config"]) token = get_token() - url = f"https://{context.config.cubejs}/cubejs-api/v1/load" + url = f"{context.config.cubejs}/cubejs-api/v1/load" data = {"query": query} response = requests.post( url=url, - headers={"Authorization": token, "Content-Type": "application/json"}, + headers={ + "Authorization": f"Bearer {token}", + "Content-Type": "application/json", + }, data=json.dumps(data), ) return response.json() @@ -78,11 +81,14 @@ def _get(ctx, path: str): context = StackletContext(ctx.obj["config"], ctx.obj["raw_config"]) token = get_token() - url = f"https://{context.config.cubejs}/cubejs-api/{path}" + url = f"{context.config.cubejs}/cubejs-api/{path}" response = requests.get( url=url, - headers={"Authorization": token, "Content-Type": "application/json"}, + headers={ + "Authorization": f"Bearer {token}", + "Content-Type": "application/json", + }, ) return response.json() diff --git a/stacklet/client/platform/executor.py b/stacklet/client/platform/executor.py index 2b1eb89..96bc38f 100644 --- a/stacklet/client/platform/executor.py +++ b/stacklet/client/platform/executor.py @@ -28,7 +28,7 @@ def __init__(self, context, token): self.session = requests.Session() self.session.headers.update( { - "Authorization": self.token, + "Authorization": f"Bearer {self.token}", } ) diff --git a/tests/test_graphql.py b/tests/test_graphql.py index 4674786..ef347f4 100644 --- a/tests/test_graphql.py +++ b/tests/test_graphql.py @@ -14,7 +14,7 @@ def test_executor_run(self): executor, adapter = get_executor_adapter() self.assertEqual(executor.token, "foo") self.assertEqual(executor.api, "mock://stacklet.acme.org/api") - self.assertEqual(executor.session.headers["authorization"], "foo") + self.assertEqual(executor.session.headers["authorization"], "Bearer foo") adapter.register_uri( "POST", From 93293f5e53b609d6df0f125e6eccc66c555fc22a Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Wed, 21 Jan 2026 10:11:26 +0100 Subject: [PATCH 2/2] extract common bits --- stacklet/client/platform/commands/cube.py | 30 ++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/stacklet/client/platform/commands/cube.py b/stacklet/client/platform/commands/cube.py index 4baba60..4e844cf 100644 --- a/stacklet/client/platform/commands/cube.py +++ b/stacklet/client/platform/commands/cube.py @@ -7,6 +7,7 @@ import textwrap from datetime import datetime from pprint import pformat +from typing import Any import click import requests @@ -39,7 +40,7 @@ def run(ctx, query): @cubejs.command() @click.pass_context def meta(ctx): - data = _get(ctx, "v1/meta") + data = _request(ctx, "GET", "v1/meta") cubes = {cube["name"]: cube for cube in data["cubes"]} for name in sorted(cubes): @@ -60,35 +61,20 @@ def resource_counts(ctx): def _run_query(ctx, query): - context = StackletContext(ctx.obj["config"], ctx.obj["raw_config"]) - token = get_token() - - url = f"{context.config.cubejs}/cubejs-api/v1/load" - - data = {"query": query} - response = requests.post( - url=url, - headers={ - "Authorization": f"Bearer {token}", - "Content-Type": "application/json", - }, - data=json.dumps(data), - ) - return response.json() + return _request(ctx, "POST", "v1/load", payload={"query": query}) -def _get(ctx, path: str): +def _request(ctx, method: str, path: str, payload: Any = None): context = StackletContext(ctx.obj["config"], ctx.obj["raw_config"]) token = get_token() - - url = f"{context.config.cubejs}/cubejs-api/{path}" - - response = requests.get( - url=url, + response = requests.request( + method, + url=f"{context.config.cubejs}/cubejs-api/{path}", headers={ "Authorization": f"Bearer {token}", "Content-Type": "application/json", }, + json=payload, ) return response.json()