1 unstable release

new 0.3.0 Dec 20, 2024
0.0.1 Oct 31, 2024

#47 in Build Utils

Apache-2.0

570KB
10K SLoC

DSH resource management API command line tool

NOTE
This tool is still under development and will most likely contain many bugs. If you encounter any of these bugs (and you will), you can report them to unibox@kpn.com. Please include the exact command, the erroneous output and an explanation of the expected output. You can also send requests for new features to this e-mail address.

This project provides a tool to call functions on the DSH resource management API from the command line of your workstation. The following DSH resources can be listed, queried, searched, created and deleted.

resource create delete diff find/usage list show update
api
app from the app catalog
application / service
bucket
certificate
environment variable
image
manifest
metric
platform
proxy
secret
topic
vhost
volume

Meaning of the dots:

Capability is supported for this resource.
Capability for this resource is still experimental, incomplete or untested. Use at your own risk.

Local installation and run

The DSH Api Command Line Tool (dsh) can be installed on your local machine (assuming you have the rust tool chain installed), by executing the following command.

> cargo install dsh
...

Environment variables

In order to run dsh, either make sure that the environment variables described below are properly set. These values can also be set via the settings file or be provided as command line arguments.

variable description
DSH_CLI_CSV_QUOTE This environment variable specifies the quote character that will be used when printing csv data. If this variable is not provided, the value from the settings file will be used. The default setting is not to use any quote characters. Note that the tool will fail when the generated output already contains the quote character.
DSH_CLI_CSV_SEPARATOR This environment variable specifies the separator string that will be used when printing csv data. If this variable is not provided, the value from the settings file will be used. The default separator is "," (comma). Note that the tool will fail when the generated output already contains the csv separator string.
DSH_CLI_DRY_RUN If this environment variable is set (to any value) the tool will run in quiet mode, meaning that no output will be produced to the terminal (stdout and stderr). The same effect can be accomplished via the --dry-run command line argument.
DSH_CLI_GUID Group and user id for the target tenant. This value must be provided as a single integer, e.g. 1903. This environment variable can be overridden via the --guid command line argument.
DSH_CLI_MATCHING_STYLE This environment variable specifies the styling to be used when printing matching results for the find functions, e.q. when matching regular expressions. If this argument is not provided, the value from the settings file will be used. Else the default 'bold' will be used.
  • normal - Matches will be displayed in normal font
  • bold - Matches will be displayed bold
  • dim - Matches will be displayed dimmed
  • italic - Matches will be displayed in italics
  • underlined - Matches will be displayed underlined
  • reverse - Mathces will be displayed reversed
This environment variable can be overridden via the --matching-style command line argument.
DSH_CLI_NO_ESCAPE
NO_COLOR
When either of these environment variables is set (to any value) the output will not contain any color or other escape sequences. This environment variable can be overridden via the --no-color or --no-ansi command line argument.
DSH_CLI_OUTPUT_FORMAT This option specifies the format used when printing the output. If this argument is not provided, the value from the settings file will be used. Else, when stdout is a terminal the default 'table' will be used, if stdout is not a terminal the value 'json' will be used.
  • csv - Output will be formatted as comma separated values
  • json - Output will be in json format
  • plain - Output will be formatted as plain text
  • quiet - No output will be generated
  • table - Output will be formatted as a table with borders
  • table-no-border - Output will be formatted as a table without borders
  • toml - Output will be in toml format
  • yaml - Output will be in yaml format
This environment variable can be overridden via the --output-format command line argument.
DSH_CLI_PASSWORD This environment variable specifies the ecret api token/password for the target tenant. Note that when the environment variable DSH_CLI_PASSWORD_FILE or the argument --password-file command line argument is provided, this environment variable will not be used. For better security, consider using one of these two options instead of defining DSH_CLI_PASSWORD
DSH_CLI_PASSWORD_FILE This environment variable specifies a file containing the secret api token/password for the target tenant. Note that when the --password-file command line argument is provided, this environment variable will not be used.
DSH_CLI_PLATFORM Target platform on which the tenant's environment lives.
  • nplz - Non production landing zone
  • poc - Proof of concept platform
  • prod - Production landing zone
  • prodaz
  • prodlz
