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. This tool allows you to publish, deprecate, unpublish, or delete API products and their versions based on state files.
Before using the CLI, ensure you have your developer portals set up on Konnect. For more information, see the Konnect documentation.
Note: The CLI is under active development. Some features may not be fully supported yet. Use responsibly and report any issues.
Table of Contents
Features
- Publish or update API Products and Versions on a Konnect Dev Portal.
- Link Gateway Services to API Product Versions.
- Manage API Product Documents.
- Deprecate or unpublish API versions.
- Delete API products and their associations.
- Supports non-interactive modes for automation.
Installation
-
Install the CLI using
pip:pip install kptl
-
(Optional) Create a
yamlconfig file to set the CLI configuration variables:# $HOME/.kptl.config.yaml konnect_url: https://us.api.konghq.com konnect_token: <your-konnect-token> http_proxy: http://proxy.example.com:8080 # Optional https_proxy: https://proxy.example.com:8080 # Optional
Usage
kptl [command] [options]
Available Commands
sync
Synchronize the predefined API Product state with Konnect.
kptl sync state_file.yaml --config .config.yaml
delete
Delete the API Product and its associations.
kptl delete product_name_or_id --config .config.yaml
To skip the interactive confirmation prompt, use the --yes flag:
kptl delete product_name_or_id --config .config.yaml --yes
explain
Explain the API Product state file and the operations that will be performed on Konnect.
kptl explain state_file.yaml
Common Arguments
| Option | Required | Description |
|---|---|---|
--konnect-token |
Yes (if config file not set) | The Konnect token to use for authentication. |
--konnect-url |
Yes (if config file not set) | The Konnect API server URL. |
--config |
No | Path to the CLI configuration file. Defaults to $HOME/.kptl.config.yaml. |
--http-proxy |
No | HTTP proxy URL. |
--https-proxy |
No | HTTPS proxy URL. |
Examples
Sync API Product State
Example state file:
# state.yaml
_version: 1.0.0
info:
name: HTTPBin API
description: A simple API Product for requests to httpbin
portals:
- name: dev_portal
- name: prod_portal
versions:
- name: "1.0.0"
spec: examples/api-specs/v1/httpbin.yaml
portals:
- name: dev_portal
- name: prod_portal
- name: "2.0.0"
spec: examples/api-specs/v2/httpbin.yaml
portals:
- name: dev_portal
- name: prod_portal
To sync the API Product state with Konnect, run:
kptl sync state.yaml --config .config.yaml
Unpublish API Product Versions
To unpublish an API Product version from a portal, update the state file to set the publish_status to unpublished for the desired portal.
# state.yaml
versions:
- name: "1.0.0"
spec: examples/api-specs/v1/httpbin.yaml
portals:
- name: dev_portal
config:
publish_status: unpublished
Then run the sync command:
kptl sync state.yaml --config .config.yaml
Deprecate API Product Versions
To deprecate an API Product version from a portal, update the state file to set deprecated to true for the desired portal.
# state.yaml
versions:
- name: "1.0.0"
spec: examples/api-specs/v1/httpbin.yaml
portals:
- name: dev_portal
config:
deprecated: true
Then run the sync command:
kptl sync state.yaml --config .config.yaml
Link Gateway Services to API Product Versions
To link a Gateway Service to an API Product version, update the state file to include the gateway_service section with the appropriate id and control_plane_id.
# state.yaml
versions:
- name: "1.0.0"
spec: examples/api-specs/v1/httpbin.yaml
gateway_service:
id: <gateway-service-id>
control_plane_id: <control-plane-id>
Then run the sync command:
kptl sync state.yaml --config .config.yaml
Manage API Products Documentation
To manage API Product documents, ensure all related documents are present in a directory. The ordering and inheritance of documents are based on file name prefixes (e.g., 1_, 1.1_, 1.2_, 2_, 3_, 3.1_). By default, all documents get published. To unpublish a document, add the __unpublished tag at the end of the file name. Existing API Product documents not present in the documents folder will be deleted.
For an example documents folder structure, see the examples/products/httpbin/docs directory.
To sync the API Product documents, update the state file to include the documents section with the sync flag set to true and the dir pointing to the documents directory.
# state.yaml
documents:
sync: true
dir: examples/products/httpbin/docs
Then run the sync command:
kptl sync state.yaml --config .config.yaml
State File Explanation
The example state file at examples/products/httpbin/state.yaml defines the configuration for the HTTPBin API product.
Version
_version: 1.0.0
Specifies the version of the state file format.
- _version: (Required) Specifies the version of the state file format. Default is
1.0.0.
Info
info:
name: HTTPBin API
description: A simple API Product for requests to /httpbin
Contains metadata about the API product, including its name and description.
- info: (Required) Contains metadata about the API product.
- name: (Required) The name of the API product.
- description: (Optional) A description of the API product.
Documents
documents:
sync: true
dir: examples/products/httpbin/docs
Defines the synchronization settings and directory for the API documentation.
- documents: (Optional) Defines the synchronization settings and directory for the API documentation.
- sync: (Required) A boolean indicating whether to sync the documents.
- dir: (Required) The directory where the documents are stored.
Portals
portals:
- name: dev_portal
config:
publish_status: published
- name: prod_portal
config:
publish_status: unpublished
Lists the portals where the API product will be published, along with their publication status.
- portals: (Optional) Lists the portals where the API product will be published.
- id: (Required - if
nameis not set) The ID of the portal. ID takes precedence over name for related operations. - name: (Required - if
idis not set) The name of the portal. At least one ofidornameis required. - config: (Optional) Configuration for the portal.
- publish_status: (Optional) The publication status of the portal. Default is
published.
- publish_status: (Optional) The publication status of the portal. Default is
- id: (Required - if
Versions
versions:
- name: "1.0.0"
spec: examples/api-specs/v1/httpbin.yaml
gateway_service:
id: null
control_plane_id: null
portals:
- name: dev_portal
config:
deprecated: true
publish_status: published
auth_strategy_ids: []
application_registration:
enabled: false
auto_approve: false
- name: prod_portal
config:
deprecated: true
publish_status: published
auth_strategy_ids: []
application_registration:
enabled: false
auto_approve: false
- name: "2.0.0"
spec: examples/api-specs/v2/httpbin.yaml
gateway_service:
id: null
control_plane_id: null
portals:
- name: dev_portal
config:
deprecated: false
publish_status: published
auth_strategy_ids: []
application_registration:
enabled: false
auto_approve: false
- name: prod_portal
config:
deprecated: false
publish_status: published
auth_strategy_ids: []
application_registration:
enabled: false
auto_approve: false
Defines the different versions of the API product, including their specifications, gateway service details, and portal configurations. Each version can have different settings for deprecation, publication status, authentication strategies, and application registration.
- versions: (Required) Defines the different versions of the API product.
- name: (Optional) The name of the version. Defaults to the version of the OAS file.
- spec: (Required) The Open API Specification file for the version.
- gateway_service: (Optional) Details of the gateway service linked to the version.
- id: (Optional) The ID of the gateway service.
- control_plane_id: (Optional) The control plane ID of the gateway service.
- portals: (Optional) Lists the portals where the version will be published.
- id: (Required - if
nameis not set) The ID of the portal. ID takes precedence over name for related operations. - name: (Required - if
idis not set) The name of the portal. At least one ofidornameis required. - config: (Optional) Configuration for the portal.
- deprecated: (Optional) A boolean indicating whether the version is deprecated. Default is
false. - publish_status: (Optional) The publication status of the version. Default is
published. - auth_strategy_ids: (Optional) A list of authentication strategy IDs.
- application_registration: (Optional) Settings for application registration.
- enabled: (Optional) A boolean indicating whether application registration is enabled. Default is
false. - auto_approve: (Optional) A boolean indicating whether application registration is auto-approved. Default is
false.
- enabled: (Optional) A boolean indicating whether application registration is enabled. Default is
- deprecated: (Optional) A boolean indicating whether the version is deprecated. Default is
- id: (Required - if
Logging
The CLI uses the logging module to log messages to the console. The default log level is set to INFO.
To change the log level, set the LOG_LEVEL environment variable to one of the following values: DEBUG, INFO, WARNING, or ERROR.
Development
Requirements
- Python 3.7+
PyYaml: For parsing YAML-based files.requests: For making HTTP requests to the Konnect API.
-
Clone the repository:
git clone https://github.com/pantsel/konnect-portal-ops-cli
-
Install the dependencies:
make deps -
Run the CLI directly:
PYTHONPATH=src python src/kptl/main.py [command] [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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kptl-0.9.0.tar.gz.
File metadata
- Download URL: kptl-0.9.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bb18767c24e431497464fe1f696e1584aadca054c0635873fb991331e2c9af6
|
|
| MD5 |
eab844a5bdd72e0f46e7e068ef342b9e
|
|
| BLAKE2b-256 |
91ee0136b0567aefdc094cafa9c878c010d1e46e195e95fff88d05404451a043
|
File details
Details for the file kptl-0.9.0-py3-none-any.whl.
File metadata
- Download URL: kptl-0.9.0-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78fbaabe31af79a8d31780b35950319c94680fe9d0cd51cb608c1afa058d490c
|
|
| MD5 |
5ab7d04836b7d39c1533d51c6737748a
|
|
| BLAKE2b-256 |
32a2345fe8f65106f0c9bb004f596d8d34be582c82838984c836d85d30049ab7
|