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
25 changes: 5 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- "*/*"

env:
SUPABASE_VERSION: 1.187.10
SUPABASE_VERSION: 2.75.0
EXCLUDED_SUPABASE_SERVICES: imgproxy,inbucket,pgadmin-schema-diff,migra,studio,deno-relay
# Qemu release page: https://github.com/espressif/qemu/releases/tag/esp-develop-8.2.0-20240122
QEMU_LINUX_URL: https://github.com/espressif/qemu/releases/download/esp-develop-8.2.0-20240122/qemu-xtensa-softmmu-esp_develop_8.2.0_20240122-x86_64-linux-gnu.tar.xz
Expand Down Expand Up @@ -123,22 +123,9 @@ jobs:
supabase start -x "$EXCLUDED_SUPABASE_SERVICES"
supabase status

# Sample output of supabase status:
# supabase local development setup is running.
#
# API URL: http://localhost:54321
# DB URL: postgresql://postgres:postgres@localhost:54322/postgres
# Studio URL: http://localhost:54323
# Inbucket URL: http://localhost:54324
# JWT secret: super-secret-jwt-token-with-at-least-32-characters-long
# anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs
# service_role key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSJ9.vI9obAHOGyVVKa3pD--kJlyxp-Z2zV9UUMAhKpNLAcU

API_URL_LINE=$(supabase status | grep "API URL:")
API_URL=${API_URL_LINE#*API URL: }
source <(supabase status --output=env)

API_HOST=${API_URL#*http://}
ANON_KEY_LINE=$(supabase status | grep "anon key:")
ANON_KEY=${ANON_KEY_LINE#*anon key: }
echo "SUPABASE_TOITWARE_API_HOST=$API_HOST" >> $GITHUB_ENV
echo "SUPABASE_TOITWARE_ANON_KEY=$ANON_KEY" >> $GITHUB_ENV

Expand All @@ -150,11 +137,9 @@ jobs:
supabase start -x "$EXCLUDED_SUPABASE_SERVICES"
supabase status

API_URL_LINE=$(supabase status | grep "API URL:")
API_URL=${API_URL_LINE#*API URL: }
source <(supabase status --output=env)

API_HOST=${API_URL#*http://}
ANON_KEY_LINE=$(supabase status | grep "anon key:")
ANON_KEY=${ANON_KEY_LINE#*anon key: }
echo "SUPABASE_BROKER_API_HOST=$API_HOST" >> $GITHUB_ENV
echo "SUPABASE_BROKER_ANON_KEY=$ANON_KEY" >> $GITHUB_ENV

Expand Down
3 changes: 1 addition & 2 deletions public/supabase_broker/supabase/functions/b/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (C) 2023 Toitware ApS. All rights reserved.

import { createClient } from "@supabase/supabase-js";
import { serve } from "std/server";

const STATUS_IM_A_TEAPOT = 418;

Expand Down Expand Up @@ -275,7 +274,7 @@ async function handleRequest(req: Request) {
}
}

serve(async (req: Request) => {
Deno.serve(async (req: Request) => {
try {
const result = await handleRequest(req);
if (result instanceof Response) {
Expand Down
3 changes: 1 addition & 2 deletions supabase_artemis/supabase/functions/b/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (C) 2023 Toitware ApS. All rights reserved.

import { createClient } from "@supabase/supabase-js";
import { serve } from "std/server";

const STATUS_IM_A_TEAPOT = 418;

Expand Down Expand Up @@ -275,7 +274,7 @@ async function handleRequest(req: Request) {
}
}

serve(async (req: Request) => {
Deno.serve(async (req: Request) => {
try {
const result = await handleRequest(req);
if (result instanceof Response) {
Expand Down
18 changes: 14 additions & 4 deletions tests/supabase-artemis-broker-policies-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ main args:
expect-equals "foo".to-byte-array
client2.storage.download --path="$path-org1/foo.txt"

expect-throws --contains="Not found":
client3.storage.download --path="$path-org1/foo.txt"
if bucket == ASSETS-BUCKET:
// Assets are public.
expect-equals "foo".to-byte-array
client3.storage.download --path="$path-org1/foo.txt"
else:
expect-throws --contains="Not found":
client3.storage.download --path="$path-org1/foo.txt"

// Client3 has access to its own org bucket/path.
path-org3 := "$bucket/$organization-id3"
Expand All @@ -125,8 +130,13 @@ main args:
expect-equals "bar".to-byte-array
client3.storage.download --path="$path-org3/bar.txt"

expect-throws --contains="Not found":
client1.storage.download --path="$path-org3/bar.txt"
if bucket == ASSETS-BUCKET:
// Assets are public.
expect-equals "bar".to-byte-array
client1.storage.download --path="$path-org3/bar.txt"
else:
expect-throws --contains="Not found":
client1.storage.download --path="$path-org3/bar.txt"

// Remember: device_id3 is in the same org as client1 and client2 (organization_id).
// client3 is in a different org.
Expand Down
30 changes: 9 additions & 21 deletions tests/supabase-local-server.toit
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ get-supabase-config --sub-directory/string -> ServerConfigSupabase:
anon-key/string? := null
api-url/string? := null

out := get-status_ sub-directory
lines := out.split "\n"
lines.map --in-place: it.trim
lines.do:
if it.starts-with "anon key:":
anon-key = it[(it.index-of ":") + 1..].trim
else if it.starts-with "API URL:":
api-url = it[(it.index-of ":") + 1..].trim

if not anon-key or not api-url:
throw "Could not get supabase info"
status := get-status_ sub-directory
api-url = status["API_URL"]
anon-key = status["ANON_KEY"]

host := api-url.trim --left "http://"
print-on-stderr_ "HOST: $host ANON_KEY: $anon-key"
Expand All @@ -39,17 +31,13 @@ get-supabase-config --sub-directory/string -> ServerConfigSupabase:
return ServerConfigSupabase name --host=host --anon=anon-key

get-supabase-service-key --sub-directory/string -> string:
out := get-status_ sub-directory
lines := out.split "\n"
lines.map --in-place: it.trim
lines.do:
if it.starts-with "service_role key:":
return it[(it.index-of ":") + 1..].trim
unreachable

get-status_ sub-directory/string -> string:
status := get-status_ sub-directory
return status["SERVICE_ROLE_KEY"]

get-status_ sub-directory/string -> Map:
supabase-exe := os.env.get "SUPABASE_EXE" or "supabase"
return pipe.backticks supabase-exe "--workdir" "$sub-directory" "status"
out := pipe.backticks supabase-exe "--output=json" "--workdir" "$sub-directory" "status"
return json.parse out

// Prints the arguments needed for adding the local supabase service to the configuration.
main args:
Expand Down
Loading