types

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package types provides common type definitions for labelgate.

Index

Constants

View Source
const (
	AccessDecisionAllow       = "allow"
	AccessDecisionBlock       = "block"
	AccessDecisionBypass      = "bypass"
	AccessDecisionServiceAuth = "service_auth"
)

AccessDecision constants matching Cloudflare Web UI action names.

View Source
const (
	// SelectorEmails maps to CF Web UI "Emails".
	SelectorEmails = "emails"
	// SelectorEmailsEndingIn maps to CF Web UI "Emails ending in".
	SelectorEmailsEndingIn = "emails_ending_in"
	// SelectorIPRanges maps to CF Web UI "IP ranges".
	SelectorIPRanges = "ip_ranges"
	// SelectorCountry maps to CF Web UI "Country".
	SelectorCountry = "country"
	// SelectorEveryone maps to CF Web UI "Everyone".
	SelectorEveryone = "everyone"
	// SelectorServiceToken maps to CF Web UI "Service Token".
	SelectorServiceToken = "service_token"
	// SelectorAccessGroups maps to CF Web UI "Access groups".
	SelectorAccessGroups = "access_groups"
	// SelectorCertificate maps to CF Web UI "Valid Certificate".
	SelectorCertificate = "certificate"
	// SelectorLoginMethods maps to CF Web UI "Login Methods".
	SelectorLoginMethods = "login_methods"
)

Access rule selector constants aligned with CF Web UI.

Variables

ValidAccessSelectors contains all valid access rule selectors.

Functions

func MapDecisionToAPI

func MapDecisionToAPI(decision string) string

MapDecisionToAPI maps label decision values to Cloudflare API decision values.

Types

type AccessPolicy

type AccessPolicy struct {
	// Decision is the CF Web UI "Action": allow, block, bypass, service_auth.
	// Mapped to CF API: allow -> "allow", block -> "deny", bypass -> "bypass",
	// service_auth -> "non_identity".
	Decision string `json:"decision"`

	// Name is the CF Web UI "Policy name".
	Name string `json:"name,omitempty"`

	// Include rules use OR logic (CF Web UI "Configure rules" > "Include").
	Include []AccessRule `json:"include,omitempty"`

	// Require rules use AND logic (CF Web UI "Configure rules" > "Require").
	Require []AccessRule `json:"require,omitempty"`

	// Exclude rules use NOT logic (CF Web UI "Configure rules" > "Exclude").
	Exclude []AccessRule `json:"exclude,omitempty"`
}

AccessPolicy corresponds to one CF Access Policy under an Application. Maps to CF Web UI: Access > Applications > [app] > Policies > [policy].

type AccessPolicyDef

type AccessPolicyDef struct {
	// Name is the policy template name (from label key, e.g., "internal", "bypass")
	Name string `json:"name"`

	// AppName is the CF "Application name" (optional, defaults to "labelgate-<name>")
	AppName string `json:"app_name,omitempty"`

	// SessionDuration is the CF "Session Duration" (default: "24h")
	SessionDuration string `json:"session_duration"`

	// Policies are the access policies to apply.
	// Phase 5.1: single policy (len=1). Phase 5.2: multiple numbered policies.
	Policies []AccessPolicy `json:"policies"`
}

AccessPolicyDef is a named, reusable access policy template parsed from labels. It has no hostname - hostname is inherited from the referencing tunnel/dns service. Multiple tunnel/dns services can reference the same policy definition.

func DefaultAccessPolicyDef

func DefaultAccessPolicyDef(name string) *AccessPolicyDef

DefaultAccessPolicyDef returns an AccessPolicyDef with default values.

type AccessRule

type AccessRule struct {
	// Selector is the CF Web UI selector name.
	Selector string `json:"selector"`

	// Values are the selector values (comma-separated in labels, split into slice).
	Values []string `json:"values"`
}

AccessRule is a single rule entry with a selector and values. Selector names are aligned with Cloudflare Web UI selector names.

type ContainerEvent

type ContainerEvent struct {
	// Type is the event type
	Type EventType `json:"type"`

	// ContainerID is the container ID
	ContainerID string `json:"container_id"`

	// ContainerName is the container name
	ContainerName string `json:"container_name"`

	// Labels are the container labels
	Labels map[string]string `json:"labels,omitempty"`

	// Timestamp is when the event occurred
	Timestamp time.Time `json:"timestamp"`

	// AgentID is the agent that reported the event (empty for local)
	AgentID string `json:"agent_id,omitempty"`
}

ContainerEvent represents a container lifecycle event.

type ContainerInfo

type ContainerInfo struct {
	// ID is the container ID
	ID string `json:"id"`

	// Name is the container name
	Name string `json:"name"`

	// Image is the container image
	Image string `json:"image"`

	// Labels are the container labels
	Labels map[string]string `json:"labels"`

	// Networks maps network name to IP address
	Networks map[string]string `json:"networks,omitempty"`

	// State is the container state (running, exited, etc.)
	State string `json:"state"`

	// Created is when the container was created
	Created time.Time `json:"created"`

	// Started is when the container was started
	Started time.Time `json:"started,omitempty"`
}

ContainerInfo represents information about a running container.

type DNSRecord

type DNSRecord struct {
	ID       string        `json:"id"`
	ZoneID   string        `json:"zone_id"`
	ZoneName string        `json:"zone_name"`
	Name     string        `json:"name"`
	Type     DNSRecordType `json:"type"`
	Content  string        `json:"content"`
	Proxied  bool          `json:"proxied"`
	TTL      int           `json:"ttl"`
	Priority int           `json:"priority,omitempty"`
	Comment  string        `json:"comment,omitempty"`
}

DNSRecord represents a DNS record in Cloudflare.

type DNSRecordType

type DNSRecordType string

DNSRecordType represents a DNS record type.

const (
	DNSTypeA     DNSRecordType = "A"
	DNSTypeAAAA  DNSRecordType = "AAAA"
	DNSTypeCNAME DNSRecordType = "CNAME"
	DNSTypeTXT   DNSRecordType = "TXT"
	DNSTypeMX    DNSRecordType = "MX"
	DNSTypeSRV   DNSRecordType = "SRV"
	DNSTypeCAA   DNSRecordType = "CAA"
)

type DNSService

type DNSService struct {
	// ServiceName is the service identifier from label
	ServiceName string `json:"service_name"`

	// Hostname is the full DNS hostname
	Hostname string `json:"hostname"`

	// Type is the DNS record type (A, AAAA, CNAME, etc.)
	Type DNSRecordType `json:"type"`

	// Target is the record target (IP, hostname, or "auto")
	Target string `json:"target"`

	// Proxied indicates if Cloudflare proxy is enabled
	Proxied bool `json:"proxied"`

	// TTL is the record TTL in seconds (0 = auto)
	TTL int `json:"ttl"`

	// Credential is the credential name to use
	Credential string `json:"credential"`

	// Cleanup indicates if record should be deleted when container stops
	Cleanup bool `json:"cleanup"`

	// Comment is an optional comment for the record
	Comment string `json:"comment,omitempty"`

	// Access is the name of the access policy template to apply (optional).
	// References a labelgate.access.<name> definition.
	Access string `json:"access,omitempty"`

	// MX specific fields
	Priority int `json:"priority,omitempty"`

	// SRV specific fields
	Weight int `json:"weight,omitempty"`
	Port   int `json:"port,omitempty"`

	// CAA specific fields
	Flags int    `json:"flags,omitempty"`
	Tag   string `json:"tag,omitempty"`
}

DNSService represents a DNS service configuration parsed from labels.

func DefaultDNSService

func DefaultDNSService() *DNSService

DefaultDNSService returns a DNSService with default values.

type DNSTarget

type DNSTarget string

DNSTarget represents the target resolution method.

const (
	// DNSTargetAuto automatically detects public IP.
	DNSTargetAuto DNSTarget = "auto"
	// DNSTargetContainer uses container IP.
	DNSTargetContainer DNSTarget = "container"
)

type EventType

type EventType string

EventType represents the type of container event.

const (
	// EventStart is emitted when a container starts.
	EventStart EventType = "start"
	// EventStop is emitted when a container stops.
	EventStop EventType = "stop"
	// EventDie is emitted when a container dies.
	EventDie EventType = "die"
	// EventDestroy is emitted when a container is destroyed.
	EventDestroy EventType = "destroy"
	// EventUpdate is emitted when container labels are updated.
	EventUpdate EventType = "update"
)

type IngressRule

type IngressRule struct {
	Hostname      string               `json:"hostname,omitempty"`
	Path          string               `json:"path,omitempty"`
	Service       string               `json:"service"`
	OriginRequest *OriginRequestConfig `json:"origin_request,omitempty"`
}

IngressRule represents a single ingress rule in tunnel configuration.

type OriginRequestConfig

type OriginRequestConfig struct {
	// Connection settings
	ConnectTimeout       string `json:"connect_timeout,omitempty"`
	TLSTimeout           string `json:"tls_timeout,omitempty"`
	TCPKeepAlive         string `json:"tcp_keepalive,omitempty"`
	KeepAliveConnections int    `json:"keep_alive_connections,omitempty"`
	KeepAliveTimeout     string `json:"keep_alive_timeout,omitempty"`

	// TLS settings
	NoTLSVerify      bool   `json:"no_tls_verify,omitempty"`
	OriginServerName string `json:"origin_server_name,omitempty"`
	CAPool           string `json:"ca_pool,omitempty"`

	// HTTP settings
	HTTPHostHeader         string `json:"http_host_header,omitempty"`
	NoHappyEyeballs        bool   `json:"no_happy_eyeballs,omitempty"`
	DisableChunkedEncoding bool   `json:"disable_chunked_encoding,omitempty"`

	// Protocol settings
	ProxyType string `json:"proxy_type,omitempty"` // "", "socks"
}

OriginRequestConfig holds origin request configuration for tunnel.

type ParsedContainer

type ParsedContainer struct {
	// Container info
	Info *ContainerInfo `json:"info"`

	// DNS services parsed from labels
	DNSServices []*DNSService `json:"dns_services,omitempty"`

	// Tunnel services parsed from labels
	TunnelServices []*TunnelService `json:"tunnel_services,omitempty"`

	// AccessPolicies are named access policy definitions from this container.
	// Key is the policy name (e.g., "internal", "bypass").
	AccessPolicies map[string]*AccessPolicyDef `json:"access_policies,omitempty"`

	// AgentID is the agent that reported this container
	AgentID string `json:"agent_id,omitempty"`
}

ParsedContainer represents a container with parsed label configurations.

type ResolvedAccessBinding

type ResolvedAccessBinding struct {
	// Hostname from the referencing tunnel/dns service
	Hostname string `json:"hostname"`

	// PolicyDef is the resolved access policy definition
	PolicyDef *AccessPolicyDef `json:"policy_def"`

	// ContainerID of the referencing tunnel/dns service
	ContainerID string `json:"container_id,omitempty"`

	// ContainerName of the referencing tunnel/dns service
	ContainerName string `json:"container_name,omitempty"`

	// ServiceName of the referencing tunnel/dns service
	ServiceName string `json:"service_name"`

	// AgentID of the agent that reported this container
	AgentID string `json:"agent_id,omitempty"`

	// Cleanup follows the tunnel/dns service's cleanup setting
	Cleanup bool `json:"cleanup"`

	// Credential for CF API calls
	Credential string `json:"credential"`
}

ResolvedAccessBinding represents a resolved access policy bound to a hostname. Created by the reconciler when resolving tunnel/dns access references.

type Tunnel

type Tunnel struct {
	ID           string           `json:"id"`
	Name         string           `json:"name"`
	AccountID    string           `json:"account_id"`
	Status       string           `json:"status"`
	RemoteConfig bool             `json:"remote_config"`
	ConnectorID  string           `json:"connector_id,omitempty"`
	IngressRules []*TunnelIngress `json:"ingress_rules,omitempty"`
}

Tunnel represents a Cloudflare Tunnel.

type TunnelConfiguration

type TunnelConfiguration struct {
	TunnelID string        `json:"tunnel_id"`
	Ingress  []IngressRule `json:"ingress"`
}

TunnelConfiguration represents a tunnel's complete configuration.

type TunnelIngress

type TunnelIngress struct {
	Hostname      string               `json:"hostname,omitempty"`
	Path          string               `json:"path,omitempty"`
	Service       string               `json:"service"`
	OriginRequest *OriginRequestConfig `json:"origin_request,omitempty"`
}

TunnelIngress represents an ingress rule in Cloudflare Tunnel.

type TunnelProtocol

type TunnelProtocol string

TunnelProtocol represents the protocol for tunnel service.

const (
	TunnelProtocolHTTP       TunnelProtocol = "http"
	TunnelProtocolHTTPS      TunnelProtocol = "https"
	TunnelProtocolSSH        TunnelProtocol = "ssh"
	TunnelProtocolRDP        TunnelProtocol = "rdp"
	TunnelProtocolTCP        TunnelProtocol = "tcp"
	TunnelProtocolUDP        TunnelProtocol = "udp"
	TunnelProtocolUnix       TunnelProtocol = "unix"
	TunnelProtocolHelloWorld TunnelProtocol = "hello_world"
	TunnelProtocolHTTPStatus TunnelProtocol = "http_status"
)

type TunnelService

type TunnelService struct {
	// ServiceName is the service identifier from label
	ServiceName string `json:"service_name"`

	// Hostname is the public hostname for the service
	Hostname string `json:"hostname"`

	// Service is the backend service URL (e.g., http://localhost:8080)
	Service string `json:"service"`

	// Tunnel is the tunnel name to use
	Tunnel string `json:"tunnel"`

	// Path is the optional path pattern for routing
	Path string `json:"path,omitempty"`

	// Credential is the credential name to use
	Credential string `json:"credential"`

	// Cleanup indicates if ingress should be deleted when container stops
	Cleanup bool `json:"cleanup"`

	// Access is the name of the access policy template to apply (optional).
	// References a labelgate.access.<name> definition.
	Access string `json:"access,omitempty"`

	// OriginRequest contains origin request configuration
	OriginRequest *OriginRequestConfig `json:"origin_request,omitempty"`
}

TunnelService represents a Tunnel service configuration parsed from labels.

func DefaultTunnelService

func DefaultTunnelService() *TunnelService

DefaultTunnelService returns a TunnelService with default values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL