Files
deploy-felhom-compose/controller/internal/integrations/integrations.go
T
admin 0a5840a255 feat: app-to-app integration framework + OnlyOffice handlers
Generic integration system for connecting deployed apps via toggle UI.
First handlers: OnlyOffice→FileBrowser (config.yaml patch) and
OnlyOffice→Nextcloud (occ CLI). Lifecycle hooks auto-suspend on
stop and re-apply on start.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 20:06:20 +01:00

58 lines
2.0 KiB
Go

package integrations
import (
"log"
"strings"
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
)
// IntegrationKey builds the settings key: "provider:target".
func IntegrationKey(provider, target string) string {
return provider + ":" + target
}
// ParseIntegrationKey splits "provider:target" into its components.
func ParseIntegrationKey(key string) (provider, target string, ok bool) {
parts := strings.SplitN(key, ":", 2)
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", "", false
}
return parts[0], parts[1], true
}
// ApplyContext holds all context needed by an integration handler.
type ApplyContext struct {
ProviderName string // e.g., "onlyoffice"
TargetName string // e.g., "filebrowser"
Domain string // e.g., "demo-felhom.eu"
ProviderEnv map[string]string // decrypted app.yaml env of provider
ProviderMeta *stacks.Metadata
StacksDir string
Logger *log.Logger
RestartStack func(name string) error // restart via stacks.Manager
}
// Handler defines the interface for a concrete integration handler.
// Each provider:target pair has one Handler implementation.
type Handler interface {
// Apply enables the integration (writes configs, runs commands, restarts containers).
Apply(ac *ApplyContext) error
// Revoke disables the integration (removes configs, runs commands, restarts containers).
Revoke(ac *ApplyContext) error
}
// StatusInfo is returned by the API for UI display.
type StatusInfo struct {
Key string `json:"key"` // "onlyoffice:filebrowser"
Provider string `json:"provider"`
Target string `json:"target"`
Label string `json:"label"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Status string `json:"status"` // "active", "error", "disabled", "provider_stopped", "target_unavailable"
LastError string `json:"last_error,omitempty"`
TargetDeployed bool `json:"target_deployed"`
TargetRunning bool `json:"target_running"`
}