Skip to main content

Spritz CLI (spx) - Deploy and manage AI agents

Project description

Spritz CLI (spx)

Command-line interface for deploying and managing Spritz AI agents across dev and production environments.

๐Ÿ“‹ Table of Contents


๐Ÿ”ง Requirements

  • Python: 3.7 or higher
  • Browser: Modern browser with localStorage support
  • Internet: Active internet connection
  • Access: Spritz dashboard access

โš™๏ธ Setup

1. Installation

Install via pip:

pip install spritz-cli

Verify installation:

spx --version
spx --help

2. Configure Environment

Configure your development environment:

spx configure --profile dev
# Spritz URL: https://app.dev.spritz.activate.bar
# API URL: https://api.dev.spritz.activate.bar

Configure your production environment:

spx configure --profile prod
# Spritz URL: https://spritz.activate.bar
# API URL: https://api.spritz.activate.bar

3. Login

Authenticate with Spritz:

# Login to dev
spx login --profile dev

# Login to prod
spx login --profile prod

You're ready! ๐ŸŽ‰


๐Ÿ“– Commands

spx configure

Configure Spritz URL and API URL for different environments.

Usage:

spx configure [--profile PROFILE]

Options:

  • --profile - Profile name (default, dev, prod)

Example:

spx configure --profile dev
# Spritz URL [https://app.dev.spritz.activate.bar]: 
# API URL [https://api.dev.spritz.activate.bar]:
# โœ“ Profile 'dev' configured successfully
# Do you want to login now? [Y/n]: y

Configuration File: ~/.spx/config

Format:

[profile default]
spritz_url = https://spritz.activate.bar
api_url = https://api.spritz.activate.bar

[profile dev]
spritz_url = https://app.dev.spritz.activate.bar
api_url = https://api.dev.spritz.activate.bar

[profile prod]
spritz_url = https://spritz.activate.bar
api_url = https://api.spritz.activate.bar

spx login

Authenticate with Spritz via browser.

Usage:

spx login [--profile PROFILE]

Options:

  • --profile - Profile to login (default: default)

Example:

spx login --profile prod

# Output:
# โ†’ Opening browser for authentication...
#    Spritz URL: https://spritz.activate.bar
#    Waiting for authentication...
#    Please login in the browser window.
# 
# [Browser opens, user logs in, window closes]
# 
# โ†’ Verifying token...
# โœ“ Authentication successful!
#    Logged in as: pradeep@incaendo.com

How it works:

  1. Opens browser to Spritz dashboard
  2. Extracts token from localStorage automatically
  3. Verifies token with API
  4. Saves token for future use
  5. Browser window closes automatically

spx list-profiles

List all configured profiles and their login status.

Usage:

spx list-profiles

Example:

spx list-profiles

# Output:
# Configured profiles:
#   - default (https://spritz.activate.bar) โœ“ logged in
#   - dev (https://app.dev.spritz.activate.bar) โœ“ logged in
#   - prod (https://spritz.activate.bar) โœ— not logged in

spx whoami

Show current user information for a profile.

Usage:

spx whoami [--profile PROFILE]

Example:

spx whoami --profile prod

# Output:
# Profile: prod
# Spritz URL: https://spritz.activate.bar
# Email: pradeep@incaendo.com
# Auth0 ID: email|64e8a0485efd44509ed20f06
# Organization ID: 64a54a30899afb66425722fc
# Last Login: 2025-10-13T09:20:00.988Z

spx help

Show help for commands.

Usage:

spx --help                    # Show all commands
spx configure --help          # Configure command help
spx login --help              # Login command help
spx agent-onboarding --help   # Agent onboarding help
spx agent-update --help       # Agent update help

spx agent-onboarding

Deploy new agents from a configuration URL.

Usage:

spx agent-onboarding --profile PROFILE --url URL [--dry-run]

Options:

  • --profile - Environment profile (default, dev, prod)
  • --url - URL that returns agent configuration JSON (required)
  • --dry-run - Preview without deploying

Example:

spx agent-onboarding --profile prod --url https://config.example.com/agents.json