This environment variable can be overridden via the --platform command line argument.
DSH_CLI_QUIET When this environment variable is set (to any value) the tool will run in quiet mode, meaning that no output will be produced to the terminal (stdout and stderr). This environment variable can be overridden via the --quit command line argument.
DSH_CLI_SHOW_EXECUTION_TIME When this environment variable is set (to any value) the execution time of the executed function will be shown, in milliseconds. The execution time will also be shown when the verbosity level is set to high. This environment variable can be overridden via the --show-execution-time command line argument.
DSH_CLI_TERMINAL_WIDTH When this environment variable is set it will define the maximum terminal width. This environment variable can be overridden via the --terminal-width command line argument.
DSH_CLI_TENANT Tenant id for the target tenant. The target tenant is the tenant whose resources will be managed via the api. This environment variable can be overridden via the --tenant command line argument.
DSH_CLI_VERBOSITY If this option is provided, it will set the verbosity level. The default verbosity setting is low.
  • off - No logging will be printed
  • low - Lowest verbosity level, only error messages will be printed
  • medium - Medium verbosity level, some info will be printed
  • high - Highest verbosity level, all info will be printed, including the execution time
This environment variable can be overridden via the --verbosity command line argument. Also, when the environment variable DSH_CLI_QUIET is set or the command line argument --quiet is provided, nothing will be printed.

Settings file

Run

When installation completed without any errors and the environment variables are set, you should be able to start the tool from the command line.

> dsh
DSH resource management api command line interface.

Usage: dsh [OPTIONS] [SUBJECT/COMMAND]

Subjects/commands:
  api          List and call DSH resource management api.
  app          Show, manage and list apps deployed from the DSH app catalog.
  application  Show, manage and list applications deployed on the DSH.
  bucket       Show, manage and list DSH buckets.
  certificate  Show, manage and list DSH certificates.
  env          Find values used in configurations.
  image        Show image usage.
  manifest     Show App Catalog manifests.
  metric       Show metric exports.
  platform     Show, list and open platform resources.
  proxy        Show, manage and list DSH Kafka proxies.
  secret       Show, manage and list DSH secrets.
  topic        Show, manage and list DSH topics.
  vhost        Show vhost usage.
  volume       Show, manage and list DSH volumes.
  setting      Show, manage and list dsh settings.
  target       Show, manage and list dsh target configurations.
  help         Print this message or the help of the given subcommand(s)

Options:
  -p, --platform <PLATFORM>                 Provide target platform. [possible values: np-aws-lz-dsh, poc-aws-dsh,
                                            prod-aws-dsh, prod-aws-lz-dsh, prod-aws-lz-laas, prod-azure-dsh]
  -t, --tenant <TENANT>                     Provide target tenant.
  -g, --guid <GUID>                         Provide target group and user id.
      --password-file <FILE>                Provide password file name.
  -o, --output-format <FORMAT>              Set output format. [possible values: csv, json, json-compact, plain, quiet,
                                            table, table-no-border, toml, toml-compact, yaml]
  -v, --verbosity <VERBOSITY>               Set verbosity level. [possible values: off, low, medium, high]
      --dry-run                             Execute in dry-run mode.
      --force                               Force changes without confirmation.
      --matching-style <STYLE>              Set styling for matches. [possible values: normal, bold, dim, italic,
                                            underlined, reverse]
      --no-color                            No color.
  -q, --quiet                               Run in quiet mode.
      --show-execution-time                 Show execution time.
      --terminal-width <WIDTH>              Set terminal width.
      --generate-autocomplete-file <SHELL>  Generate autocomplete file [possible values: bash, elvish, fish, powershell,
                                            zsh]
  -h, --help                                Print help (see more with '--help')
  -V, --version                             Print version

For most commands adding an 's' as a postfix will yield the same result as using the 'list' subcommand, e.g. using 'dsh
apps' will be the same as using 'dsh app list'.

You can have a more comprehensive explanation by using the --help command line option. Commands also have their own help text.

> dsh --help
> dsh secret --help
> dsh secret list --help

Development

Dependencies

The dsh tool has a strong dependency on the dsh_api library, that provides the client for the DSH resource management API. This library is continuously being worked on, and is published to crates.io. Hence, at this time dsh depends on the crates.io version of the library.

# Cargo.toml
dsh_api = "0.3.1"

When developing simultaneously on dsh and dsh_api consider changing the library dependency to your local copy.

# Cargo.toml
dsh_api = { path = "../dsh-api/dsh-api" }

Coding guidelines

Before pushing code to github, make sure that you adhere to the code formatting defined in rustfmt.toml and that you have run the clippy linter. The following commands should return without any remarks:

> cargo +nightly fmt --check
> cargo clippy

Consider configuring your IDE to automatically apply the formatting rules when saving a file.

Dependencies

~22–56MB
~1M SLoC