Skip to main content

A Python middleware service for managing Port.io resources including blueprints, actions, mappings, and widgets

Project description

Port Experience

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 handling
  • PortBlueprintManager: Manages Port.io blueprints
  • PortActionManager: Manages Port.io actions
  • PortMappingManager: Manages Port.io integrations and mappings
  • PortWidgetManager: Manages Port.io dashboard widgets
  • BlueprintTreeManager: 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-experience

Option 2: Install from source

  1. Clone the repository:

    git clone https://github.com/port-experimental/one-click-port-experience
    cd one-click-port-experience
    
  2. Create a virtual environment (recommended):

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Install package in development mode:

    pip install -e .
    
  5. Configure environment variables:

    Create a .env file 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

Recommended: Install and use the CLI

# Install the package
pip install port-experience

# Apply all configurations
experience apply

Alternative: Run from source

# Activate virtual environment
source .venv/bin/activate

# Install in development mode
pip install -e .

# Run using the CLI command
experience apply

The tool will:

  1. ๐Ÿ” Scan local JSON files in the setup/ directories
  2. ๐Ÿ“‹ Compare them with existing resources in Port.io
  3. ๐Ÿ“Š Display a summary of changes (new vs. updates)
  4. โš ๏ธ Ask for confirmation before proceeding
  5. ๐Ÿš€ Create/update resources based on your confirmation
  6. โœ… Report the results

Programmatic Usage

You can also use the managers programmatically in your Python code:

from port_experience 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

Currently, the CLI processes all resource types by default. For more granular control, you can modify the source code or use environment variables:

# The CLI will process all resources by default
experience apply

# For development/testing with specific resource types,
# you can modify the source code or use environment variables

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_experience/  # 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 experience apply  # Detailed debug information
LOG_LEVEL=INFO experience apply   # Standard information (default)
LOG_LEVEL=WARNING experience apply  # Only warnings and errors
LOG_LEVEL=ERROR experience apply  # Only errors

Development

Adding New Resource Types

  1. Create a new manager class inheriting from BasePortManager
  2. Implement resource-specific methods
  3. Add the resource type to main.py
  4. 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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

[Add your license here]

Support

For issues, questions, or contributions:

Acknowledgments

Built for seamless integration with Port.io - The Internal Developer Portal.

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

port_experience-0.1.1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

port_experience-0.1.1-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file port_experience-0.1.1.tar.gz.

File metadata

  • Download URL: port_experience-0.1.1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for port_experience-0.1.1.tar.gz
Algorithm Hash digest
SHA256 468bd92f89c6e2a29883a30b490dfa51e9344e2cc5a6e79e74c893b42672ff7d
MD5 775f6b7624a8a9c0af0b5f667a3156bb
BLAKE2b-256 dcdd753872a846f20f388dd6071c637617fcb4d594e2d8f509855a749f41e46e

See more details on using hashes here.

File details

Details for the file port_experience-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for port_experience-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1f7f602d941f0d4cff3abe1a7428ef26bd8f0185bc49c530548ae9b2efb251f
MD5 eb00129332dc3cf2bf5f0fe939186acf
BLAKE2b-256 b422a0313d4095fef87b9c0708d65372d065a3876b764251f37bb56050cdd5e9

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