cli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

README

Magistrala CLI

The Magistrala CLI is backed by Atom GraphQL. It talks to the Atom GraphQL endpoint directly instead of the removed legacy HTTP management APIs.

Build

From the project root:

make cli

The binary is written to build/cli.

Configuration

The CLI reuses the Atom endpoint and token variables the rest of the deployment already sets, so a shell that has sourced docker/.env is configured for local GraphQL access:

Variable Purpose
ATOM_URL Atom base URL; the endpoint is this plus /graphql
ATOM_GRAPHQL_URL Full GraphQL endpoint, overrides ATOM_URL
ATOM_SERVICE_TOKEN Bearer token, falling back to ATOM_ADMIN_TOKEN
MG_CLI_ATOM_TIMEOUT CLI request timeout; defaults to 90s when unset

Without ATOM_URL the CLI defaults to http://localhost:8080/graphql. The CLI does not use the backend service ATOM_TIMEOUT; set MG_CLI_ATOM_TIMEOUT only when an interactive command needs a different request timeout.

Both settings also have flags, which win over the environment:

./build/cli --graphql-url http://localhost:8080/graphql --token "$ATOM_ADMIN_TOKEN" workspaces list

--graphql-url also configures the pkg/atom client behind devices, gateways and devicetypes: the Atom base URL is the endpoint minus its trailing /graphql.

These persistent flags apply to every listing command:

Flag Purpose
-l, --limit page size, 10 by default
-o, --offset records to skip
-n, --name name search, used by devices all get
-r, --raw raw output for easier parsing

Login

./build/cli login admin 12345678

Tenant-scoped credentials can pass either a tenant ID or alias:

./build/cli login user@example.com secret --tenant-id <workspace_id>
./build/cli login user@example.com secret --tenant-alias <workspace_alias>

Password

Authenticated users must provide their current password when changing it:

./build/cli --token "$ATOM_USER_TOKEN" password change <current_password> <new_password>

Workspaces

Workspaces map to Atom tenants.

./build/cli workspaces create "Demo Workspace" --alias demo
./build/cli workspaces list --limit 20 --offset 0
./build/cli workspaces get <workspace_id>

Channels

Channels map to Atom resources with kind="channel".

./build/cli channels create <workspace_id> "Measurements"
./build/cli channels create <workspace_id> "Alerts" --attributes '{"retention":"7d"}'
./build/cli channels list <workspace_id>
./build/cli channels list <workspace_id> --kind ""
./build/cli channels get <channel_id>

Groups

Atom exposes one mutation per group type, so --type selects between createObjectGroup and createPrincipalGroup. It defaults to object, and any other value is rejected before the request is sent.

./build/cli groups create <workspace_id> "Factory Floor" --description "Plant devices"
./build/cli groups create <workspace_id> "Operators" --type principal
./build/cli groups list <workspace_id>
./build/cli groups get <group_id>

Authorization

./build/cli authz check <subject_id> read --object-kind resource --object-id <resource_id>
./build/cli authz check <subject_id> publish --resource-id <channel_id>

Devices, gateways and device types

These commands go through pkg/atom's typed client. Devices are Atom entities of kind device.

./build/cli devices create <JSON_device> <workspace_id>
./build/cli devices all get <workspace_id>
./build/cli devices <device_id> get
./build/cli devices <device_id> update <JSON_string>
./build/cli devices <device_id> enable
./build/cli devices <device_id> disable
./build/cli devices <device_id> delete

A gateway is a device with attributes.is_gateway set; gateways manages the reachability relation between devices and gateways.

./build/cli gateways set <device_id> <gateway_id1,gateway_id2,...>
./build/cli gateways <gateway_id> devices <workspace_id>

In raw mode, successful mutating commands that otherwise print ok return a JSON object:

{"status":"ok"}
./build/cli devicetypes create <JSON_device_type> <workspace_id>
./build/cli devicetypes all get <workspace_id>
./build/cli devicetypes <device_type_id> update <JSON_string>
./build/cli devicetypes <device_type_id> versions
./build/cli devicetypes <device_type_id> create-version <JSON_version>
./build/cli devicetypes <device_type_id> active-version
./build/cli devicetypes <device_type_id> bind <device_id> [version_id]

Health

health is served by the per-service HTTP APIs rather than by Atom. It covers the FluxMQ HTTP adapter and reads MG_HTTP_ADAPTER_URL, defaulting to the local Compose nginx route at http://localhost/http.

./build/cli health fluxmq

All management commands except login and health require a bearer token through --token, ATOM_SERVICE_TOKEN, or ATOM_ADMIN_TOKEN.

Documentation

Overview

Package cli contains the domain concept definitions needed to support Magistrala CLI functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Limit query parameter.
	Limit uint64 = 10
	// Offset query parameter.
	Offset uint64 = 0
	// Name query parameter.
	Name string = ""
	// Identity query parameter.
	Identity string = ""
	// Metadata query parameter.
	Metadata string = ""
	// Status query parameter.
	Status string = ""
	// ConfigPath config path parameter.
	ConfigPath string = ""
	// Topic query parameter.
	Topic string = ""
	// Contact query parameter.
	Contact string = ""
	// RawOutput raw output mode.
	RawOutput bool = false
	// Username query parameter.
	Username string = ""
	// FirstName query parameter.
	FirstName string = ""
	// LastName query parameter.
	LastName string = ""
)

Functions

func NewBootstrapCmd

func NewBootstrapCmd() *cobra.Command

NewBootstrapCmd returns bootstrap command.

func NewCertsCmd

func NewCertsCmd() *cobra.Command

NewCertsCmd returns certificate command.

func NewConfigCmd

func NewConfigCmd() *cobra.Command

New config command to store params to local TOML file.

func NewDeviceTypesCmd added in v1.0.0

func NewDeviceTypesCmd() *cobra.Command

NewDeviceTypesCmd wraps pkg/atom's device type API. There is deliberately no delete operation: Atom has no deleteProfile mutation, so a device type is retired by setting its status, not removed.

func NewDevicesCmd added in v1.0.0

func NewDevicesCmd() *cobra.Command

func NewGatewaysCmd added in v1.0.0

func NewGatewaysCmd() *cobra.Command

NewGatewaysCmd is a thin view over devices filtered by is_gateway, not a separate entity surface — creating/editing a gateway is "devices" with attributes.is_gateway set (spec §8 A12).

func NewHealthCmd

func NewHealthCmd() *cobra.Command

NewHealthCmd returns health check command.

func NewMessagesCmd

func NewMessagesCmd() *cobra.Command

NewMessagesCmd returns messages command.

func NewRootCmd added in v1.0.0

func NewRootCmd() *cobra.Command

NewRootCmd returns the Atom-backed Magistrala CLI root command.

func ParseConfig

func ParseConfig(sdkConf smqsdk.Config) (smqsdk.Config, error)

ParseConfig - parses the config file.

func SetAtomClient added in v1.0.0

func SetAtomClient(c *atom.Client)

SetAtomClient sets the Atom client instance used by devices/gateways commands.

func SetSDK

func SetSDK(s smqsdk.SDK)

SetSDK sets magistrala SDK instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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