# Output:
# โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
# โ•‘           ๐Ÿš€ SPRITZ AGENT ONBOARDING                      โ•‘
# โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# 
# ๐Ÿ“‹ Profile: prod
# ๐ŸŒ Spritz Web: https://spritz.activate.bar
# ๐Ÿ”Œ Spritz API: https://api.spritz.activate.bar
# 
# ๐Ÿ“ฅ Loading agent configuration...
#    Source: https://config.example.com/agents.json
# โœ… Found 3 agent(s) to onboard
# 
# ๐Ÿ“ฆ Agent Configurations:
#   [1] Customer Support Agent
#   [2] Sales Assistant
#   [3] Analytics Bot
# 
# โš™๏ธ  Creating agents...
#   โœ… [1/3] Customer Support Agent onboarded successfully
#      ๐Ÿ†” Agent ID: 6925db4a0ad000cbdfa44cb5
#   โœ… [2/3] Sales Assistant onboarded successfully
#      ๐Ÿ†” Agent ID: 6925db4a0ad000cbdfa44cb6
#   โœ… [3/3] Analytics Bot onboarded successfully
#      ๐Ÿ†” Agent ID: 6925db4a0ad000cbdfa44cb7
# 
# โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
# โ•‘                    ๐Ÿ“Š SUMMARY                             โ•‘
# โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# 
# โœ… Success: 3/3
# 
# ๐ŸŽ‰ All agents onboarded successfully!

Agent Configuration Format:

Single agent:

{
  "name": "Customer Support Agent",
  "url": "https://your-agent.com/agent",
  "type": "chat",
  "description": "Handles customer inquiries"
}

Multiple agents:

[
  {
    "name": "Customer Support Agent",
    "url": "https://your-agent.com/agent1",
    "type": "chat"
  },
  {
    "name": "Sales Assistant",
    "url": "https://your-agent.com/agent2",
    "type": "voice"
  }
]

spx agent-update

Update existing agents from a configuration URL.

Usage:

spx agent-update --profile PROFILE --url URL [--dry-run]

Options:

  • --profile - Environment profile (default, dev, prod)
  • --url - URL that returns agent configuration JSON (required)
  • --dry-run - Preview without updating

How it works:

  1. Fetches agent configuration from the provided URL
  2. Extracts the url field from the configuration
  3. Searches for the existing agent in Spritz using that URL
  4. Updates the agent with the new configuration (PATCH)

Example:

spx agent-update --profile prod --url http://localhost:8000/agent

# Output:
# โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
# โ•‘           ๐Ÿš€ SPRITZ AGENT UPDATE                          โ•‘
# โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# 
# ๐Ÿ“‹ Profile: prod
# ๐ŸŒ Spritz Web: https://spritz.activate.bar
# ๐Ÿ”Œ Spritz API: https://api.spritz.activate.bar
# 
# ๐Ÿ“ฅ Loading agent configuration...
#    Source: http://localhost:8000/agent
# โœ… Configuration loaded successfully
# 
# ๐Ÿ” Agent URL from config: http://localhost:8000/agent
# ๐Ÿ”Ž Searching for existing agent in Spritz...
# โœ… Found agent: Customer Support Agent
#    Agent ID: 6925db4a0ad000cbdfa44cb5
# 
# โš™๏ธ  Updating agent...
# 
# โœ… Agent updated successfully!
# 
# ๐Ÿ“ Agent: Customer Support Agent
# ๐Ÿ†” ID: 6925db4a0ad000cbdfa44cb5

Requirements:

  • Agent must already exist in Spritz
  • Agent configuration must have a url field
  • The url field must match the agent's URL in Spritz

spx assign-agents

Assign agents (resolved from a discover JSON) to an organization.

Usage:

spx assign-agents --profile PROFILE --url URL

What it does:

  1. Fetches organizations from Spritz ($limit=999, $skip=0, sorted by _id desc, selecting profile.name/logo)
  2. Shows the names in 3-4 columns with numbered entries (logo indicator when present)
  3. Prompts you to pick an organization number
  4. Loads agents from your discover JSON, searches Spritz by each agent url to resolve IDs
  5. PATCHes the organization with the resolved agent IDs

Example:

spx assign-agents \
  --profile dev \
  --url https://example.com/agents-discover.json

# Output (trimmed):
# ๐Ÿ“ฅ Fetching organizations...
# โœ… Found 10 organization(s)
# [ 1] ๐Ÿ–ผ๏ธ Alpha Labs      [ 2] ๐Ÿ–ผ๏ธ Beta Group      [ 3] Gamma Corp
# [ 4] Delta Ventures    [ 5] ๐Ÿ–ผ๏ธ Epsilon Studio   [ 6] Zeta Partners
# ...
# ๐Ÿ”ข Enter organization number: 3
# โœ… Selected: Gamma Corp
# ๐Ÿ“ฅ Loading agent configuration...
# ๐Ÿ” Resolving agent IDs...
# โœ… Resolved 3 agent ID(s)
# โš™๏ธ  Assigning agents to organization...
# โœ… Agents assigned successfully!

Agent JSON requirements:

  • Provide a url for each agent so the CLI can search and resolve the Spritz agent ID.
  • Other agent fields are ignored for assignment but help with readability in logs.

spx validate

Validate profile configuration and authentication.

Usage:

spx validate [--profile PROFILE]

Example:

spx validate --profile prod

# Output:
# โœ“ Profile 'prod' is valid
#   Spritz URL: https://spritz.activate.bar
#   API URL: https://api.spritz.activate.bar
#   Token: ****************************************...tQuDQ
#   User: pradeep@incaendo.com
#   Organization: 64a54a30899afb66425722fc

What it checks:

  • Profile exists
  • Spritz URL is configured
  • API URL is configured
  • Authentication token is present
  • Token is valid and not expired
  • User information is accessible

Preview Before Deploy (Dry Run)

Test your deployment without making changes using the --dry-run flag.

Agent Onboarding (Dry Run):

spx agent-onboarding \
  --profile prod \
  --url https://config.example.com/agents.json \
  --dry-run

# Output:
# โš ๏ธ  DRY RUN MODE - No changes will be made
# 
# ๐Ÿ“ฆ Agent Configurations:
#   [1] Customer Support Agent
#   [2] Sales Assistant
# 
# ๐Ÿ” [DRY RUN] Would create the above agents
#    Endpoint: POST https://api.spritz.activate.bar/v1/agent/create

Agent Update (Dry Run):

spx agent-update \
  --profile prod \
  --url http://localhost:8000/agent \
  --dry-run

# Output:
# โš ๏ธ  DRY RUN MODE - No changes will be made
# 
# ๐Ÿ”ง DRY RUN: Would PATCH the following data:
# {
#   "name": "Customer Support Agent",
#   "url": "http://localhost:8000/agent",
#   "type": "chat"
# }
#    Endpoint: PATCH https://api.spritz.activate.bar/v1/agent/6925db4a0ad000cbdfa44cb5

๐Ÿ”„ Complete Workflow

Development to Production Pipeline

# 1. Configure environments
spx configure --profile dev
spx configure --profile prod

# 2. Login to both environments
spx login --profile dev
spx login --profile prod

# 3. Deploy to dev first (test environment)
spx agent-onboarding \
  --profile dev \
  --url https://config-dev.example.com/agents.json

# 4. Test your agents in dev
# ... manual testing ...

# 5. Preview production deployment
spx agent-onboarding \
  --profile prod \
  --url https://config-prod.example.com/agents.json \
  --dry-run

# 6. Deploy to production
spx agent-onboarding \
  --profile prod \
  --url https://config-prod.example.com/agents.json

# 7. Update agents when configuration changes
spx agent-update \
  --profile prod \
  --url https://config-prod.example.com/agents.json

๐Ÿ› Troubleshooting

"Profile not found"

Problem: Profile hasn't been configured.

Solution:

spx configure --profile prod

"Token expired" or "Authentication failed"

Problem: Authentication token has expired or is invalid.

Solution:

# Re-authenticate
spx login --profile prod

"Agent not found" (during update)

Problem: Agent doesn't exist in Spritz or URL doesn't match.

Solution:

# Option 1: Create the agent first
spx agent-onboarding --profile prod --url https://config.example.com/agent.json

# Option 2: Verify the agent exists and URL matches
spx whoami --profile prod

"Connection Error" or "Connection refused"

Problem: Agent server is not running or URL is incorrect.

Solution:

# Check if your agent server is running
curl http://localhost:8000/agent

# Test with dry-run first
spx agent-onboarding --profile dev --url http://localhost:8000/agent --dry-run

