A Python middleware service for managing Port.io resources including blueprints, actions, mappings, and widgets
Project description
Port One-Click Middleware
A Python middleware service for managing Port.io resources including blueprints, actions, mappings, and widgets. This tool provides an interactive CLI to create, update, and synchronize Port.io configurations from local JSON files.
Features
- ๐ฏ Multi-Resource Management: Handle blueprints, actions, mappings, and widgets
- ๐ Intelligent Sync: Compare local resources with existing Port.io resources
- โ Interactive Confirmation: Review and confirm changes before applying them
- ๐ก๏ธ Safe Merge Strategy: Update existing resources without losing data
- ๐ Detailed Reporting: Clear summary of operations and their outcomes
- ๐ง Flexible Configuration: Control which resources to process via environment variables
Architecture
The project is organized into specialized managers:
BasePortManager: Shared authentication and API request handlingPortBlueprintManager: Manages Port.io blueprintsPortActionManager: Manages Port.io actionsPortMappingManager: Manages Port.io integrations and mappingsPortWidgetManager: Manages Port.io dashboard widgetsBlueprintTreeManager: Handles blueprint dependency resolution
Quick Start
Prerequisites
- Python 3.10 or higher
- Port.io account with API credentials (Client ID and Client Secret)
Installation
Option 1: Install from PyPI (recommended)
pip install port-one-click-middleware
Option 2: Install from source
-
Clone the repository:
git clone https://github.com/port-experimental/one-click-port-experience cd one-click-port-experience
-
Create a virtual environment (recommended):
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Install package in development mode:
pip install -e .
-
Configure environment variables:
Create a
.envfile in the project root:PORT_CLIENT_ID=your_client_id_here PORT_CLIENT_SECRET=your_client_secret_here # Optional: Customize directories BLUEPRINTS_DIR=setup/blueprints ACTIONS_DIR=setup/actions MAPPINGS_DIR=setup/mappings WIDGETS_DIR=setup/widgets # Optional: Specify which resources to process ACTION=all # Options: blueprints, actions, mappings, widgets, all # Optional: Define which folders are required EXPECTED_FOLDERS=blueprints,actions,widgets # Comma-separated list # Optional: Set log level LOG_LEVEL=INFO # Options: DEBUG, INFO, WARNING, ERROR
Getting Port.io Credentials:
- Log in to your Port.io account
- Navigate to Settings โ Credentials
- Create a new API client or use existing credentials
- Copy the Client ID and Client Secret
Usage
Run the middleware to sync all resources:
Method 1: Run as a module (recommended)
# Activate virtual environment
source .venv/bin/activate
# Run the project
python -m port_one_click_middleware.main
Method 2: Run directly
# Activate virtual environment
source .venv/bin/activate
# Run directly from project root
python port_one_click_middleware/main.py
Method 3: After installing as a package
# Install the package
pip install port-one-click-middleware
# Run using the CLI command
port-middleware
The tool will:
- ๐ Scan local JSON files in the
setup/directories - ๐ Compare them with existing resources in Port.io
- ๐ Display a summary of changes (new vs. updates)
- โ ๏ธ Ask for confirmation before proceeding
- ๐ Create/update resources based on your confirmation
- โ Report the results
Programmatic Usage
You can also use the managers programmatically in your Python code:
from port_one_click_middleware import PortBlueprintManager, PortActionManager
# Initialize managers
blueprint_manager = PortBlueprintManager(
client_id="your_client_id",
client_secret="your_client_secret"
)
action_manager = PortActionManager(
client_id="your_client_id",
client_secret="your_client_secret"
)
# Setup blueprints from directory
blueprint_results = blueprint_manager.setup_all_blueprints("setup/blueprints")
# Setup actions from directory
action_results = action_manager.setup_all_actions("setup/actions")
# Check if specific resources exist
if blueprint_manager.blueprint_exists("my_blueprint"):
print("Blueprint exists!")
if action_manager.action_exists("my_action"):
print("Action exists!")
Processing Specific Resources
Use the ACTION environment variable to process specific resource types:
# Process only blueprints
ACTION=blueprints python -m port_one_click_middleware.main
# Process only actions
ACTION=actions python -m port_one_click_middleware.main
# Process only widgets
ACTION=widgets python -m port_one_click_middleware.main
# Process all (default)
ACTION=all python -m port_one_click_middleware.main
Project Structure
one-click-port-experience/
โโโ pyproject.toml # Python package configuration
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
โโโ .env # Environment configuration (create this)
โโโ .gitignore # Git ignore patterns
โโโ port_one_click_middleware/ # Main package directory
โ โโโ __init__.py # Package initialization and exports
โ โโโ main.py # Main entry point and orchestration
โ โโโ managers/ # Resource managers
โ โโโ __init__.py # Base manager class
โ โโโ action_manager.py # Action resource manager
โ โโโ blueprint_manager.py # Blueprint resource manager
โ โโโ blueprint_tree_manager.py # Blueprint dependency manager
โ โโโ mapping_manager.py # Mapping/integration manager
โ โโโ widget_manager.py # Widget/dashboard manager
โโโ setup/ # Resource definitions (JSON files)
โโโ blueprints/ # Blueprint JSON files
โโโ actions/ # Action JSON files
โโโ mappings/ # Mapping JSON files
โโโ widgets/ # Widget JSON files
Configuration
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
PORT_CLIENT_ID |
โ | - | Port.io API Client ID |
PORT_CLIENT_SECRET |
โ | - | Port.io API Client Secret |
BLUEPRINTS_DIR |
โ | setup/blueprints |
Path to blueprints directory |
ACTIONS_DIR |
โ | setup/actions |
Path to actions directory |
MAPPINGS_DIR |
โ | setup/mappings |
Path to mappings directory |
WIDGETS_DIR |
โ | setup/widgets |
Path to widgets directory |
ACTION |
โ | all |
Resource types to process |
EXPECTED_FOLDERS |
โ | blueprints,actions,mappings,widgets |
Required directories |
LOG_LEVEL |
โ | INFO |
Logging verbosity level |
Resource JSON Format
Each resource type expects JSON files in a specific format. Here are examples:
Blueprint (setup/blueprints/example.json):
{
"identifier": "my_blueprint",
"title": "My Blueprint",
"icon": "Microservice",
"schema": {
"properties": {
"name": {
"type": "string",
"title": "Name"
}
}
}
}
Action (setup/actions/example.json):
{
"identifier": "my_action",
"title": "My Action",
"icon": "Github",
"blueprint": "my_blueprint",
"invocationMethod": {
"type": "WEBHOOK"
}
}
How It Works
1. Resource Discovery
The tool scans the configured directories for JSON files containing resource definitions.
2. Comparison & Analysis
For each local resource, the tool:
- Checks if it already exists in Port.io
- Determines if it needs to be created or updated
- Identifies any additional resources in Port.io not in local files
3. User Confirmation
Before making any changes, the tool displays:
- Resources to be created (๐)
- Resources to be updated (๐)
- Total operation summary
4. Merge Strategy
The tool uses a merge strategy when updating resources:
- Existing properties are preserved
- New properties are added
- Changed properties are updated
- No data is deleted
5. Execution & Reporting
After confirmation, the tool:
- Processes each resource
- Reports success/failure for each operation
- Provides a final summary
Manager Classes
BasePortManager
Located in managers/__init__.py, provides:
- Authentication with Port.io API
- Access token management
- Generic API request methods
- JSON file discovery
- Logging configuration
PortBlueprintManager
Manages Port.io blueprints:
- Create and update blueprints
- Check blueprint existence
- Handle blueprint dependencies
PortActionManager
Manages Port.io actions:
- Create and update actions
- Validate action configurations
- Link actions to blueprints
PortMappingManager
Manages Port.io integrations:
- Create and update mappings
- Handle integration configurations
PortWidgetManager
Manages Port.io dashboard widgets:
- Create and update pages/widgets
- Configure dashboard layouts
BlueprintTreeManager
Handles blueprint dependencies:
- Parse blueprint relationships
- Resolve dependency order
- Build blueprint hierarchy trees
Error Handling
The tool includes comprehensive error handling:
- Missing Credentials: Clear error if Port.io credentials are not provided
- API Failures: Detailed logging of API errors with status codes
- Invalid JSON: Reports which files have syntax errors
- Missing Directories: Configurable whether to treat as error or skip
- Failed Operations: Continues processing other resources, reports failures at the end
Logging
Configure logging verbosity with the LOG_LEVEL environment variable:
LOG_LEVEL=DEBUG python main.py # Detailed debug information
LOG_LEVEL=INFO python main.py # Standard information (default)
LOG_LEVEL=WARNING python main.py # Only warnings and errors
LOG_LEVEL=ERROR python main.py # Only errors
Development
Adding New Resource Types
- Create a new manager class inheriting from
BasePortManager - Implement resource-specific methods
- Add the resource type to
main.py - Create corresponding directory in
setup/
Running Tests
# Add your test commands here
pytest tests/
Troubleshooting
Authentication Failures
Error: Authentication failed: 401
Solution: Verify your PORT_CLIENT_ID and PORT_CLIENT_SECRET are correct.
Missing Resources
Error: Required blueprints directory 'setup/blueprints' not found
Solution: Create the directory or update BLUEPRINTS_DIR in .env.
API Rate Limits
If you encounter rate limiting, the tool will log the error. Wait a moment and retry.
JSON Syntax Errors
Error: Invalid JSON in example.json: Expecting ',' delimiter
Solution: Validate your JSON files using a JSON validator.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
[Add your license here]
Support
For issues, questions, or contributions:
- Open an issue in the repository
- Contact the development team
- Check Port.io documentation: https://docs.getport.io/
Acknowledgments
Built for seamless integration with Port.io - The Internal Developer Portal.
Project details
Release history Release notifications | RSS feed
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 port_one_click_middleware-0.1.0.tar.gz.
File metadata
- Download URL: port_one_click_middleware-0.1.0.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bead37a5e43015602659da60afb62a4e0169356e076685fcf1c57ab75eb68ce
|
|
| MD5 |
fd0865871b575e2544379eb931cf15cc
|
|
| BLAKE2b-256 |
b45e9be1df9b51ed06199d691d4e21bd1a14711e376871201fc921d188409e5d
|
File details
Details for the file port_one_click_middleware-0.1.0-py3-none-any.whl.
File metadata
- Download URL: port_one_click_middleware-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c97721b6e4bcb539dff089df8622bce6c1858d35e7448e29096661a06503501
|
|
| MD5 |
44ef8013f659108f1ea910c213081b22
|
|
| BLAKE2b-256 |
a63477192b506f129843e34f63ab300be85c3f63458291c4fb346ad42b8f968a
|