Skip to main content

CLI to access salt-api

Project description

salt-api-cli

Thin Python CLI for salt-api. Depends only on the standard library plus rich (readable output) and typeguard (JSON validation).

Logs in once with PAM credentials, caches the token in ~/.cache/salt-api-cli/token.json, then invokes salt-api's local, runner, and wheel clients over HTTPS. The cached token self-heals: it is refreshed proactively when its stored expiry has passed, and reactively when the server rejects it (e.g. after the salt-master container restarts and wipes its session store) — on rejection the CLI discards the token, logs in again, and retries the request once.

Commands come in two layers:

  • Low-level (local, runner, wheel) map directly to the salt-api clients and print raw JSON.
  • High-level (state, keys) wrap those clients and render readable, colorized output with rich.

Installation

pip install salt-api-cli

Configuration

Configuration is resolved in this order (later sources override earlier):

  1. ~/.saltapiclirc — INI file, [salt-api-cli] section
  2. Environment variables — SALT_API_URL, SALT_API_USER, SALT_API_PASS, SALT_API_INSECURE
  3. Command-line flags — --url, --user, --password, --insecure, --relogin, --no-token-cache

Example ~/.saltapiclirc:

[salt-api-cli]
url = https://salt.example.com
user = salt_api
password = secret
insecure = false

SALT_API_INSECURE=1 (or insecure = true in the config) skips TLS certificate verification.

Token cache control: --relogin ignores any cached token and logs in fresh (re-caching the new token); --no-token-cache neither reads nor writes the cache for that run; salt logout discards the cached token.

Usage

Low-level commands (raw JSON)

These map one-to-one to the salt-api clients and print the response verbatim as indented JSON.

# Local client — fan out to minions
salt local '*' test.ping
salt local 'bml*' cmd.run 'whoami'
salt local 'bml1' cmd.run 'Get-Date' shell=powershell

# Runner client (master-side: manage.status, jobs.list_jobs, ...)
salt runner manage.status
salt runner jobs.list_jobs

# Wheel client (master-side, low-level)
salt wheel key.list_all

High-level commands (readable, colorized)

These wrap the low-level clients and render their output with rich.

# State runs — a colored table of states, one row each, with a summary.
# Driven by the local client + state.* functions.
salt state highstate 'bml1'           # apply the highstate
salt state test 'bml1'                # dry-run the highstate (forces test=True)
salt state apply 'bml1' veyon         # apply specific sls module(s)
salt state apply 'bml1' veyon.ldap test=True

# Key management — wraps the wheel client's key.* functions.
# `keys list` shows one colored panel per status (Accepted/Pending/Denied/Rejected).
salt keys list
salt keys accept <id-or-glob>
salt keys accept-all
salt keys reject <id-or-glob>
salt keys delete <id-or-glob>

Color and panels appear when writing to a terminal; output is plain when piped to a file or pager.

Any key=value argument is parsed as a kwarg to the salt function; anything else is positional.

You can also invoke the CLI as a module: python -m salt_api_cli ....

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

salt_api_cli-1.2.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

salt_api_cli-1.2.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file salt_api_cli-1.2.0.tar.gz.

File metadata

  • Download URL: salt_api_cli-1.2.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for salt_api_cli-1.2.0.tar.gz
Algorithm Hash digest
SHA256 3c152c4d47c34a6fa20ff446023cd96e230b1745935ea4d64de6d20a06525e33
MD5 8f2980819e9f02ca8d1e89f015d7ae7a
BLAKE2b-256 b1c74dd210c509f85ca9ba923338ff68169331dc272adc2e37c678ad3b1d4632

See more details on using hashes here.

File details

Details for the file salt_api_cli-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: salt_api_cli-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for salt_api_cli-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4fe22e2c6cb563211de8c89a9949c39c61a33598786e5c51e835353d4800138
MD5 009059f9897b38fabbe8729cec1ebad9
BLAKE2b-256 1c2cc5054f2a62d4aa904e07de2517ae7cf8e2562ead8c7107f424b05df6fae2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page