Skip to main content

Command Line Interface for cortexapps

Project description

Installation

pypi.org

pip install cortexapps-cli

Using a python virtual environment:

VENV_DIR=~/.venv/cortex
python3 -m venv $VENV_DIR
source $VENV_DIR/bin/activate
pip install cortexapps-cli

homebrew

The package will be published to homebrew in the future, but we need your help!

In order to be accepted to homebrew-core, a repository has to be ‘notable’. This is determined by running an audit of the homebrew formula. Currently, this results in the following:

brew audit --strict --new-formula --online cortexapps-cli
cortexapps-cli
  * GitHub repository not notable enough (<30 forks, <30 watchers and <75 stars)
Error: 1 problem in 1 formula detected.

Please help us by watching and starring https://github.com/cortexapps/cli. Once we’re ‘notable’, we’ll throw a small party for ourselves and then submit a PR to homebrew-core.

Workaround for homebrew installation

This is a temporary solution until we reach ‘notable’ status and get the formula added to homebrew-core.

Run the following commands to download the homebrew formula from this repo into your local homebrew tap:

curl -L -H "Accept: application/vnd.github.VERSION.raw" -o $(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/c/cortexapps-cli.rb https://api.github.com/repos/cortexapps/cli/contents/homebrew/cortexapps-cli.rb
HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source cortexapps-cli

Usage

Config file

The CLI requires an API key for all operations. This key is stored in a config file whose default location is ~/.cortex/config. This path can be overridden with the -c flag.

Minimal contents of the file:

[default]
api_key = REPLACE_WITH_YOUR_CORTEX_API_KEY

If you have multiple Cortex instances, you can create a section for each, for example:

[default]
api_key = REPLACE_WITH_YOUR_CORTEX_API_KEY

[my-test]
api_key = REPLACE_WITH_YOUR_CORTEX_API_KEY
base_url = https://app.cortex.mycompany.com

NOTE: if not supplied, base_url defaults to https://app.getcortexapp.com.

The CLI will retrieve configuration data from the [default] section unless you pass the -t/--tenant flag.

For example, to list all entities in the my-test tenant, run the following command:

cortex -t my-test catalog list

If the config file does not exist, the CLI will prompt you to create it.

Environment Variables

The CLI supports the following environment variables. If provided, the Cortex config file will not be read.

  • CORTEX_API_KEY

  • CORTEX_BASE_URL - this is optional if using Cortex cloud; defaults to https://app.getcortexapp.com

Example:

export CORTEX_API_KEY=<YOUR_API_KEY>

Commands

Run cortex -h to see a list of all commands:

Run cortex <subcommand> -h to see a list of all commands for each subcommand.

For example:

cortex audit-logs -h
usage: cortex CLI audit-logs [-h] {get} ...

positional arguments:
  {get}       audit logs help
    get       retrieve audit logs

options:
  -h, --help  show this help message and exit

Examples

Almost all CLI responses return JSON or YAML. Tools like jq and yq will be helpful to extract content from these responses.

Export from one tenant; import into another

This example shows how to export from a tenant named myTenant-dev and import those contents into a tenant named myTenant.

Your cortex config file will require api keys for both tenants. It would look like this:

[myTenant]
api_key = <your API Key for myTenant>

[myTenant-dev]
api_key = <your API Key for myTenant-dev>

Export

cortex -t myTenant-dev backup export
Getting resource definitions
 -->  my-resource-1
 Getting catalog entities
 -->  my-domain-1
 -->  my-service-1
 -->  my-service-2
 Getting IP Allowlist definitions
 Getting scorecards
 -->  my-scorecard-1
 Getting teams
 -->  my-team-1
 -->  my-team-2

 Export complete!
 Contents available in /Users/myUser/.cortex/export/2023-11-19-14-58-14

Import

cortex backup import -d <directory created by export>

NOTE: some content will not be exported, including integration configurations and resources that are automatically imported by Cortex. Cortex does not have access to any keys, so it cannot export any integration configurations.

Iterate over all domains

for domain in `cortex catalog list -t domain | jq -r ".entities[].tag" | sort`; do echo "domain = $domain"; done

Iterate over all teams

for team in `cortex catalog list -t team | jq -r ".entities[].tag" | sort`; do echo "team = $team"; done

Iterate over all services

for service in `cortex catalog list -t service | jq -r ".entities[].tag" | sort`; do echo "service = $service"; done

Get git details for a service

cortex catalog details -t my-service-1 | jq ".git"
{
  "repository": "my-org/my-service-1",
  "alias": null,
  "basepath": null,
  "provider": "github"
}

Add a suffix to all x-cortex-tag values for services

for service in `cortex catalog list -t service | jq -r ".entities[].tag" | sort`; do
   cortex catalog descriptor -y -t ${service} | yq '.info.x-cortex-tag |= . + "-suffix"' | cortex catalog create -f-
done

This example combines several CLI commands:

  • the for loop iterates over all services

  • the descriptor for each service is retrieved in YAML format

  • the YAML descriptor is piped to yq where the value of x-cortex-tag is retrieved and modified to add “-suffix” to the end

  • the modified YAML is then piped to the cortex catalog command to update the entity in cortex

NOTE: Any cortex commands that accept a file as input can also receive input from stdin by specifying a “-” after the -f parameter.

Add a group to all domains

for domain in `cortex catalog list -t domain | jq -r ".entities[].tag" | sort`; do
   cortex catalog descriptor -y -t ${domain} | yq -e '.info.x-cortex-groups += [ "my-new-group" ]' | cortex catalog create -f-
done

Remove a group from domains

for domain in `cortex catalog list -t domain -g my-old-group | jq -r ".entities[].tag" | sort`; do
   cortex catalog descriptor -y -t ${domain} | yq -e '.info.x-cortex-groups -= [ "my-old-group" ]' | cortex catalog create -f-
done

Add a domain parent to a single service

cortex catalog descriptor -y -t my-service | yq -e '.info.x-cortex-domain-parents += { "tag": "my-new-domain" }' | cortex catalog create -f-

Add a github group as an owner to a service

cortex catalog descriptor -y -t my-service | yq -e '.info.x-cortex-owners += { "name": "my-org/my-team", "type": "GROUP", "provider": "GITHUB" }' | cortex catalog create -f-

Modify all github basepath values for domain entitities, changing ‘-’ to ‘_’

for domain in `cortex catalog list -t domain | jq -r ".entities[].tag"`; do
   cortex catalog descriptor -y -t ${domain} | yq ".info.x-cortex-git.github.basepath |= sub(\"-\", \"_\")" | cortex catalog create -f-
done

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

cortexapps_cli-0.15.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

cortexapps_cli-0.15.0-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file cortexapps_cli-0.15.0.tar.gz.

File metadata

  • Download URL: cortexapps_cli-0.15.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.2.0-1016-azure

File hashes

Hashes for cortexapps_cli-0.15.0.tar.gz
Algorithm Hash digest
SHA256 c2b6b7359b9785e724c7b1b7305a297ed27862cfe9298f34fbe31f787994641f
MD5 758a0b1528a87a27e8e78fad04c4c27f
BLAKE2b-256 7858790ee6e49edd0fa76f4fd79025e2bed203f6af86abb129997bb70b958926

See more details on using hashes here.

File details

Details for the file cortexapps_cli-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: cortexapps_cli-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.2.0-1016-azure

File hashes

Hashes for cortexapps_cli-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6017c922d900d983e91208a1fa2c273408f2feaf59e2338d1d0d4e2bae40815
MD5 de445a14c39594ce7bc5c42fcb97adce
BLAKE2b-256 79324e625461fbbe0e91b4e38664b490e4dd3275f156aa81c50ceef183bd2f87

See more details on using hashes here.

Supported by

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