Skip to main content

A rather opinionated CLI for managing API Products in Kong Konnect.

Project description

Konnect Dev Portal Ops CLI

A rather opinionated CLI tool for managing API products on Konnect Developer Portals.

The tool is designed to perform various operations, such as publishing, deprecating, unpublishing, or deleting API products and their versions based on OpenAPI Specification (OAS) files.

Ensure that the Konnect Developer Portals are set up before using this tool.

Note: The CLI is still under active development. Some features may not be fully supported yet. Use it responsibly and report any issues you encounter.

Table of Contents

Features

  • Publish or update API products on a Konnect Dev Portal.
  • Deprecate or unpublish API versions.
  • Delete API products and their associations.
  • Manage API product documentation.
  • Supports non-interactive modes for automation.

How It Works

The CLI tool requires two primary inputs:

  • The path to an OpenAPI Specification (OAS) file.
  • The name of the Konnect portal to perform operations on.

It then parses the OAS file to extract essential information for identifying the API Product and its version:

  • The info.title field in the OAS file serves as the API Product name, acting as the primary identifier for idempotent operations.
  • The info.description field in the OAS file provides the API Product description.
  • The info.version field in the OAS file denotes the API Product Version name, which is the primary identifier for version-specific idempotent operations.

Finally, the tool executes the following operations:

  1. Creates or updates the API Product on the Portal.
  2. Creates or updates the associated API Product Version.
  3. Ensures the OAS file is linked to the API Product Version.
  4. Publishes the API Product and its Version on the Portal.
  5. If a documents folder is provided, the tool synchronizes its contents with the API Product documentation on the Portal. This includes publishing new documents, updating existing ones, and removing documents that are no longer present in the folder.

Flow:

graph LR
    A[Parse OAS File] --> B[Create or Update API Product]
    B --> C[Create or Update API Product Version]
    C --> D[Attach OAS File to API Product Version]
    D --> E[Publish API Product and Version]
    E --> F[Sync API Product Documentation]

Installation

  1. Install the CLI using pip:

    $ pip install kptl
    
  2. (Optional) Create a yaml config file to set the configuration variables.

       # .config.yaml
       konnect_url: https://us.api.konghq.com
       konnect_token: <your-konnect-token>
    

Usage

Run the script using the following command:

$ kptl [options]  

Arguments

Option Required Description
--oas-spec Yes Path to the OAS spec file.
--docs No Path to the API product documents folder.
--konnect-portal-name Yes (except for --delete) Name of the Konnect portal to perform operations on.
--konnect-token Yes (except for --config) The Konnect spat or kpat token.
--konnect-url Yes (except for --config) The Konnect API server URL.
--deprecate No Deprecate the API product version on the portal.
--application-registration-enabled No Enable application registration for the API product on the portal.
--auto-aprove-registration No Automatically approve application registrations for the API product.
--auth-strategy-ids No Comma-separated list of authentication strategy IDs.
--unpublish {product,version} No Unpublish the API product or version from the portal.
--delete No Delete the API product and it's associations.
--yes No Skip confirmation prompts (useful for non-interactive environments).
--config Yes (except for --konnect-token, --konnect-url) Path to the configuration file.
--http-proxy No HTTP proxy URL.
--https-proxy No HTTPS proxy URL.

Examples

🚀 Publish an API Product and Version to a Portal

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv1.yaml \
   --konnect-portal-name my-portal 

🚀 Publish a New Version of the API Product to a Portal

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv2.yaml \
   --konnect-portal-name my-portal

⚠️ Deprecate an API Version on a Portal

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv1.yaml \
   --konnect-portal-name my-portal --deprecate

🚫 Unpublish an API Version from a Portal

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv1.yaml \
   --konnect-portal-name my-portal \
   --unpublish version

🚫 Unpublish an API Product from a Portal

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv1.yaml \
   --konnect-portal-name my-portal \
   --unpublish product

📚 Managing API Products Documentation

How it works:

  • All related API Product documents must be present in a directory.
  • All .md files in the directory are considered documentation files.
  • The ordering and inheritance of documents are based on the file name prefixes (ex: 1_,1.1_,1.2_,2_,3_,3.1_).
  • By default, all documents get published. If you want to unpublish a document, add the __unpublished tag at the end of the file name.
  • Existing API Product documents that are not present in the documents folder will be deleted.

For an example documents folder structure and use-cases, see the examples/docs directory.

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv1.yaml \
   --docs ../examples/docs \
   --konnect-portal-name my-portal

🗑️ Completely Delete an API Product and Its Associations

$ kptl --config .config.yaml \
   --oas-spec ../examples/oasv1.yaml --delete --yes

CLI Configuration

The CLI supports the following variables for configuration in a yaml file:

Variable Description
konnect_url Konnect API server URL.
konnect_token Token for authenticating API requests.

And the following environment variables:

Variable Description
LOG_LEVEL Logging verbosity level (DEBUG, INFO, WARNING, ERROR). Default: INFO.

Local Development

Requirements

  • Python 3+
  • PyYaml: For parsing YAML-based files.
  • requests: For making HTTP requests to the Konnect API.
  1. Clone the repository:

       $ git clone https://github.com/pantsel/konnect-portal-ops-cli
    
  2. Install the dependencies:

       $ make deps
    
  3. Run the CLI directly:

       $ python src/kptl/main.py [options]
    

Testing

To run the tests, use the following command from the root directory:

$ make test

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

kptl-0.7.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

kptl-0.7.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file kptl-0.7.0.tar.gz.

File metadata

  • Download URL: kptl-0.7.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for kptl-0.7.0.tar.gz
Algorithm Hash digest
SHA256 b458b8aa048c076c6d5cd616d52177f98d1f9c2cb5e96722689c4d42d71f5076
MD5 71f11db3e5b329466006a1792b48cb74
BLAKE2b-256 d05019e6bf53ee36da29f70f367a046ca322ad87c114e5ab8b85cbf3a2fd47c5

See more details on using hashes here.

File details

Details for the file kptl-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: kptl-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for kptl-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 037c7cc3a70eb4ba61365020ba1816b63f0e7d1dda50ee818535c3b805bae42f
MD5 d9331d9c4bc69cf054b7bb45c9726730
BLAKE2b-256 ade0159b7b605b4dced83e0ec9cf0b584e98bab4cf0883328252ddb0cd7c7abb

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