-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
88 lines (88 loc) · 3.78 KB
/
doc.go
File metadata and controls
88 lines (88 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Package goplugins provides a production-ready, type-safe plugin architecture
// for Go applications. It supports gRPC and subprocess transport protocols
// with built-in circuit breaking, health monitoring, authentication, and graceful degradation.
//
// Key Features:
// - Type-safe plugin interfaces using Go generics
// - Multiple transport protocols (gRPC, subprocess execution)
// - Circuit breaker pattern for resilience
// - Health monitoring and automatic recovery
// - Authentication and authorization (API key, Bearer, mTLS, Basic, Custom)
// - Advanced security system with plugin whitelisting and hash validation
// - Hot-reloading of plugin configurations with active request monitoring
// - Production-grade graceful draining with atomic request tracking
// - Pluggable logging system supporting any framework
// - Comprehensive observability with metrics exporters and distributed tracing
// - Zero-downtime deployments and graceful shutdown
// - Simple API with fluent builder pattern for common use cases
//
// Basic Usage:
//
// // Define your plugin request/response types
// type KeyRequest struct {
// KeyID string `json:"key_id"`
// }
//
// type KeyResponse struct {
// Key []byte `json:"key"`
// Error string `json:"error,omitempty"`
// }
//
// // Simple API - Recommended for most use cases
// manager, err := goplugins.Production[KeyRequest, KeyResponse]().
// WithPlugin("vault-provider", goplugins.Subprocess("./vault-plugin")).
// WithSecurity("./plugins.whitelist").
// WithMetrics().
// Build()
// if err != nil {
// log.Fatal(err)
// }
// defer manager.Shutdown(context.Background())
//
// // Execute plugin operations
// resp, err := manager.Execute(ctx, "vault-provider", KeyRequest{KeyID: "master"})
//
// // Advanced API - For complex configurations
// manager := goplugins.NewManager[KeyRequest, KeyResponse](logger)
// config := goplugins.GetDefaultManagerConfig()
// config.Plugins = []goplugins.PluginConfig{
// {
// Name: "vault-provider",
// Transport: goplugins.TransportExecutable,
// Executable: "./vault-plugin",
// Auth: goplugins.AuthConfig{Method: goplugins.AuthAPIKey, APIKey: "secret"},
// },
// }
// err = manager.LoadFromConfig(config)
//
// Active Request Monitoring:
// The library includes a sophisticated request tracking system that enables true zero-downtime
// deployments by monitoring active requests in real-time:
//
// - Atomic request counters for lock-free performance (~50ns per operation)
// - Context-based request tracking for selective cancellation
// - Intelligent drain detection with 10ms precision (replaces time.Sleep)
// - Configurable drain timeouts with fallback to force cancellation
// - Real-time progress callbacks for operational visibility
//
// This eliminates the need for fixed timeout delays and provides precise control over
// graceful operations during hot reloads, plugin updates, and system shutdowns.
//
// Security System:
// The library implements a comprehensive security system with multiple layers:
//
// - Plugin Whitelisting: SHA256 hash validation of plugin binaries
// - Security Policies: Strict, Permissive, and Audit modes
// - Authentication: mTLS, API key, Bearer token, Basic, and Custom methods
// - Audit Logging: Comprehensive security event logging with unified SQLite backend
// - Path Traversal Protection: Prevents malicious path manipulation
// - Hot-reload: Security configuration updates without restart
// - Process Isolation: Subprocess plugins run in isolated processes
//
// Performance:
// Built-in connection pooling, intelligent caching, circuit breakers, optimized
// serialization, and atomic request tracking ensure high performance even under heavy load.
//
// Copyright (c) 2025 AGILira - A. Giordano
// SPDX-License-Identifier: MPL-2.0
package goplugins