The Lenses 5.x CLI is incompatible with Lenses 6.0
A new CLI for HQ is available here. To view the available commands run
terminal
docker run -it lensting/lenses-cli:6.0.0-alpha.16 --help
Command line interface to the Lenses HQ HTTP API.
Usage:
lenses [command]
Available Commands:
agent Command line interface to the agent.
api API meta information.
completion Generate the autocompletion script for the specified shell
config Manage CLI configuration.
environments Manage Environments.
groups Manage Groups.
help Help about any command
misc Miscellaneous commands.
roles Manage Roles.
service-accounts Manage ServiceAccounts.
users Manage Users.
utils Bundles utility commands.
version Display's the cli's version
Flags:
-a, --address string URL to the HQ HTTP api.
-c, --context string Config context.
-h, --help help for hq
-k, --insecure Insecure. Disables TLS verification.
-p, --password string Password.
-s, --session-id string Session ID (cookie auth).
-t, --token string Auth (bearer) token of a service account.
-u, --username string Username.
-v, --verbose Verbose; log to stderr.
-w, --verboser Verboser; log raw http traffic to stderr.
Use "lenses [command] --help" for more information about a command.
Environment Creation
In this page we will explain how to utilise CLI for environment creation.
Prerequisites:
Running HQ;
Enough permissions to create a new Service Account;
Running Docker daemon.
1
Go to IAM section.
Click the "Service Account" Tab;
Click on "New Service Account";
Fill in the mandatory fields. Make sure you assign a group with enough permissions to create new environments to the service account.
Copy the service account key, which will be used later;
An alternative method is to make an API call to HQ to create a new environment.
create_new_env.sh
#!/bin/bash
# Variables for URLs and endpoints
URL_LOGIN="http://hq:9991/api/v1/login"
URL_DATA="http://hq:9991/api/v1/environments"
# Check if the file exists and is not empty
if grep -q '^agent' "$FILE"; then
echo "[INFO] Environment has already been created -> Proceeding with the Agent creation"
exit 0
else
# Step 1: Perform the first request to get the session cookie
# Replace the login payload and headers as per your requirements
response=$(curl -s -D - \
-X POST \
-H 'Accept: application/json' \
-H "Content-Type: application/json" \
-d '{"username":"admin", "password":"admin"}' \
$URL_LOGIN)
# Step 2: Extract the session cookie from the response headers
# Assuming the session cookie is called "session_id" in the response
cookie=$(echo "$response" | grep -i 'Set-Cookie' | grep -o 'session_id=[^;]*')
if [ -z "$cookie" ]; then
echo "[ERROR] Failed to retrieve session cookie"
exit 1
fi
echo "[INFO] Session Cookie: $cookie"
# Step 3: Use the session cookie to make another request
response_body=$(curl -s \
-X POST \
-H "Cookie: $cookie" \
-H "Content-Type: application/json" \
-d '{ "name": "demo-environment", "tier": "development" }' \
$URL_DATA)