Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions stacklet/client/platform/commands/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap
from datetime import datetime
from pprint import pformat
from typing import Any

import click
import requests
Expand Down Expand Up @@ -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):
Expand All @@ -60,29 +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"https://{context.config.cubejs}/cubejs-api/v1/load"

data = {"query": query}
response = requests.post(
url=url,
headers={"Authorization": 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"https://{context.config.cubejs}/cubejs-api/{path}"

response = requests.get(
url=url,
headers={"Authorization": token, "Content-Type": "application/json"},
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()

Expand Down
2 changes: 1 addition & 1 deletion stacklet/client/platform/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
}
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down