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.

Requirements

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

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

  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.6.0.tar.gz (16.1 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.6.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kptl-0.6.0.tar.gz
Algorithm Hash digest
SHA256 ee5ac76d1aa84320e229a1e49eac310f065b83d483a85038a2e87e2d4c8984c5
MD5 2ae3260c41e2003c307a9839bf135685
BLAKE2b-256 1040750343a96144ec3cdaf866673b4bc4de4bd30cd37917d0336e0cfb1c1778

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kptl-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef41d1ad8811e7fb85bdfbc6efa271984e62f35394a6983ae20a731ec23acbd9
MD5 5514a5f04f137adb970654d1179dbfe2
BLAKE2b-256 e8239bb4439a2cbde37ba363d03a32cdd4cd3967e0766af0c97fcbd58f53c547

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