The new StackState sts CLI provides easy access to the functionality provided by the StackState APIs. It can be used for automate using StackState data, configure StackState and to develop StackPacks.
The new sts CLI will eventually replace the stac CLI, however, not all commands are currently supported. For an overview of the differences and overlap between the new sts CLI and the stac CLI, see the CLI comparison page.
In the meantime, you can install and run as the new sts CLI on the same machine as the stac CLI.
Install the new sts CLI
The new sts CLI works with StackState version 5.0 and above.
If you are running an older version of StackState, use the stac CLI.
If it is installed, upgrade the old sts CLI to stac:
Follow the steps below to install the new sts CLI:
Open a Powershell terminal (version 5.1 or later), change the <URL> and <API-TOKEN> and run the command below. After installation, the sts command will be available for the current user on both the Powershell terminal and the command prompt (cmd.exe).
Alternatively, go to the CLI page in the StackState UI and copy the Quick installation command for Windows - this is pre-filled with the correct <URL> and <API-TOKEN> for your StackState instance.
Open a Powershell terminal (version 5.1 or later) and run the steps below. This can be done one step at a time, or joined together as a single script. After installation, the sts command will be available for the current user on both the Powershell terminal and the command prompt (cmd.exe).
Set the source version and target path for the CLI:
Open a terminal, change the <URL> and <API-TOKEN> and run the command below. After installation, the sts command will be available for the current user.
Alternatively, go to the CLI page in the StackState UI and copy the Quick installation command for MacOS - this is pre-filled with the correct <URL> and <API-TOKEN> for your StackState instance.
Open a terminal and run the steps below. This can be done one step at a time, or all together as a single script. After installation, the sts command will be available for the current user.
Download the latest CLI version for x86_64 (Intel) or arm64 (M1).
(VERSION=`curlhttps://dl.stackstate.com/stackstate-cli/LATEST_VERSION`&& ARCH=`uname-m`&& curl https://dl.stackstate.com/stackstate-cli/v$VERSION/stackstate-cli-$VERSION.darwin-$ARCH.tar.gz | tar xz --directory /usr/local/bin)
Verify that the CLI works:
stsversion
Open a terminal, change the <URL> and <API-TOKEN> and run the command below. After installation, the sts command will be available for the current user.
Alternatively, go to the CLI page in the StackState UI and copy the Quick installation command for Linux - this is pre-filled with the correct <URL> and <API-TOKEN> for your StackState instance.
Open a terminal and run the steps below. This can be done one step at a time, or all together as a single script. After installation, the sts command will be available for the current user.
Download and unpack the latest version for x86_64:
(VERSION=`curlhttps://dl.stackstate.com/stackstate-cli/LATEST_VERSION`&&curl https://dl.stackstate.com/stackstate-cli/v$VERSION/stackstate-cli-$VERSION.linux-x86_64.tar.gz | tar xz --directory /usr/local/bin)
Verify that the CLI works:
stsversion
To run the latest version of the CLI using Docker execute:
dockerrunstackstate/stackstate-cli2
Alternatively, go to the CLI page in the StackState UI and copy the Quick installation command for Docker - this is pre-filled with the correct <URL> and <API-TOKEN> required to configure the CLI for your StackState instance.
You can now run CLI commands by adding appending them to the end of the docker run command (e.g. docker run stackstate/stackstate-cli2 version).
Configure the new sts CLI
Quick start
The most secure way to use your API token is through an environment variable. You can store the API token with a secrets manager and inject it as an environment variable into your shell.
Linux, macOS and Windows
In the StackState UI, go to Main menu > CLI and copy your API token.
Run the command below, where <URL> is the URL to your StackState instance and <API-TOKEN> is the API token you copied from the CLI page in the StackState UI:
The connection to your StackState instance will be tested and a configuration file stored at ~/.config/stackstate-cli/config.yaml.
Docker
The Docker version of the CLI cannot be configured with a config file. Specify the configuration of your StackState instance using environment variables and pass these to Docker:
STS_CLI_URL - the URL to your StackState instance.
STS_CLI_API_TOKEN - the API token taken from the StackState UI Main menu > CLI page.
For example:
docker run \
-e STS_CLI_URL \
-e STS_CLI_API_TOKEN \
stackstate/stackstate-cli2 settings list --type Layer
Authentication
API token
By default, the CLI will authenticate using the API token that you provided when the CLI configuration was saved.
Service tokens
You can optionally use the CLI to create one or more service tokens to authenticate with the StackState Base and Admin APIs. For example, a service token can be used to authenticate in CI (Continuous Integration) scenarios where no real user is doing the operations on the StackState instance.
This will create a new service token and print it. The --expiration parameter is optional and can be used to set the expiration date of the service token.
Once you have this, you can configure the CLI to use it:
The new sts CLI supports configuration and management of different (authentication) contexts. This enables you to easily switch between an administrative and regular user, or to switch between different StackState instances. For example, you could use a different context for a test and production instance of StackState. You can list, save, delete, set and validate contexts in the new sts CLI. Run sts context -h for details of the available commands and their usage.
Configuration options
You do not need a configuration file to run the new sts CLI. You can also configure the CLI through a combination of environment variables and flags.
If multiple types of configuration are presented to the CLI the order of processing will be:
Flags
Environment variables
Config file
Environment variable
Flag
Description
STS_CLI_URL
--url
URL to your StackState instance.
STS_CLI_API_TOKEN
--api-token
API token to your StackState instance. The most secure way to use your API token is through an environment variable. You can store the API token with a secrets manager and inject it as an environment variable into your shell.
STS_CLI_SERVICE_TOKEN
--service-token
A service token to your StackState instance. The most secure way to use your service token is through an environment variable. You can store the service token with a secrets manager and inject it as an environment variable into your shell.
STS_CLI_API_PATH
n/a
The path appended to the end of the URL to get the API endpoint. (Defaults to /api)
STS_CLI_CONTEXT
--context
The name of the context to use.
Next to overriding specific parts of the config file, it is also possible to override the default config file location. This is done through the --config <PATH> flag.
Uninstall
Follow the instructions below to uninstall the StackState CLI.
The new sts CLI and all associated configuration are now removed for the current user.
Open a Powershell terminal and run each step one-by-one or all at once. The new sts CLI and all associated configuration will be removed for the current user.