Skip to content

sedkis/tyk-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tyk CLI

A powerful command-line interface for managing Tyk APIs and configurations. Built to streamline API lifecycle management with OpenAPI Specification (OAS) support.

πŸ“– View Complete Documentation | πŸš€ Get Started | πŸ’‘ Examples

Go Version License Latest Release Downloads Go Report Card Documentation

✨ Features

  • πŸš€ Interactive Setup Wizard - Get started quickly with guided configuration
  • 🌍 Unified Config/Environment System - Named environments with seamless switching
  • πŸ“ OpenAPI First - Native support for OAS 3.0 specifications
  • πŸ”§ Flexible Configuration - Environment variables, unified config file, or CLI flags
  • 🎨 Beautiful CLI - Colorful, intuitive command-line experience
  • βœ… Comprehensive Testing - >80% test coverage with live environment validation

Licensed Tyk only

  • This CLI is designed to work with the licensed version of Tyk - via Control Plane.

πŸš€ Quick Start

Installation

Homebrew (Recommended)

# Add the Tyk tap
brew tap sedkis/tyk

# Install the CLI
brew install tyk

## Check version
$ tyk -v
tyk version 0.2.1

## UPGRADING the cli
$ brew update

$ brew upgrade tyk

## Check version
$ tyk -v
tyk version 0.2.1

Direct Download

# Download and install the latest release
curl -L "https://github.com/sedkis/tyk-cli/releases/latest/download/tyk-cli_$(uname -s)_$(uname -m).tar.gz" | tar xz
sudo mv tyk /usr/local/bin/

# Verify installation
tyk --version

From Source

git clone https://github.com/sedkis/tyk-cli.git
cd tyk-cli
go build -o tyk .
sudo mv tyk /usr/local/bin/

Initialize Configuration

# Run the interactive setup wizard
tyk init

πŸ’‘ Need more help? Check out our complete documentation with detailed guides, examples, and troubleshooting tips!

πŸ“‹ Commands

Configuration/Environment Management

# Interactive setup wizard
tyk init                    # Full setup wizard with multiple environments

# Environment management
tyk config list            # List all environments
tyk config use             # Switch environnment interactively
tyk config use staging     # Switch to staging environment
tyk config current         # Show current environment
tyk config set dashboard-url https://api.tyk.io  # Update current environment

API Management

# Quick API Creation
tyk api create --name "User Service" --upstream-url https://users.api.com

# Create from OpenAPI Spec Management
tyk api import-oas --file petstore.yaml           # Import external OpenAPI spec
tyk api import-oas --url https://api.example.com/openapi.json  # Import from URL
tyk api update-oas <api-id> --file new-spec.yaml  # Update API's OpenAPI spec only

# Tyk-Enhanced OAS Management (GitOps)
# If the file contains x-tyk-api-gateway.info.id, apply will upsert:
# update if it exists, or create with the same ID if missing
tyk api apply --file enhanced-api.yaml            # Idempotent upsert (update or create)

# General Operations
tyk api list                        # List all APIs
tyk api list -i                     # Interactive
tyk api get <api-id>                               # Get API details
tyk api get <api-id> --oas-only                   # Get OpenAPI spec only
tyk api delete <api-id>             # Delete API (with confirmation)
tyk api delete <api-id> --yes       # Delete without confirmation

# Utilities (Phase 3)
tyk api convert --file api.yaml --format apidef  # Convert OAS to Tyk format

βš™οΈ Configuration

The Tyk CLI uses a unified environment/configuration system with the following precedence (highest to lowest):

  1. Command-line flags (--dash-url, --auth-token, --org-id)
  2. Environment variables (TYK_DASH_URL, TYK_AUTH_TOKEN, TYK_ORG_ID)
  3. Named environments in config file (~/.config/tyk/cli.toml)

Each "environment" is simply a named set of configuration values.

Environment Variables

export TYK_DASH_URL=http://localhost:3000
export TYK_AUTH_TOKEN=your-api-token
export TYK_ORG_ID=your-org-id

Config File (Unified Environment System)

Configuration is automatically saved to ~/.config/tyk/cli.toml:

default_environment = "dev"

[environments.dev]
dashboard_url = "http://localhost:3000"
auth_token = "dev-api-token" 
org_id = "dev-org-id"

[environments.staging]
dashboard_url = "https://staging.tyk.io"
auth_token = "staging-token"
org_id = "staging-org-id"

[environments.production]
dashboard_url = "https://api.yourcompany.com"
auth_token = "prod-token"
org_id = "prod-org-id"

πŸ” Finding Your Credentials

Dashboard URL

  • Local Development: http://localhost:3000 (default)
  • Tyk Cloud: https://admin.cloud.tyk.io
  • Self-hosted: Your custom domain

Auth Token

  1. Log into your Tyk Dashboard
  2. Go to Users β†’ Your User Profile
  3. Find API Access Credentials
  4. Copy the Auth Token

Organization ID

  • Found next to your API Token, in User Profile.

πŸ› οΈ Development

Prerequisites

  • Go 1.21+
  • Make (optional)

Setup

# Clone the repository
git clone https://github.com/sedkis/tyk-cli.git
cd tyk-cli

# Install dependencies
go mod download

# Build the CLI
go build -o tyk .

# Run tests
go test ./...

# Build with make (if available)
make build
make test

Project Structure

tyk-cli/
β”œβ”€β”€ cmd/           # CLI commands and subcommands
β”œβ”€β”€ internal/      # Internal packages
β”‚   β”œβ”€β”€ config/    # Configuration management
β”‚   β”œβ”€β”€ client/    # HTTP client for Tyk Dashboard API
β”‚   └── util/      # Utilities and helpers
β”œβ”€β”€ pkg/           # Public packages (if any)
β”œβ”€β”€ test/          # Integration tests
└── docs/          # Documentation

πŸ—ΊοΈ Roadmap

πŸ”§ Other lifecycle objects

  • Tyk Security Policies
  • Tyk API Tokens / Credentials

πŸ”§ Enhanced Features

  • tyk api convert - Convert between OAS and Tyk API definition formats
  • Enhanced error handling and user experience improvements
  • Advanced JSON output formatting
  • API versioning commands (versions list/create/switch-default)
  • API validation and linting
  • GitOps diff functionality

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Common Development Tasks

# Run tests
go test ./...

# Run tests with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

# Lint code (if golangci-lint is installed)
golangci-lint run

# Format code
go fmt ./...

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

πŸ™ Acknowledgments

Built with:

  • Cobra - CLI framework
  • Viper - Configuration management
  • Survey - Interactive prompts
  • Color - Terminal colors

About

A CLI to manage your Tyk configurations

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •