Skip to main content

No project description provided

Project description

API Deployment Script Documentation

This script allows you to deploy an API to Anypoint Platform using either command-line arguments or a YAML configuration file.

Prerequisites

  • Python 3.x
  • pip
  • Anypoint Platform Connected App
  • API Spec uploaded to Anypoint Exchange

Connected App

The Anypoint Platform API credentials are required to authenticate with the Anypoint Platform API. The Connected App should have the following permissions:

  • API Manager: Manage APIs Configuration, Manage Policies, Manage Contracts, and Deploy API Proxies
  • Runtime Manager: Read Servers, Manage Servers, Create Applications, and Delete Applications
  • Exchange: Exchange Contributor and Exchange Viewer
  • General: View Organization, View Client Management Providers
  • OpenID: Profile
  • Secrets Manager: Grant access to secrets

Packaging and Dependencies

This script can be packaged as a Python package and imported or downloaded using Pip. Another option is to zip and download the script folder and install the dependencies manually.

Install Dependencies Manually and Run Script

pip install -r requirements.txt
python3 flex_gw_api_automation/api_deploy.py <COMMANDS>

Package using PyPi and Pip

This script can be transformed into a Python Package using Poetry and be uploaded to any PyPI repository.

Install Poetry

curl -sSL https://install.python-poetry.org | python3 -

Or

pip install poetry

Configure PyPI Repository

To generate the package and publish it to a PyPI repository first you have to configure the URL and credentials. For example, use the default PyPI public repository:

poetry config pypi-token.pypi <PYPI_API_TOKEN>

For more information: Poetry Docs - Repository

Publish Package

First, generate the requirements.txt file that will be used by pip if the package is downloaded manually. Then, publish the package.

poetry export -f requirements.txt --output requirements.txt --without-hashes
poetry publish

Use Pip Package

If the library is uploaded to your PyPI repository, you can download the package as a Pip dependency and use it.

pip install flex-gw-api-automation
python -m flex_gw_api_automation.api_deploy <COMMANDS>

Collaborate

To work with this Python package you'll need Poetry installed.

Create a virtual environment running

poetry install
poetry env info

Activate the Poetry environment and run the script:

poetry shell
python3 flex_gw_api_automation/api_deploy.py

Or run the code within the poetry environment using:

poetry run python api_deploy.py

Usage

The script can be run in two ways:

  1. Using command-line arguments
  2. Using a YAML configuration file

1. Using Command-Line Arguments

To run the script with command-line arguments, use the following format:

python api_deploy.py --bg-name "Your BG" --env-name "Your Env" --flex-gw-instance-name "Your FG" --client-id "Your ID" --client-secret "Your Secret" --api-spec-group-id "Your Group ID" --api-spec-asset-id "Your Asset ID" --api-spec-version "Your Version" --listener-port 8081 --listener-basepath "/api" --upstream-url "http://your-upstream-url"

Replace the placeholder values with your actual configuration details.

2. Using a YAML Configuration File

To run the script with a YAML configuration file, use the following format:

python api_deploy.py --file your_config.yaml

Minimal YAML Configuration

A minimal YAML configuration file should contain only the required parameters. Here's an example:

bg_name: "Your Business Group"
env_name: "Your Environment"
flex_gw_instance_name: "Your Flex Gateway Instance"
client_id: "Your Client ID"
client_secret: "Your Client Secret"
api_spec_group_id: "Your API Spec Group ID"
api_spec_asset_id: "Your API Spec Asset ID"
api_spec_version: "Your API Spec Version"
listener_port: 8081
listener_basepath: "/api"
routes:
  - label: "default"
    upstreams:
      - label: "default"
        uri: "http://your-upstream-url"
        weight: 100

Save this as deploy_config_minimal.yaml and run:

python api_deploy.py --file deploy_config_minimal.yaml

Full YAML Configuration

A full YAML configuration file should contain all the required and optional parameters. Here's an example:

bg_name: "Your Business Group"
env_name: "Your Environment"
ext_client_provider_name: "Your External Client Provider Name"
flex_gw_instance_name: "Your Flex Gateway Instance"
client_id: "Your Client ID"
client_secret: "Your Client Secret"
api_spec_group_id: "Your API Spec Group ID"
api_spec_asset_id: "Your API Spec Asset ID"
api_spec_version: "Your API Spec Version"
listener_port: 8081
listener_basepath: "/api"

routes:
  - label: Route 1
    methods: POST|PUT
    host: www.example.com
    path: /test/*
    headers:
      destination: "2"
    upstreams:
      - label: httpbin1
        uri: http://httpbin.org
        weight: 100
        tls_context:
          secret_group_name: "flex-gateway-secret-group"
          tls_context_name: "flex-gateway-tls-context"
  - label: Route 2
    methods: null
    host: null
    path: null
    headers: {}
    upstreams:
      - label: httpbin2
        uri: http://httpbin.org
        weight: 50
        tls_context:
          secret_group_name: "flex-gateway-secret-group"
          tls_context_name: "flex-gateway-tls-context"
      - label: httpbin3
        uri: http://httpbin.org
        weight: 50
        tls_context:
          secret_group_name: "flex-gateway-secret-group"
          tls_context_name: "flex-gateway-tls-context"

sla_tiers:
  - name: Gold
    description: Gold Tier
    autoapprove: false
    max_requests: 1000
    timeperiodmillis: 3600000

policies:
  - group_id: 68ef9520-24e9-4cf2-b2f5-620025690913
    asset_id: message-logging
    policy_version: "2.0.1"
    configuration_data:
      loggingConfiguration: 
        - itemName: Log
          itemData:
            message: "#['TEST']"
            level: "INFO"
            firstSection: true
            secondSection: false

Save this as deploy_config.yaml and run:

python api_deploy.py --file deploy_config.yaml

Notes

  • The command-line argument method is suitable for basic deployments with one upstream and no policies or SLA tiers.
  • The YAML file method allows for more complex configurations and is recommended for production deployments.
  • Ensure all required fields are provided, whether using command-line arguments or a YAML file.

Output

The example output will look like this:

Authenticating with Anypoint Platform
Getting Business Group ID for: <Business Group>
Business Group ID: <Business Group ID>
Getting Environment ID for: <Environment>
Environment ID: <Environment ID>
Getting Client Provider ID for: <External Provider Name>
Client Provider ID: <External Provider ID>
Getting Flex Gateway Instance ID for: <Instance Name>
Flex Gateway Instance ID: <Instance ID>
Creating API Instance
Getting Secret Group ID for: <Secret Group Name>
Getting TLS Context ID for: <TLS Context Name>
Getting Secret Group ID for: <Secret Group Name>
Getting TLS Context ID for: <TLS Context Name>
API Instance ID: <API Instance ID>
Creating SLA Tiers
Created SLA Tier: Gold
Created SLA Tier IDs: [<SLA Tier ID>]
Applying Policies
Applied Policy: message-logging
Applied Policy IDs: [<Policy ID>]
Deploying API Instance: <API Instance ID>
API Instance <API Instance ID> deployment initiated successfully
API deployment completed successfully!

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

flex_gw_api_automation-0.1.4.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

flex_gw_api_automation-0.1.4-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file flex_gw_api_automation-0.1.4.tar.gz.

File metadata

  • Download URL: flex_gw_api_automation-0.1.4.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0

File hashes

Hashes for flex_gw_api_automation-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1cb97d6d934f1ad77b1247e4c66b7909e13834f1a4ee32f7b7788cf729ad7e42
MD5 b261529fce895fc193e7f2cf980498a6
BLAKE2b-256 0ef1aecdc22c5b8f2e84bfe36471afc7dcdcfb0d34901185024822acb96d544d

See more details on using hashes here.

File details

Details for the file flex_gw_api_automation-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for flex_gw_api_automation-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3b96141c8727135f8966d21162ca38241f68a5f04a546e12359c4841f339370d
MD5 8ebe2da5dcfcfc38c60aa1f45eb709a1
BLAKE2b-256 0ca337b251c1e53f7235fffb9129892e7118488fdb085d627f64ccce8d3ba548

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