Skip to content
Open
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
17 changes: 3 additions & 14 deletions src/cli/broker.toit
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,17 @@ class Broker:
--part-id=id
cli_.cache.get-file-path key: | store/FileStore |
broker-connection_.pod-registry-upload-pod-part contents --part-id=id
--scope=server-config.scope
store.save contents
key := cache-key-pod-manifest
--broker-config=server-config
--pod-id=pod.id
cli_.cache.get-file-path key: | store/FileStore |
encoded := ubjson.encode manifest
broker-connection_.pod-registry-upload-pod-manifest encoded --pod-id=pod.id
--scope=server-config.scope
store.save encoded

description-ids := broker-connection_.pod-registry-descriptions
--fleet-id=fleet-id
--scope=server-config.scope
--names=[pod.name]
--create-if-absent

Expand Down Expand Up @@ -219,7 +216,6 @@ class Broker:
cli_.cache.get cache-key: | store/FileStore |
trivial := build-trivial-patch patch.bits_
broker-connection_.upload-firmware trivial
--scope=server-config.scope
--firmware-id=trivial-id
store.save-via-writer: | writer/io.Writer |
trivial.do: writer.write it
Expand All @@ -235,7 +231,6 @@ class Broker:
trivial-old := cli_.cache.get cache-key: | store/FileStore |
downloaded := null
catch: downloaded = broker-connection_.download-firmware
--scope=server-config.scope
--id=old-id
if not downloaded:
cli_.ui.emit --warning "Failed to download old firmware for patch $old-id -> $trivial-id."
Expand Down Expand Up @@ -273,7 +268,6 @@ class Broker:
to64 := base64.encode patch.to_ --url-mode
cli_.ui.emit --info "Uploading patch $from64 -> $to64 ($diff-size)."
broker-connection_.upload-firmware diff
--scope=server-config.scope
--firmware-id=diff-id
store.save-via-writer: | writer/io.Writer |
diff.do: writer.write it
Expand Down Expand Up @@ -306,7 +300,6 @@ class Broker:
encoded-manifest := cli_.cache.get manifest-key: | store/FileStore |
bytes := broker-connection_.pod-registry-download-pod-manifest
--pod-id=pod-id
--scope=server-config.scope
store.save bytes
manifest := ubjson.decode encoded-manifest
return Pod.from-manifest
Expand All @@ -319,7 +312,6 @@ class Broker:
cli_.cache.get key: | store/FileStore |
bytes := broker-connection_.pod-registry-download-pod-part
part-id
--scope=server-config.scope
store.save bytes

list-pods --names/List -> Map:
Expand All @@ -329,7 +321,6 @@ class Broker:
else:
descriptions = broker-connection_.pod-registry-descriptions
--fleet-id=fleet-id
--scope=server-config.scope
--names=names
--no-create-if-absent
result := {:}
Expand All @@ -341,7 +332,6 @@ class Broker:
delete --description-names/List:
descriptions := broker-connection_.pod-registry-descriptions
--fleet-id=fleet-id
--scope=server-config.scope
--names=description-names
--no-create-if-absent
unknown-pod-descriptions := []
Expand Down Expand Up @@ -410,7 +400,6 @@ class Broker:

descriptions := broker-connection_.pod-registry-descriptions
--fleet-id=fleet-id
--scope=server-config.scope
--names=names.to-list
--no-create-if-absent

Expand Down Expand Up @@ -754,14 +743,14 @@ class Broker:
store.with-tmp-directory: | tmp-dir |
// TODO(florian): do we want to rely on the cache, or should we
// do a check to see if the files are really uploaded?
device-scope := Scope.from-organization-id device.organization-id
// Note: every device in this fleet uses the broker's scope.
// device.organization-id is guaranteed to equal the broker's
// configured scope, so we don't need to pass it explicitly.
broker-connection_.upload-image program.image32
--app-id=id
--scope=device-scope
--word-size=32
file.write-contents program.image32 --path="$tmp-dir/image32.bin"
broker-connection_.upload-image program.image64
--scope=device-scope
--app-id=id
--word-size=64
file.write-contents program.image64 --path="$tmp-dir/image64.bin"
Expand Down
23 changes: 9 additions & 14 deletions src/cli/brokers/broker.toit
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,30 @@ interface BrokerCli implements Authenticatable:
update-goals --device-ids/List --goals/List -> none

/**
Uploads an application image with the given $app-id so that a device in
$scope can fetch it.
Uploads an application image with the given $app-id.

Each $BrokerCli instance is bound to a single $Scope (through its
server config); the image is uploaded for devices in that scope.

There may be multiple images for the same $app-id, that differ in the $word-size.
Generally $word-size is either 32 or 64.
*/
upload-image
--scope/Scope
--app-id/Uuid
--word-size/int
contents/ByteArray -> none

/**
Uploads a firmware with the given $firmware-id so that a device in
$scope can fetch it.
Uploads a firmware with the given $firmware-id.

The $chunks are a list of byte arrays.
*/
upload-firmware --scope/Scope --firmware-id/string chunks/List -> none
upload-firmware --firmware-id/string chunks/List -> none

/**
Downloads a firmware chunk inside the given $scope.
Downloads a firmware chunk.
*/
download-firmware --scope/Scope --id/string -> ByteArray
download-firmware --id/string -> ByteArray

/**
Informs the broker that a device with the given $device-id has been provisioned.
Expand Down Expand Up @@ -155,7 +155,6 @@ interface BrokerCli implements Authenticatable:
*/
pod-registry-description-upsert -> int
--fleet-id/Uuid
--scope/Scope
--name/string
--description/string?

Expand Down Expand Up @@ -218,7 +217,6 @@ interface BrokerCli implements Authenticatable:
*/
pod-registry-descriptions -> List
--fleet-id/Uuid
--scope/Scope
--names/List
--create-if-absent/bool

Expand Down Expand Up @@ -250,14 +248,13 @@ interface BrokerCli implements Authenticatable:
Uploads a pod part to the registry.
*/
pod-registry-upload-pod-part -> none
--scope/Scope
--part-id/string
contents/ByteArray

/**
Downloads a pod part from the registry.
*/
pod-registry-download-pod-part part-id/string --scope/Scope -> ByteArray
pod-registry-download-pod-part part-id/string -> ByteArray

/**
Saves the manifest of a pod.
Expand All @@ -266,15 +263,13 @@ interface BrokerCli implements Authenticatable:
a pod from its parts.
*/
pod-registry-upload-pod-manifest -> none
--scope/Scope
--pod-id/Uuid
contents/ByteArray

/**
Downloads the manifest of a pod.
*/
pod-registry-download-pod-manifest -> ByteArray
--scope/Scope
--pod-id/Uuid

with-broker server-config/ServerConfig --cli/Cli [block]:
Expand Down
51 changes: 23 additions & 28 deletions src/cli/brokers/http/base.toit
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,28 @@ class BrokerCliHttp implements BrokerCli:
return result

upload-image -> none
--scope/Scope
--app-id/Uuid
--word-size/int
contents/ByteArray:
organization-id := scope.as-uuid
scope := server-config_.scope.to-json
send-request_ COMMAND-UPLOAD_ {
"path": "/toit-artemis-assets/$organization-id/images/$app-id.$word-size",
"path": "/toit-artemis-assets/$scope/images/$app-id.$word-size",
"content": contents,
}

upload-firmware --scope/Scope --firmware-id/string chunks/List -> none:
organization-id := scope.as-uuid
upload-firmware --firmware-id/string chunks/List -> none:
scope := server-config_.scope.to-json
firmware := #[]
chunks.do: firmware += it
send-request_ COMMAND-UPLOAD_ {
"path": "/toit-artemis-assets/$organization-id/firmware/$firmware-id",
"path": "/toit-artemis-assets/$scope/firmware/$firmware-id",
"content": firmware,
}

download-firmware --scope/Scope --id/string -> ByteArray:
organization-id := scope.as-uuid
download-firmware --id/string -> ByteArray:
scope := server-config_.scope.to-json
return send-request_ COMMAND-DOWNLOAD_ {
"path": "/toit-artemis-assets/$organization-id/firmware/$id",
"path": "/toit-artemis-assets/$scope/firmware/$id",
}

notify-created --device-id/Uuid --state/Map -> none:
Expand Down Expand Up @@ -245,13 +244,12 @@ class BrokerCliHttp implements BrokerCli:
/** See $BrokerCli.pod-registry-description-upsert. */
pod-registry-description-upsert -> int
--fleet-id/Uuid
--scope/Scope
--name/string
--description/string?:
organization-id := scope.as-uuid
scope := server-config_.scope.to-json
return send-request_ COMMAND-POD-REGISTRY-DESCRIPTION-UPSERT_ {
"_fleet_id": "$fleet-id",
"_organization_id": "$organization-id",
"_organization_id": scope,
"_name": name,
"_description": description,
}
Expand Down Expand Up @@ -315,16 +313,15 @@ class BrokerCliHttp implements BrokerCli:
}
return response.map: PodRegistryDescription.from-map it

/** See $(BrokerCli.pod-registry-descriptions --fleet-id --scope --names --create-if-absent). */
/** See $(BrokerCli.pod-registry-descriptions --fleet-id --names --create-if-absent). */
pod-registry-descriptions -> List
--fleet-id/Uuid
--scope/Scope
--names/List
--create-if-absent/bool:
organization-id := scope.as-uuid
scope := server-config_.scope.to-json
response := send-request_ COMMAND-POD-REGISTRY-DESCRIPTIONS-BY-NAMES_ {
"_fleet_id": "$fleet-id",
"_organization_id": "$organization-id",
"_organization_id": scope,
"_names": names,
"_create_if_absent": create-if-absent,
}
Expand Down Expand Up @@ -371,36 +368,34 @@ class BrokerCliHttp implements BrokerCli:

/** See $BrokerCli.pod-registry-upload-pod-part. */
pod-registry-upload-pod-part -> none
--scope/Scope
--part-id/string
contents/ByteArray:
organization-id := scope.as-uuid
scope := server-config_.scope.to-json
send-request_ COMMAND-UPLOAD_ {
"path": "/toit-artemis-pods/$organization-id/part/$part-id",
"path": "/toit-artemis-pods/$scope/part/$part-id",
"content": contents,
}

/** See $BrokerCli.pod-registry-download-pod-part. */
pod-registry-download-pod-part part-id/string --scope/Scope -> ByteArray:
organization-id := scope.as-uuid
pod-registry-download-pod-part part-id/string -> ByteArray:
scope := server-config_.scope.to-json
return send-request_ COMMAND-DOWNLOAD-PRIVATE_ {
"path": "/toit-artemis-pods/$organization-id/part/$part-id",
"path": "/toit-artemis-pods/$scope/part/$part-id",
}

/** See $BrokerCli.pod-registry-upload-pod-manifest. */
pod-registry-upload-pod-manifest -> none
--scope/Scope
--pod-id/Uuid
contents/ByteArray:
organization-id := scope.as-uuid
scope := server-config_.scope.to-json
send-request_ COMMAND-UPLOAD_ {
"path": "/toit-artemis-pods/$organization-id/manifest/$pod-id",
"path": "/toit-artemis-pods/$scope/manifest/$pod-id",
"content": contents,
}

/** See $BrokerCli.pod-registry-download-pod-manifest. */
pod-registry-download-pod-manifest --scope/Scope --pod-id/Uuid -> ByteArray:
organization-id := scope.as-uuid
pod-registry-download-pod-manifest --pod-id/Uuid -> ByteArray:
scope := server-config_.scope.to-json
return send-request_ COMMAND-DOWNLOAD-PRIVATE_ {
"path": "/toit-artemis-pods/$organization-id/manifest/$pod-id",
"path": "/toit-artemis-pods/$scope/manifest/$pod-id",
}
1 change: 1 addition & 0 deletions src/cli/brokers/supabase/supabase.toit
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ create-broker-cli-supabase-http server-config/ServerConfigSupabase --cli/Cli ->
--use-tls=server-config.use-tls
--root-certificate-ders=server-config.root-certificate-der ? [server-config.root-certificate-der] : null
--poll-interval=server-config.poll-interval
--scope=server-config.scope

return BrokerCliSupabase --id=id supabase-client http-config

Expand Down
6 changes: 3 additions & 3 deletions src/cli/cache.toit
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ cache-key-application-image id/Uuid --broker-config/ServerConfig -> string:
cache-key-pod-parts -> string
--broker-config/ServerConfig
--part-id/string:
return "$broker-config.cache-key/$broker-config.scope.as-uuid/pod/parts/$part-id"
return "$broker-config.cache-key/$broker-config.scope.to-json/pod/parts/$part-id"

cache-key-pod-manifest -> string
--broker-config/ServerConfig
--pod-id/Uuid:
return "$broker-config.cache-key/$broker-config.scope.as-uuid/pod/manifest/$pod-id"
return "$broker-config.cache-key/$broker-config.scope.to-json/pod/manifest/$pod-id"

cache-key-patch -> string
--broker-config/ServerConfig
--patch-id/string:
return "$broker-config.cache-key/$broker-config.scope.as-uuid/patches/$patch-id"
return "$broker-config.cache-key/$broker-config.scope.to-json/patches/$patch-id"

CACHE-ARTIFACT-KIND-ENVELOPE ::= "envelope"
CACHE-ARTIFACT-KIND-PARTITION-TABLE ::= "partitions"
Expand Down
12 changes: 6 additions & 6 deletions src/cli/fleet.toit
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class FleetFile:
(which is still org-id concrete).
*/
organization-id -> Uuid:
return broker-scope.as-uuid
return Uuid.parse broker-scope.to-json

static parse path/string --default-broker-config/ServerConfig --cli/Cli -> FleetFile:
ui := cli.ui
Expand Down Expand Up @@ -198,12 +198,12 @@ class FleetFile:
if is-new-format:
if not broker-server.scope:
ui.abort "Fleet file '$path' is missing 'scope' on broker server '$broker-name'."
organization-id = broker-server.scope.as-uuid
organization-id = Uuid.parse broker-server.scope.to-json
else:
// Legacy format: the top-level organization-id was the same for
// every server. Pin it onto every entry so the new in-memory
// shape is consistent.
legacy-scope := Scope.from-organization-id organization-id
legacy-scope := Scope "$organization-id"
servers.map --in-place: | _ server-config/ServerConfig |
server-config.with --scope=legacy-scope

Expand All @@ -222,7 +222,7 @@ class FleetFile:
broker-name = default-broker-config.name
// Very-legacy fleet file with no broker/servers entry. Attach the
// legacy top-level organization-id to the default broker config.
legacy-scope := Scope.from-organization-id organization-id
legacy-scope := Scope "$organization-id"
servers = {
default-broker-config.name: default-broker-config.with --scope=legacy-scope,
}
Expand Down Expand Up @@ -437,7 +437,7 @@ class Fleet:
(which is still org-id concrete).
*/
organization-id -> Uuid:
return broker-scope.as-uuid
return Uuid.parse broker-scope.to-json

static load-fleet-file -> FleetFile
fleet-root-or-ref/string
Expand Down Expand Up @@ -640,7 +640,7 @@ class FleetWithDevices extends Fleet:
recovery-urls := recovery-url-prefixes.map: | prefix |
"$prefix/recover-$(fleet-id).json"
scoped-broker-config := broker-config.with
--scope=(Scope.from-organization-id organization-id)
--scope=(Scope "$organization-id")
fleet-file := FleetFile
--path="$fleet-root/$FLEET-FILE_"
--id=fleet-id
Expand Down
Loading
Loading