appengine

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package appengine is the AppEngine API (docs/DESIGN.md §3.7, ROADMAP §8.2): the operator/application surface for device status, interface data queries, server-owned publishing, groups, and the live event socket. It is wire-shaped to upstream astarte_appengine_api so astartectl and applications work unmodified, reading through the store and writing server-owned values through the engine.

Index

Constants

View Source
const DefaultDeviceLimit = 100

DefaultDeviceLimit is the device-list page size when the caller gives none.

Variables

View Source
var ErrValidation = errors.New("appengine: validation failed")

ErrValidation wraps a well-formed request that violates a rule (maps to 422).

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is the /appengine/v1 HTTP surface (docs/ROADMAP.md §8.2 file 7.8), guarded by a realm JWT carrying a_aea.

func NewAPI

func NewAPI(svc *Service, mw *auth.Middleware) *API

NewAPI wires the AppEngine service to its HTTP surface.

func (*API) Mount

func (a *API) Mount(mux *http.ServeMux)

Mount registers the routes on mux (paths wire-frozen to upstream astarte_appengine_api).

type DevicePatch

type DevicePatch struct {
	Aliases              map[string]*string
	Attributes           map[string]*string
	CredentialsInhibited *bool
}

DevicePatch carries the JSON-merge-style PATCH fields (upstream DevicePatch): a nil pointer leaves a field unchanged, a present map patches aliases/attributes (a nil map value removes that key).

type DeviceStatus

type DeviceStatus struct {
	ID                   string                        `json:"id"`
	Connected            bool                          `json:"connected"`
	Introspection        map[string]introspectionEntry `json:"introspection"`
	Aliases              map[string]string             `json:"aliases"`
	Attributes           map[string]string             `json:"attributes"`
	Groups               []string                      `json:"groups"`
	CredentialsInhibited bool                          `json:"credentials_inhibited"`
	TotalReceivedMsgs    int64                         `json:"total_received_msgs"`
	TotalReceivedBytes   int64                         `json:"total_received_bytes"`
	FirstRegistration    *time.Time                    `json:"first_registration"`
	FirstCredentialsReq  *time.Time                    `json:"first_credentials_request"`
	LastConnection       *time.Time                    `json:"last_connection"`
	LastDisconnection    *time.Time                    `json:"last_disconnection"`
	LastSeenIP           string                        `json:"last_seen_ip,omitempty"`
	PreviousInterfaces   map[string]introspectionEntry `json:"previous_interfaces,omitempty"`
}

DeviceStatus is the AppEngine device status body (upstream DeviceStatusView): a JSON-friendly projection of a devices row.

type QueryOpts

type QueryOpts struct {
	Since        *time.Time
	SinceAfter   *time.Time
	To           *time.Time
	Limit        int
	Descending   bool
	DownsampleTo *time.Duration
}

QueryOpts are the datastream query parameters (upstream since/since_after/to/limit/downsample_to). The zero value reads the whole series ascending.

type Sample

type Sample struct {
	Value     any       `json:"value"`
	Timestamp time.Time `json:"timestamp"`
}

Sample is one datastream point rendered for the wire.

type ServerData

type ServerData interface {
	PublishServerValue(ctx context.Context, realm string, id deviceid.ID, iface, path string, value json.RawMessage, ts *time.Time) error
	UnsetServerProperty(ctx context.Context, realm string, id deviceid.ID, iface, path string) error
}

ServerData is the engine port for server-owned writes (docs/ROADMAP.md §8.2 file 7.7). *engine.Engine satisfies it; tests substitute a fake.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implements the AppEngine business logic over the store and engine.

func NewService

func NewService(st *store.Store, sd ServerData, log *slog.Logger) *Service

NewService builds the service. sd may be nil (read-only deployments); log defaults to slog.Default().

func (*Service) AddGroupDevice

func (s *Service) AddGroupDevice(ctx context.Context, realm, name, deviceID string) error

AddGroupDevice adds a device to a group.

func (*Service) CreateGroup

func (s *Service) CreateGroup(ctx context.Context, realm, name string, devices []string) error

CreateGroup creates a group with its initial device membership (upstream POST /groups requires a non-empty device list).

func (*Service) GetData

func (s *Service) GetData(ctx context.Context, realm, deviceID, ifaceName, path string, opts QueryOpts) (any, error)

GetData reads an interface endpoint (upstream GET .../interfaces/{iface} [/{path}]), dispatching on the interface type: a datastream series (with the query options) or a properties snapshot.

func (*Service) GetDevice

func (s *Service) GetDevice(ctx context.Context, realm, deviceID string) (*DeviceStatus, error)

GetDevice returns one device's status (upstream GET /devices/{id}).

func (*Service) GetDeviceByAlias

func (s *Service) GetDeviceByAlias(ctx context.Context, realm, alias string) (*DeviceStatus, error)

GetDeviceByAlias returns the status of the device owning an alias (upstream GET /devices-by-alias/{alias}).

func (*Service) ListDevices

func (s *Service) ListDevices(ctx context.Context, realm string, after string, limit int) ([]string, string, error)

ListDevices returns one page of device IDs (upstream GET /devices). after is the cursor (exclusive); limit <= 0 selects DefaultDeviceLimit. The second result is the next-page cursor, or "" at the end.

func (*Service) ListGroupDevices

func (s *Service) ListGroupDevices(ctx context.Context, realm, name string) ([]string, error)

ListGroupDevices returns the device IDs in a group.

func (*Service) ListGroups

func (s *Service) ListGroups(ctx context.Context, realm string) ([]string, error)

ListGroups returns the realm's group names.

func (*Service) PatchDevice

func (s *Service) PatchDevice(ctx context.Context, realm, deviceID string, p DevicePatch) (*DeviceStatus, error)

PatchDevice applies a device patch (upstream PATCH /devices/{id}).

func (*Service) PublishData

func (s *Service) PublishData(ctx context.Context, realm, deviceID, ifaceName, path string, value json.RawMessage, ts *time.Time) error

PublishData writes a server-owned value (upstream PUT/POST .../interfaces/{iface}/{path}) through the engine. value is the unwrapped "data" JSON; ts is the optional explicit timestamp.

func (*Service) RemoveGroupDevice

func (s *Service) RemoveGroupDevice(ctx context.Context, realm, name, deviceID string) error

RemoveGroupDevice removes a device from a group.

func (*Service) UnsetProperty

func (s *Service) UnsetProperty(ctx context.Context, realm, deviceID, ifaceName, path string) error

UnsetProperty unsets a server-owned property (upstream DELETE .../interfaces/{iface}/{path}).

Directories

Path Synopsis
Package stream is the AppEngine live event socket (docs/DESIGN.md §3.7, §1.1 deviation; ROADMAP §8.2 file 7.9): a WebSocket (with an SSE fallback) at /astrate/v1/{realm}/socket fed by the engine's in-process fan-out bus.
Package stream is the AppEngine live event socket (docs/DESIGN.md §3.7, §1.1 deviation; ROADMAP §8.2 file 7.9): a WebSocket (with an SSE fallback) at /astrate/v1/{realm}/socket fed by the engine's in-process fan-out bus.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL