Akamai Command-Line Interface

repository·master·Indexed 42 days ago

https://github.com/akamai/cli

A command-line tool used to configure and manage Akamai's platform and products. It features a task-oriented interface and an extensible package system supporting Go, Python, and JavaScript. The CLI supports EdgeGrid authentication via .edgerc files and provides built-in commands for package management, configuration, and shell auto-completion for Bash and Zsh.

Tokens
12.4K
Snippets
34
Records
51
Agent score
53%

What's inside Akamai CLI

  1. Overview of Akamai CLI

    master
    The Akamai command-line interface (CLI) allows you to configure Akamai's platform and products directly from your terminal. It features a consistent, task-oriented interface across all Akamai products. You can extend its functionality by installing ready-to-use product packages or building your own custom solutions using supported languages like Go, Python, and JavaScript.
  2. How to build custom Akamai CLI commands

    master

    You can build custom commands using any language (Python, Go, JavaScript, etc.). To ensure compatibility with the Akamai CLI framework, follow these requirements:

    1. Naming: The executable must be named akamai-<command> (dashed-lowercase) or akamai<Command> (camelCase).
    2. Help: The command must support akamai-<command> help and ideally akamai-<command> help <sub-command>.
    3. Authentication: If using Akamai APIs, the executable must support the .edgerc format and respect the --edgerc and --section flags.
    4. Error Handling: The executable must exit with a non-zero status code if an action fails.
    5. Distribution: The package must be available via a Git repository that supports standard SSH public key authentication.
  3. Install the Akamai CLI with Docker

    master

    You can use a Docker container that comes with the Akamai CLI and pre-installed public packages. This is useful for a consistent development environment.

    Run the Akamai Development Environment

    To run the container and mount your local .edgerc file (required for authentication) into the container, use the following command:

    docker run -it -v $HOME/.edgerc:/root/.edgerc:ro akamai/shell

    Persistent Configuration

    To use a local .akamai-cli directory to manage your installed packages and persist configuration, modify the volume mount:

    docker run -it -v $HOME/.akamai-cli:/cli/.akamai-cli akamai/shell

    Shell Alias

    To use the akamai command directly via Docker, add this alias to your .bashrc, .bash_profile, or .zshrc:

    alias akamai='docker run -it -v $HOME/.edgerc:/root/.edgerc:ro akamai/shell'
    # Run with local .edgerc mounted
    $ docker run -it -v $HOME/.edgerc:/root/.edgerc:ro akamai/shell
    
    # Run with local .akamai-cli for persistent packages
    $ docker run -it -v $HOME/.akamai-cli:/cli/.akamai-cli akamai/shell
    
    # Add to shell config for convenience
    alias akamai='docker run -it -v $HOME/.edgerc:/root/.edgerc:ro akamai/shell'
  4. Install the Akamai CLI with Homebrew

    master

    If you have Homebrew installed on your system, you can install the Akamai CLI and its necessary dependencies using a single command. This will compile and globally install the binary.

    $ brew install akamai
  5. Compile the Akamai CLI from source

    master

    To build the Akamai CLI from source, you must have Go 1.25.7 or later installed.

    1. Navigate to your $GOPATH.
    2. Clone the repository: git clone github.com/akamai/cli.
    3. Enter the cli directory.
    4. Run the go build command for your specific platform.
    5. Move the resulting binary to a directory in your $PATH.
    # 1. Change directory
    $ cd $GOPATH
    
    # 2. Fetch package
    $ git clone github.com/akamai/cli
    
    # 3. Go to package directory
    $ cd cli
    
    # 4. Compile binary
    # Linux, macOS, or other Unix-based systems:
    $ go build -o akamai cli/main.go
    
    # Windows:
    $ go build -o akamai.exe cli/main.go
  6. Authenticate Akamai CLI with EdgeGrid credentials

    master

    Akamai-branded packages use a .edgerc file for standard EdgeGrid authentication. By default, the CLI looks for this file in your $HOME directory under a [default] section.

    To use a different file or section, use the --edgerc (or -e) and --section (or -s) global flags.

    Example .edgerc format:

    [default]
    client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
    host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
    access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
    client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj
    akamai --edgerc "~/.edgerc" --section "default" property-manager list
  7. Configure logging levels for Akamai CLI

    master

    You can view detailed log information by prepending the AKAMAI_LOG environment variable to any command. The available levels are (from least to most verbose):

    • fatal
    • error
    • warn
    • info
    • debug

    To redirect logs to a specific file, set the AKAMAI_CLI_LOG_PATH environment variable.

    Example: Running a command with debug logging to a file:

    AKAMAI_LOG=debug AKAMAI_CLI_LOG_PATH=akamai.log akamai update property-manager
    AKAMAI_LOG=debug akamai update property-manager
  8. Install the Akamai CLI via binaries

    master

    Download a release binary compatible with your operating system from the official releases page.

    Linux and macOS

    After downloading, make the binary executable and move it to a directory in your $PATH (e.g., /usr/local/bin/).

    Windows

    Download the appropriate .exe and run it directly from the command line.

    # Linux and macOS
    $ chmod +x ~/Downloads/akamai-<VERSION>-<PLATFORM>
    $ mv ~/Downloads/akamai-<VERSION>-<PLATFORM> /usr/local/bin/akamai
    
    # Windows
    $ akamai.exe help
  9. Manage Akamai CLI configuration

    master

    The config command allows you to interact with the Akamai CLI configuration settings. You can retrieve, set, unset, or list configuration values using a dot-notation path in the format <section>.<key>.

    Configuration Path Format

    All commands that target a specific setting require the path to be provided as the first argument in the format: section.key

    If a key contains hyphens in the actual configuration, the parser handles the mapping from the dot-notation provided in the CLI.

  10. The structure of an Akamai CLI package (cli.json)

    master

    Akamai CLI packages are defined by a cli.json file located within a package directory. This file describes the available subcommands, their requirements, and how to obtain the necessary binaries. When developing or inspecting a package, the subcommands structure is the core data model used by the CLI to register and execute commands.

    Key fields in the package definition include:

    • commands: A map of command objects containing metadata like name, bin (for binary-based packages), and other command-specific properties.
    • requirements: A packages.LanguageRequirements object specifying what the package needs to run (e.g., specific language runtimes).
    • pkg: The name of the package (derived from the directory name).

    Note: Command names are automatically converted to lowercase by the CLI during processing.

  11. Define command package metadata with cli.json

    master

    Every Akamai CLI package requires a cli.json file to define its requirements and commands. This file allows the CLI to manage dependencies and locate binaries.

    Schema Overview:

    • requirements: Specifies runtime requirements (e.g., go, node, python) and version constraints.
    • commands: An array of command objects containing:
      • name: The command name (used for the executable).
      • aliases: Array of alternative names.
      • version: Command version.
      • description: Short summary.
      • bin: A URL for fetching binaries. Supports placeholders: {{.Version}}, {{.Name}}, {{.OS}} (windows, mac, linux), {{.Arch}} (386, amd64, arm64), and {{.BinSuffix}} (e.g., .exe).
    {
      "requirements": {
        "go": "1.8.0"
      },
      "commands": [
        {
          "name": "purge",
          "version": "0.1.0",
          "description": "Purge content from the Edge",
          "bin": "https://github.com/akamai/cli-purge/releases/download/{{.Version}}/akamai-{{.Name}}-{{.OS}}{{.Arch}}{{.BinSuffix}}"
        }
      ]
    }
  12. How binary-based commands are downloaded

    master

    For packages that provide pre-compiled binaries rather than source code, the Akamai CLI uses a template-based URL system to fetch the correct executable for the user's environment.

    When a command is identified as a binary command (i.e., it has a bin field defined), the CLI performs the following:

    1. Determines OS/Arch: It detects the current runtime.GOOS and runtime.GOARCH.
      • Note: darwin is mapped to mac for URL purposes.
      • Note: windows targets receive a .exe suffix.
    2. Resolves URL: It parses the bin template string from the cli.json using the command's metadata.
    3. Downloads and Installs: It downloads the binary, saves it as akamai-<command-name><suffix>, and sets the file permissions to 0775 (executable).

    Example of how a binary URL might be templated in a cli.json (conceptual): https://example.com/binaries/{{.Name}}-{{.OS}}-{{.Arch}}