Newer
Older
EnvoyControlPlane / internal / api / types.go
package internal

import (
	resourcev3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
)

// --- xDS Resource Management Requests (CRUD) ---

// AddClusterRequest defines the payload to add or update an Envoy Cluster resource.
type AddClusterRequest struct {
	Name string `json:"name"` // The name of the Cluster resource.
	YAML string `json:"yaml"` // The YAML/JSON string containing the Envoy Cluster configuration.
	// If true, performs an 'upsert' (update if exists, insert if new).
	Upsert bool `json:"upsert"`
}

// AddListenerRequest defines the payload to add or update an Envoy Listener resource.
type AddListenerRequest struct {
	Name string `json:"name"` // The name of the Listener resource.
	YAML string `json:"yaml"` // The YAML/JSON string containing the Envoy Listener configuration.
	// If true, performs an 'upsert' (update if exists, insert if new).
	Upsert bool `json:"upsert"`
}

// AddSecretRequest defines the payload to add or update an Envoy Secret resource.
type AddSecretRequest struct {
	Name string `json:"name"` // The name of the Secret resource.
	YAML string `json:"yaml"` // The YAML/JSON string containing the Envoy Secret configuration.
	// If true, performs an 'upsert' (update if exists, insert if new).
	Upsert bool `json:"upsert"`
}

// AddExtensionConfigRequest defines the payload to add or update an Envoy TypedExtensionConfig resource.
// This is typically used for shared configuration like Lua filters.
type AddExtensionConfigRequest struct {
	Name string `json:"name"` // The name of the ExtensionConfig resource.
	YAML string `json:"yaml"` // The YAML/JSON string containing the TypedExtensionConfig configuration.
	// If true, performs an 'upsert' (update if exists, insert if new).
	Upsert bool `json:"upsert"`
}

// EnableResourceRequest defines a generic payload to enable a disabled resource (Cluster, Listener, etc.).
type EnableResourceRequest struct {
	Name string `json:"name"` // The name of the resource to enable.
}

// RemoveResourceRequest defines a generic payload to remove a resource (Cluster, Listener, etc.).
type RemoveResourceRequest struct {
	Name string `json:"name"` // The name of the resource to remove.
}

// NOTE: RemoveClusterRequest and RemoveListenerRequest are redundant with RemoveResourceRequest
// but can be kept for specific API handler routing/type safety if needed.
// RemoveClusterRequest defines payload to remove a cluster.
type RemoveClusterRequest struct {
	Name string `json:"name"`
}

// RemoveListenerRequest defines payload to remove a listener.
type RemoveListenerRequest struct {
	Name string `json:"name"`
}

// --- Listener Filter Chain Requests ---

// AppendFilterChainRequest defines payload to append a new filter chain to a given listener.
type AppendFilterChainRequest struct {
	ListenerName string `json:"listener_name"` // The name of the Listener to modify.
	YAML         string `json:"yaml"`          // The YAML/JSON string of the new FilterChain configuration.
	Upsert       bool   `json:"upsert"`        // If true, replaces an existing filter chain with matching domains.
}

// UpdateFilterChainRequest defines payload to update an existing filter chain on a given listener.
type UpdateFilterChainRequest struct {
	ListenerName string `json:"listener_name"` // The name of the Listener to modify.
	YAML         string `json:"yaml"`          // The YAML/JSON string containing the *updated* FilterChain configuration.
}

// RemoveFilterChainRequest defines payload to remove a filter chain from a given listener.
type RemoveFilterChainRequest struct {
	ListenerName string   `json:"listener_name"` // The name of the Listener to modify.
	Domains      []string `json:"domains"`       // The domain list used to match and identify the filter chain to remove.
}

// --- Persistence & Utility Requests/Responses ---

// SnapshotFileRequest defines payload to load/save the snapshot from/to a file path.
type SnapshotFileRequest struct {
	Path string `json:"path"` // The file path for snapshot operation.
}

// ConsistencyReport holds the results of the cache/DB consistency check.
type ConsistencyReport struct {
	// Resources present in cache but not enabled in DB. Keyed by resource type.
	CacheOnly map[resourcev3.Type][]string `json:"cache-only"`
	// Resources enabled in DB but not present in cache. Keyed by resource type.
	DBOnly map[resourcev3.Type][]string `json:"db-only"`
	// True if any inconsistency was found (CacheOnly or DBOnly non-empty).
	Inconsistent bool `json:"inconsistent"`
}

// --- Certificate Management Requests/Responses ---

// RequestDomainCertificate defines the payload to issue a new certificate for a domain.
type RequestDomainCertificate struct {
	Domain     string `json:"domain"`      // The domain name for which to issue the certificate.
	Email      string `json:"email"`       // The email address for the ACME registration.
	Issuer     string `json:"issuer"`      // The ACME issuer (e.g., "letsencrypt").
	SecretName string `json:"secret_name"` // The name of the Envoy Secret to store the certificate in.
}

// RenewCertificateRequest defines the payload to manually renew an existing certificate.
type RenewCertificateRequest struct {
	Domain     string `json:"domain"`      // The domain name associated with the certificate.
	SecretName string `json:"secret_name"` // The name of the Envoy Secret holding the certificate.
}

// ParseCertificateRequest defines the payload to parse a PEM-encoded certificate.
type ParseCertificateRequest struct {
	CertificatePEM string `json:"certificate_pem"` // The certificate contents in PEM format.
}

// CheckCertificateValidityRequest defines the payload to check the validity of a PEM-encoded certificate.
type CheckCertificateValidityRequest struct {
	CertificatePEM string `json:"certificate_pem"` // The certificate contents in PEM format.
}

// EnableCertificateRotationRequest defines the payload to enable automated certificate rotation.
type EnableCertificateRotationRequest struct {
	Domain     string `json:"domain"`      // The domain name associated with the certificate.
	SecretName string `json:"secret_name"` // The name of the Envoy Secret to monitor.
	// Optional: Duration before expiration to trigger rotation (e.g., "168h" for 7 days).
	RenewBefore string `json:"renew_before,omitempty"`
}

// DisableCertificateRotationRequest defines the payload to disable automated certificate rotation.
type DisableCertificateRotationRequest struct {
	Domain     string `json:"domain"`      // The domain name associated with the certificate.
	SecretName string `json:"secret_name"` // The name of the Envoy Secret to stop monitoring.
}

// ListRotatingCertificatesRequest is a placeholder for listing rotating certificates (currently has no fields).
type ListRotatingCertificatesRequest struct{}

// ListRotatingCertificatesResponse defines the list of certificates currently set for rotation.
type ListRotatingCertificatesResponse struct {
	Certificates []RotatingCertificateInfo `json:"certificates"` // The list of rotating certificate details.
}

// RotatingCertificateInfo holds details about a certificate tracked for rotation.
type RotatingCertificateInfo struct {
	Domain          string `json:"domain"`           // The domain name.
	SecretName      string `json:"secret_name"`      // The name of the Secret resource.
	ExpiresAt       string `json:"expires_at"`       // The expiration date/time of the current certificate.
	RenewBefore     string `json:"renew_before"`     // The duration before expiration the renewal is triggered.
	RotationEnabled bool   `json:"rotation_enabled"` // Whether automated rotation is currently enabled.
}