# Verify the URL is correct and accessible

"Request Timeout"

Problem: Server is taking too long to respond.

Solution:

# Check server response time
curl -w "@curl-format.txt" -o /dev/null -s http://localhost:8000/agent

# Increase timeout by contacting support
# Or optimize your agent's response time

"Browser doesn't close automatically"

Problem: Browser automation didn't complete properly.

Solution:

  • Close the browser window manually after seeing the success message
  • Token has already been saved to your configuration

"Cannot connect to localhost:8765"

Problem: Port 8765 is already in use.

Solution:

# Check what's using the port
lsof -i :8765

# Kill the process if needed
kill -9 <PID>

# Try login again
spx login --profile prod

Reset Everything

Remove all configuration and credentials:

rm -rf ~/.spx

Uninstall CLI:

pip uninstall spritz-cli -y

Complete reinstall:

# 1. Uninstall
pip uninstall spritz-cli -y
rm -rf ~/.spx

# 2. Reinstall
pip install spritz-cli

# 3. Reconfigure
spx configure --profile default
spx login --profile default

๐Ÿ’ป Development

Project Structure

spritz-cli/
โ”œโ”€โ”€ spritz.py              # Main CLI entry point
โ”œโ”€โ”€ setup.py               # Package configuration
โ”œโ”€โ”€ pyproject.toml         # Build configuration
โ”œโ”€โ”€ requirements.txt       # Dependencies
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ LICENSE                # MIT License
โ”œโ”€โ”€ MANIFEST.in            # Package manifest
โ”œโ”€โ”€ publish.sh             # Publishing script
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ”œโ”€โ”€ auth.py            # Authentication handling
โ”‚   โ”œโ”€โ”€ utils.py           # Utility functions
โ”‚   โ””โ”€โ”€ commands/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ configure.py   # Configure command
โ”‚       โ”œโ”€โ”€ login.py       # Login command
โ”‚       โ”œโ”€โ”€ onboarding.py  # Agent onboarding & update
โ”‚       โ””โ”€โ”€ info.py        # whoami, list-profiles, validate
โ””โ”€โ”€ tests/
    โ””โ”€โ”€ test_cli.py        # Unit tests

Getting Started

1. Clone the repository:

git clone https://github.com/Activate-Intelligence/spritz-cli.git
cd spritz-cli

2. Create virtual environment:

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install dependencies:

pip install -r requirements.txt

4. Install in editable mode:

pip install -e .

5. Test the CLI:

spx --version
spx --help

6. Run tests:

pytest tests/

Publishing to PyPI

Quick Publish

Make the script executable (first time only):

chmod +x publish.sh

Publish to PyPI:

./publish.sh

Publish to TestPyPI (for testing):

./publish.sh --test

Manual Publishing

Install build tools:

pip install --upgrade pip build twine

Clean and build:

rm -rf dist/ build/ *.egg-info
python -m build

Check the package:

twine check dist/*

Upload to TestPyPI (recommended first):

twine upload --repository testpypi dist/*

Test installation:

pip install --index-url https://test.pypi.org/simple/ spritz-cli

Upload to PyPI:

twine upload dist/*

Verify:

pip install spritz-cli
spx --version

Troubleshooting Publishing

Package name already taken:

Update setup.py:

setup(
    name='spritz-ai-cli',  # Or 'incaendo-spritz-cli'
    version='1.0.0',
    # ... rest of configuration
)

Then rebuild and publish:

rm -rf dist/ build/ *.egg-info
python -m build
twine upload dist/*

Upload with verbose output:

twine upload dist/* --verbose

Clear pip cache:

pip cache purge
pip install spritz-cli --no-cache-dir

Verify package exists:

curl -I https://pypi.org/project/spritz-cli/ | grep HTTP

PyPI Credentials

Create API Token:

  1. Go to https://pypi.org/manage/account/token/
  2. Click "Add API token"
  3. Name: spritz-cli-upload
  4. Scope: "Entire account" or specific project
  5. Copy the token (starts with pypi-)

Save credentials:

cat > ~/.pypirc << 'EOF'
[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
password = pypi-YOUR-TOKEN-HERE

[testpypi]
username = __token__
password = pypi-YOUR-TESTPYPI-TOKEN-HERE
repository = https://test.pypi.org/legacy/
EOF

chmod 600 ~/.pypirc

Using environment variables:

export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-YOUR-TOKEN-HERE
twine upload dist/*

๐Ÿค– Automation Scripts

Shell Scripts

agent-onboarding.sh - Onboard agents without assuming authentication

#!/bin/bash

# Configuration
PROFILE="prod"
AGENT_URL="http://localhost:8000/agent"

echo "๐Ÿš€ Spritz Agent Onboarding Automation"
echo "======================================"

# Check if spx is installed
if ! command -v spx &> /dev/null; then
    echo "โŒ Error: spritz-cli is not installed"
    echo "Install with: pip install spritz-cli"
    exit 1
fi

# Check if profile exists
if ! spx list-profiles 2>/dev/null | grep -q "$PROFILE"; then
    echo "โš™๏ธ  Configuring profile: $PROFILE"
    spx configure --profile "$PROFILE"
fi

# Check authentication
echo "๐Ÿ” Checking authentication..."
if ! spx validate --profile "$PROFILE" &>/dev/null; then
    echo "๐Ÿ”‘ Authentication required"
    spx login --profile "$PROFILE"
fi

# Onboard agents
echo "๐Ÿ“ฆ Onboarding agents from: $AGENT_URL"
spx agent-onboarding --profile "$PROFILE" --url "$AGENT_URL"

if [ $? -eq 0 ]; then
    echo "โœ… Agent onboarding completed successfully!"
else
    echo "โŒ Agent onboarding failed!"
    exit 1
fi

Make it executable:

chmod +x agent-onboarding.sh

Usage:

./agent-onboarding.sh

agent-update.sh - Update agents without assuming authentication

#!/bin/bash

# Configuration
PROFILE="prod"
AGENT_URL="http://localhost:8000/agent"

echo "๐Ÿ”„ Spritz Agent Update Automation"
echo "=================================="

# Check if spx is installed
if ! command -v spx &> /dev/null; then
    echo "โŒ Error: spritz-cli is not installed"
    echo "Install with: pip install spritz-cli"
    exit 1
fi

# Check if profile exists
if ! spx list-profiles 2>/dev/null | grep -q "$PROFILE"; then
    echo "โš™๏ธ  Configuring profile: $PROFILE"
    spx configure --profile "$PROFILE"
fi

# Check authentication
echo "๐Ÿ” Checking authentication..."
if ! spx validate --profile "$PROFILE" &>/dev/null; then
    echo "๐Ÿ”‘ Authentication required"
    spx login --profile "$PROFILE"
fi

# Update agents
echo "๐Ÿ”„ Updating agent from: $AGENT_URL"
spx agent-update --profile "$PROFILE" --url "$AGENT_URL"

if [ $? -eq 0 ]; then
    echo "โœ… Agent update completed successfully!"
else
    echo "โŒ Agent update failed!"
    exit 1
fi

Make it executable:

chmod +x agent-update.sh

Usage:

./agent-update.sh

Python Scripts

agent-onboarding.py - Python automation for agent onboarding

#!/usr/bin/env python3
"""
Spritz Agent Onboarding Automation
Handles authentication automatically before onboarding
"""

import subprocess
import sys

# Configuration
PROFILE = "prod"
AGENT_URL = "http://localhost:8000/agent"

def run_command(cmd):
    """Run shell command and return result"""
    try:
        result = subprocess.run(
            cmd,
            shell=True,
            capture_output=True,
            text=True,
            check=False
        )
        return result.returncode == 0, result.stdout, result.stderr
    except Exception as e:
        return False, "", str(e)

def check_spx_installed():
    """Check if spx CLI is installed"""
    success, _, _ = run_command("spx --version")
    return success

def check_profile_exists(profile):
    """Check if profile is configured"""
    success, output, _ = run_command("spx list-profiles")
    return success and profile in output

def check_authentication(profile):
    """Check if user is authenticated"""
    success, _, _ = run_command(f"spx validate --profile {profile}")
    return success

def configure_profile(profile):
    """Configure a new profile"""
    print(f"โš™๏ธ  Configuring profile: {profile}")
    success, _, _ = run_command(f"spx configure --profile {profile}")
    return success

def login(profile):
    """Login to profile"""
    print(f"๐Ÿ”‘ Logging in to: {profile}")
    success, _, _ = run_command(f"spx login --profile {profile}")
    return success

def onboard_agent(profile, url):
    """Onboard agent"""
    print(f"๐Ÿ“ฆ Onboarding agent from: {url}")
    cmd = f"spx agent-onboarding --profile {profile} --url {url}"
    result = subprocess.run(cmd, shell=True)
    return result.returncode == 0

def main():
    print("๐Ÿš€ Spritz Agent Onboarding Automation")
    print("=" * 40)
    
    # Check if spx is installed
    if not check_spx_installed():
        print("โŒ Error: spritz-cli is not installed")
        print("Install with: pip install spritz-cli")
        sys.exit(1)
    
    # Check if profile exists
    if not check_profile_exists(PROFILE):
        if not configure_profile(PROFILE):
            print(f"โŒ Failed to configure profile: {PROFILE}")
            sys.exit(1)
    
    # Check authentication
    print("๐Ÿ” Checking authentication...")
    if not check_authentication(PROFILE):
        if not login(PROFILE):
            print("โŒ Authentication failed")
            sys.exit(1)
    
    # Onboard agent
    if onboard_agent(PROFILE, AGENT_URL):
        print("โœ… Agent onboarding completed successfully!")
        sys.exit(0)
    else:
        print("โŒ Agent onboarding failed!")
        sys.exit(1)

if __name__ == "__main__":
    main()

Make it executable:

chmod +x agent-onboarding.py

Usage:

python3 agent-onboarding.py

agent-update.py - Python automation for agent updates

#!/usr/bin/env python3
"""
Spritz Agent Update Automation
Handles authentication automatically before updating
"""

import subprocess
import sys

# Configuration
PROFILE = "prod"
AGENT_URL = "http://localhost:8000/agent"

def run_command(cmd):
    """Run shell command and return result"""
    try:
        result = subprocess.run(
            cmd,
            shell=True,
            capture_output=True,
            text=True,
            check=False
        )
        return result.returncode == 0, result.stdout, result.stderr
    except Exception as e:
        return False, "", str(e)

def check_spx_installed():
    """Check if spx CLI is installed"""
    success, _, _ = run_command("spx --version")
    return success

def check_profile_exists(profile):
    """Check if profile is configured"""
    success, output, _ = run_command("spx list-profiles")
    return success and profile in output

def check_authentication(profile):
    """Check if user is authenticated"""
    success, _, _ = run_command(f"spx validate --profile {profile}")
    return success

def configure_profile(profile):
    """Configure a new profile"""
    print(f"โš™๏ธ  Configuring profile: {profile}")
    success, _, _ = run_command(f"spx configure --profile {profile}")
    return success

def login(profile):
    """Login to profile"""
    print(f"๐Ÿ”‘ Logging in to: {profile}")
    success, _, _ = run_command(f"spx login --profile {profile}")
    return success

def update_agent(profile, url):
    """Update agent"""
    print(f"๐Ÿ”„ Updating agent from: {url}")
    cmd = f"spx agent-update --profile {profile} --url {url}"
    result = subprocess.run(cmd, shell=True)
    return result.returncode == 0

def main():
    print("๐Ÿ”„ Spritz Agent Update Automation")
    print("=" * 40)
    
    # Check if spx is installed
    if not check_spx_installed():
        print("โŒ Error: spritz-cli is not installed")
        print("Install with: pip install spritz-cli")
        sys.exit(1)
    
    # Check if profile exists
    if not check_profile_exists(PROFILE):
        if not configure_profile(PROFILE):
            print(f"โŒ Failed to configure profile: {PROFILE}")
            sys.exit(1)
    
    # Check authentication
    print("๐Ÿ” Checking authentication...")
    if not check_authentication(PROFILE):
        if not login(PROFILE):
            print("โŒ Authentication failed")
            sys.exit(1)
    
    # Update agent
    if update_agent(PROFILE, AGENT_URL):
        print("โœ… Agent update completed successfully!")
        sys.exit(0)
    else:
        print("โŒ Agent update failed!")
        sys.exit(1)

if __name__ == "__main__":
    main()

Make it executable:

chmod +x agent-update.py

Usage:

python3 agent-update.py

Using Scripts in CI/CD

GitHub Actions Example:

name: Deploy Agent

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      
      - name: Install Spritz CLI
        run: pip install spritz-cli
      
      - name: Configure Spritz
        run: |
          mkdir -p ~/.spx
          echo "[profile prod]" > ~/.spx/config
          echo "spritz_url = https://spritz.activate.bar" >> ~/.spx/config
          echo "api_url = https://api.spritz.activate.bar" >> ~/.spx/config
      
      - name: Set Credentials
        run: |
          echo "${{ secrets.SPRITZ_TOKEN }}" > ~/.spx/credentials_prod
        env:
          SPRITZ_TOKEN: ${{ secrets.SPRITZ_TOKEN }}
      
      - name: Deploy Agent
        run: |
          python3 agent-onboarding.py

GitLab CI Example:

deploy_agent:
  stage: deploy
  image: python:3.11
  before_script:
    - pip install spritz-cli
    - mkdir -p ~/.spx
    - echo "[profile prod]" > ~/.spx/config
    - echo "spritz_url = https://spritz.activate.bar" >> ~/.spx/config
    - echo "api_url = https://api.spritz.activate.bar" >> ~/.spx/config
    - echo "$SPRITZ_TOKEN" > ~/.spx/credentials_prod
  script:
    - python3 agent-onboarding.py
  only:
    - main

๐Ÿ” Security Best Practices

Local Development

# Use dev profile for local testing
spx configure --profile dev
spx login --profile dev
spx agent-onboarding --profile dev --url http://localhost:8000/agent

Production

# Always verify before deploying to prod
spx agent-onboarding --profile prod --url https://prod.example.com/agent --dry-run

# Deploy after verification
spx agent-onboarding --profile prod --url https://prod.example.com/agent

CI/CD

  • Store tokens as encrypted secrets
  • Use separate profiles for different environments
  • Rotate tokens regularly
  • Never commit tokens to version control

Token Management

# Check token status
spx validate --profile prod

# Re-authenticate when needed
spx login --profile prod

# Logout to remove token
rm ~/.spx/credentials_prod

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

Development Setup

# Fork and clone the repository
git clone https://github.com/YOUR-USERNAME/spritz-cli.git
cd spritz-cli

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install in development mode
pip install -e .

# Install development dependencies
pip install pytest black flake8 mypy

# Run tests
pytest tests/

# Format code
black .

# Lint code
flake8 .

Making Changes

  1. Create a feature branch: git checkout -b feature/amazing-feature
  2. Make your changes
  3. Add tests for new features
  4. Run tests: pytest tests/
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Open a Pull Request

๐Ÿ“š Additional Resources

Documentation

Support


๐Ÿ“ Changelog

v1.0.0 (2024-12-02)

Initial Release

  • โœ… Profile-based configuration management
  • โœ… Browser-based authentication
  • โœ… Agent onboarding from URL
  • โœ… Agent updates from URL
  • โœ… Multiple environment support (dev, prod)
  • โœ… Dry-run mode for safe previews
  • โœ… Automatic token refresh
  • โœ… Comprehensive error handling

๐Ÿ™ Acknowledgments

  • Click - Beautiful command line interfaces
  • Requests - HTTP library for Python
  • PyYAML - YAML parser and emitter

Built with โค๏ธ by the Incaendo Technology Team


Quick Links:


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

spritz_cli-1.2.1.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

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

spritz_cli-1.2.1-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file spritz_cli-1.2.1.tar.gz.

File metadata

  • Download URL: spritz_cli-1.2.1.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for spritz_cli-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6d25761b6973a8afac04204b9f4ebe8e22e7fb9897ef8f505bc838b636b9a34b
MD5 3f8a17341ab6f52d5d215e815f315ac8
BLAKE2b-256 e420473bc947f0e6c78f17466a627824d71c828a2eb1a68deca198a7a8ec82bb

See more details on using hashes here.

File details

Details for the file spritz_cli-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: spritz_cli-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for spritz_cli-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 501ee43ff64f7f5dc22101ead644f0db539b9ddf7187d9e560705edf1bd42558
MD5 96cd93b9b26c98756e848dda720be934
BLAKE2b-256 2d6850045ebb858074fe84d4a51cb32ab637adc7915f94aea3b320fdaf13b331

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