Documentation
¶
Overview ¶
Package cloudflare provides Cloudflare API client for labelgate.
Index ¶
- type AccessClient
- func (a *AccessClient) CheckAccessPermissions(ctx context.Context) error
- func (a *AccessClient) DeleteAccessApplication(ctx context.Context, appID string) error
- func (a *AccessClient) EnsureAccessForHostname(ctx context.Context, hostname string, policyDef *types.AccessPolicyDef, ...) (string, error)
- func (a *AccessClient) FindExistingAccessApp(ctx context.Context, hostname string) (string, string, error)
- type Client
- type Credential
- type CredentialManager
- func (cm *CredentialManager) GetClient(cred *Credential) (*Client, error)
- func (cm *CredentialManager) GetClientForHostname(hostname string, explicitCredName string) (*Client, error)
- func (cm *CredentialManager) GetCredentialForZone(hostname string, explicitCredName string) (*Credential, error)
- func (cm *CredentialManager) GetDefaultClient() (*Client, error)
- func (cm *CredentialManager) GetTunnelClient(tunnelIDOrName string) (*Client, *TunnelCredential, error)
- func (cm *CredentialManager) GetTunnelCredential(tunnelIDOrName string) (*TunnelCredential, error)
- func (cm *CredentialManager) HealthCheck(ctx context.Context) *HealthResult
- func (cm *CredentialManager) ListTunnels() []string
- func (cm *CredentialManager) Validate(ctx context.Context) error
- type DNSClient
- func (d *DNSClient) CreateRecord(ctx context.Context, record *types.DNSRecord) (*types.DNSRecord, error)
- func (d *DNSClient) DeleteRecord(ctx context.Context, zoneID, recordID string) error
- func (d *DNSClient) GetRecord(ctx context.Context, zoneID, recordID string) (*types.DNSRecord, error)
- func (d *DNSClient) GetRecordByName(ctx context.Context, hostname string, recordType types.DNSRecordType) (*types.DNSRecord, error)
- func (d *DNSClient) ListRecords(ctx context.Context, zoneID string) ([]*types.DNSRecord, error)
- func (d *DNSClient) UpdateRecord(ctx context.Context, record *types.DNSRecord) (*types.DNSRecord, error)
- type HealthResult
- type TunnelClient
- func (t *TunnelClient) AddIngressRule(ctx context.Context, tunnelID string, rule *types.TunnelIngress) error
- func (t *TunnelClient) GetTunnel(ctx context.Context, tunnelID string) (*types.Tunnel, error)
- func (t *TunnelClient) GetTunnelConfiguration(ctx context.Context, tunnelID string) (*types.TunnelConfiguration, error)
- func (t *TunnelClient) ListTunnels(ctx context.Context) ([]*types.Tunnel, error)
- func (t *TunnelClient) RemoveIngressRule(ctx context.Context, tunnelID string, hostname string) error
- func (t *TunnelClient) UpdateTunnelConfiguration(ctx context.Context, tunnelID string, ingresses []*types.TunnelIngress) error
- type TunnelCredential
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessClient ¶
type AccessClient struct {
// contains filtered or unexported fields
}
AccessClient provides Cloudflare Zero Trust Access management operations.
func NewAccessClient ¶
func NewAccessClient(client *Client, accountID string) *AccessClient
NewAccessClient creates a new Access client wrapper.
func (*AccessClient) CheckAccessPermissions ¶
func (a *AccessClient) CheckAccessPermissions(ctx context.Context) error
CheckAccessPermissions probes the Cloudflare Access API to verify the token has sufficient permissions. It does a lightweight List Applications call. Returns nil if permissions are valid, error with details otherwise.
func (*AccessClient) DeleteAccessApplication ¶
func (a *AccessClient) DeleteAccessApplication(ctx context.Context, appID string) error
DeleteAccessApplication deletes an Access Application and its linked policies.
func (*AccessClient) EnsureAccessForHostname ¶
func (a *AccessClient) EnsureAccessForHostname(ctx context.Context, hostname string, policyDef *types.AccessPolicyDef, existingAppID string) (string, error)
EnsureAccessForHostname creates or updates an Access Application + Policies for a hostname. This is the main entry point used by the Access Operator.
Flow:
- Find or create account-level reusable policies
- Create or update the Access Application, linking policies via the Policies field
- Clean up old unreferenced policies from the previous app state
func (*AccessClient) FindExistingAccessApp ¶
func (a *AccessClient) FindExistingAccessApp(ctx context.Context, hostname string) (string, string, error)
FindExistingAccessApp searches for an existing Access Application by hostname. Returns the app ID if found, empty string if not found. This is used to detect pre-existing apps not managed by labelgate.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Cloudflare API client with caching and credential management.
func (*Client) GetZoneID ¶
GetZoneID retrieves the zone ID for a given hostname. It loads and caches all available zones from the API, then performs longest-suffix matching to find the correct zone. This avoids the need to guess root domains from TLD structure.
func (*Client) InvalidateZoneCache ¶
func (c *Client) InvalidateZoneCache()
InvalidateZoneCache clears the zone cache, forcing a reload on next GetZoneID call. Useful when zones may have been added or removed from the Cloudflare account.
func (*Client) SetAccountID ¶
SetAccountID sets the account ID for tunnel operations.
type Credential ¶
type Credential struct {
Name string // Credential name for reference
APIToken string // API token
Zones []string // Zones this credential applies to
Default bool // Whether this is the default credential
}
Credential represents a Cloudflare API credential.
type CredentialManager ¶
type CredentialManager struct {
// contains filtered or unexported fields
}
CredentialManager manages multiple Cloudflare credentials.
Credentials are stored as pointer slices so that defaultCredential and any caller holding a *Credential remain valid after additional credentials are appended (a value slice would invalidate addresses on reallocation).
func NewCredentialManager ¶
func NewCredentialManager(cfg *config.Config) (*CredentialManager, error)
NewCredentialManager creates a new credential manager from config.
func (*CredentialManager) GetClient ¶
func (cm *CredentialManager) GetClient(cred *Credential) (*Client, error)
GetClient returns a cached Cloudflare client for the given credential.
func (*CredentialManager) GetClientForHostname ¶
func (cm *CredentialManager) GetClientForHostname(hostname string, explicitCredName string) (*Client, error)
GetClientForHostname returns a client suitable for operations on the given hostname.
func (*CredentialManager) GetCredentialForZone ¶
func (cm *CredentialManager) GetCredentialForZone(hostname string, explicitCredName string) (*Credential, error)
GetCredentialForZone returns the appropriate credential for a given hostname. Priority: explicit label > zone matching > default
func (*CredentialManager) GetDefaultClient ¶
func (cm *CredentialManager) GetDefaultClient() (*Client, error)
GetDefaultClient returns the default Cloudflare client.
func (*CredentialManager) GetTunnelClient ¶
func (cm *CredentialManager) GetTunnelClient(tunnelIDOrName string) (*Client, *TunnelCredential, error)
GetTunnelClient returns a client configured for tunnel operations.
func (*CredentialManager) GetTunnelCredential ¶
func (cm *CredentialManager) GetTunnelCredential(tunnelIDOrName string) (*TunnelCredential, error)
GetTunnelCredential returns the tunnel credential for a given tunnel ID or name.
func (*CredentialManager) HealthCheck ¶
func (cm *CredentialManager) HealthCheck(ctx context.Context) *HealthResult
HealthCheck returns a cached health check result for the Cloudflare API. Results are cached for 30 seconds to avoid excessive API calls.
func (*CredentialManager) ListTunnels ¶
func (cm *CredentialManager) ListTunnels() []string
ListTunnels returns all tunnel names.
type DNSClient ¶
type DNSClient struct {
// contains filtered or unexported fields
}
DNSClient provides DNS record management operations.
func NewDNSClient ¶
NewDNSClient creates a new DNS client wrapper.
func (*DNSClient) CreateRecord ¶
func (d *DNSClient) CreateRecord(ctx context.Context, record *types.DNSRecord) (*types.DNSRecord, error)
CreateRecord creates a new DNS record.
func (*DNSClient) DeleteRecord ¶
DeleteRecord deletes a DNS record.
func (*DNSClient) GetRecord ¶
func (d *DNSClient) GetRecord(ctx context.Context, zoneID, recordID string) (*types.DNSRecord, error)
GetRecord retrieves a DNS record by ID.
func (*DNSClient) GetRecordByName ¶
func (d *DNSClient) GetRecordByName(ctx context.Context, hostname string, recordType types.DNSRecordType) (*types.DNSRecord, error)
GetRecordByName retrieves a DNS record by hostname and type.
func (*DNSClient) ListRecords ¶
ListRecords lists DNS records for a zone.
type HealthResult ¶
HealthResult holds the result of a Cloudflare API health check.
type TunnelClient ¶
type TunnelClient struct {
// contains filtered or unexported fields
}
TunnelClient provides Cloudflare Tunnel management operations.
func NewTunnelClient ¶
func NewTunnelClient(client *Client, accountID string) *TunnelClient
NewTunnelClient creates a new Tunnel client wrapper.
func (*TunnelClient) AddIngressRule ¶
func (t *TunnelClient) AddIngressRule(ctx context.Context, tunnelID string, rule *types.TunnelIngress) error
AddIngressRule adds an ingress rule to the tunnel configuration.
func (*TunnelClient) GetTunnelConfiguration ¶
func (t *TunnelClient) GetTunnelConfiguration(ctx context.Context, tunnelID string) (*types.TunnelConfiguration, error)
GetTunnelConfiguration retrieves the ingress configuration for a tunnel.
func (*TunnelClient) ListTunnels ¶
ListTunnels lists all tunnels for the account.
func (*TunnelClient) RemoveIngressRule ¶
func (t *TunnelClient) RemoveIngressRule(ctx context.Context, tunnelID string, hostname string) error
RemoveIngressRule removes an ingress rule from the tunnel configuration.
func (*TunnelClient) UpdateTunnelConfiguration ¶
func (t *TunnelClient) UpdateTunnelConfiguration(ctx context.Context, tunnelID string, ingresses []*types.TunnelIngress) error
UpdateTunnelConfiguration updates the entire ingress configuration for a tunnel.