mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
Created 11 packagerepo-specific workflow plugins: - auth_verify_jwt - JWT token verification - auth_check_scopes - Scope-based authorization - parse_path - URL path parameter extraction (Express-style) - normalize_entity - Field normalization (trim, lower, unique, sort) - validate_entity - JSON schema validation - kv_get/kv_put - RocksDB key-value operations - blob_put - Filesystem blob storage with SHA-256 hashing - index_upsert - Index entry management - respond_json/respond_error - Response formatting Created string.sha256 plugin: - Compute SHA256 hash of strings/bytes - Optional "sha256:" prefix - Used by packagerepo for content-addressed storage All plugins follow standard pattern: - Class extending NodeExecutor - Factory with create() function - package.json with metadata - Access external state via runtime parameter Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""Workflow plugin: validate entity against JSON schema."""
|
|
|
|
import jsonschema
|
|
from typing import Dict, Any
|
|
|
|
from ...base import NodeExecutor
|
|
|
|
|
|
class ValidateEntity(NodeExecutor):
|
|
"""Validate entity against JSON schema."""
|
|
|
|
node_type = "packagerepo.validate_entity"
|
|
category = "packagerepo"
|
|
description = "Validate entity against JSON schema"
|
|
|
|
def execute(self, inputs: Dict[str, Any], runtime: Any = None) -> Dict[str, Any]:
|
|
"""Validate entity against schema."""
|
|
entity = inputs.get("entity")
|
|
schema = inputs.get("schema")
|
|
|
|
if not entity:
|
|
return {"error": "entity is required"}
|
|
|
|
if not schema:
|
|
return {"error": "schema is required"}
|
|
|
|
try:
|
|
# Validate entity against schema
|
|
jsonschema.validate(instance=entity, schema=schema)
|
|
|
|
return {"result": {"valid": True, "errors": []}}
|
|
|
|
except jsonschema.ValidationError as e:
|
|
# Collect validation errors
|
|
errors = []
|
|
errors.append({
|
|
"path": list(e.path),
|
|
"message": e.message,
|
|
"schema_path": list(e.schema_path),
|
|
})
|
|
|
|
return {"result": {"valid": False, "errors": errors}}
|
|
|
|
except jsonschema.SchemaError as e:
|
|
return {"error": f"invalid schema: {str(e)}", "error_code": "INVALID_SCHEMA"}
|
|
|
|
except Exception as e:
|
|
return {"error": f"validation failed: {str(e)}", "error_code": "VALIDATION_FAILED"}
|