remote

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client fetches tokens from a remote config server and syncs them into a local TokenStore.

func NewClient

func NewClient(baseURL, apiKey string, httpClient *http.Client) *Client

NewClient creates a remote config client.

func (*Client) FetchTokens

func (c *Client) FetchTokens() ([]TokenResponse, error)

FetchTokens retrieves all tokens from the remote server.

func (*Client) RegisterWebhook added in v0.1.1

func (c *Client) RegisterWebhook(reg ClientRegistration) (string, error)

RegisterWebhook registers this client's webhook endpoint with the central config server so the server will push token events to this proxy. Returns the registration ID on success.

func (*Client) StartPeriodicSync

func (c *Client) StartPeriodicSync(localStore store.TokenStore, interval time.Duration)

StartPeriodicSync runs SyncTo on the given interval in a background goroutine. Call Stop() to cancel.

func (*Client) Stop

func (c *Client) Stop()

Stop cancels periodic sync.

func (*Client) SyncTo

func (c *Client) SyncTo(localStore store.TokenStore) (int, error)

SyncTo fetches tokens from the remote server and writes them into the local store. Existing tokens with the same hash are updated. Tokens present locally but missing from the remote are left untouched (additive sync). Returns the number of tokens synced.

func (*Client) UnregisterWebhook added in v0.1.1

func (c *Client) UnregisterWebhook(clientID string) error

UnregisterWebhook removes a previously registered webhook client from the central config server.

type ClientRegistration added in v0.1.1

type ClientRegistration struct {
	ID         string   `json:"id"`
	URL        string   `json:"url"`                   // Client's webhook endpoint URL
	Secret     string   `json:"secret,omitempty"`      // Shared secret for X-Webhook-Secret header
	SigningKey string   `json:"signing_key,omitempty"` // HMAC-SHA256 key for X-Webhook-Signature header
	Events     []string `json:"events,omitempty"`      // Event type filter (supports trailing * wildcard); empty = all
	Insecure   bool     `json:"insecure,omitempty"`    // Skip TLS certificate verification (for self-signed certs)
	CreatedAt  string   `json:"created_at"`
}

ClientRegistration represents a registered webhook client that receives push-based configuration updates from the central server.

type ClientRegistry added in v0.1.1

type ClientRegistry struct {
	// contains filtered or unexported fields
}

ClientRegistry manages webhook client registrations in BoltDB and delivers events to all registered clients. It implements the events.Emitter interface.

func NewClientRegistry added in v0.1.1

func NewClientRegistry(dbPath string) (*ClientRegistry, error)

NewClientRegistry opens a BoltDB file for client registrations and initializes emitters for all existing registrations.

func (*ClientRegistry) Close added in v0.1.1

func (cr *ClientRegistry) Close() error

Close stops all emitters and closes the BoltDB. Implements the events.Emitter interface.

func (*ClientRegistry) Emit added in v0.1.1

func (cr *ClientRegistry) Emit(ctx context.Context, event events.Event) error

Emit delivers an event to all registered webhook clients. Implements the events.Emitter interface.

func (*ClientRegistry) Get added in v0.1.1

Get retrieves a single client registration by ID.

func (*ClientRegistry) List added in v0.1.1

func (cr *ClientRegistry) List() ([]ClientRegistration, error)

List returns all registered webhook clients.

func (*ClientRegistry) Register added in v0.1.1

Register adds a new webhook client and starts its emitter.

func (*ClientRegistry) Unregister added in v0.1.1

func (cr *ClientRegistry) Unregister(id string) error

Unregister removes a webhook client and stops its emitter.

type HTTPError

type HTTPError struct {
	StatusCode int
}

HTTPError represents a non-200 response from the remote server.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a lightweight HTTP server that serves tokens and config to remote proxy instances. It wraps a TokenStore and exposes read-only endpoints for syncing. Optionally manages webhook client registrations via a ClientRegistry.

func NewServer

func NewServer(tokenStore store.TokenStore, apiKey string, registry ...*ClientRegistry) *Server

NewServer creates a remote config server backed by the given token store. If apiKey is non-empty, requests must include it as a Bearer token. If registry is non-nil, client registration endpoints are enabled.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type TokenResponse

type TokenResponse struct {
	TokenHash string `json:"token_hash"`
	Policy    string `json:"policy"`
	CreatedAt string `json:"created_at"`
	ExpiresAt string `json:"expires_at,omitempty"`
}

TokenResponse is the JSON shape for a single token in the API.

type WebhookReceiver

type WebhookReceiver struct {
	// contains filtered or unexported fields
}

WebhookReceiver handles inbound webhook events from the central config server and triggers token sync on the local proxy. This provides push-based sync as an alternative (or complement) to polling.

func NewWebhookReceiver

func NewWebhookReceiver(cfg config.WebhookReceiver, tokenStore store.TokenStore, client *Client) *WebhookReceiver

NewWebhookReceiver creates a handler that accepts inbound webhook events and triggers store reload or remote sync.

If client is non-nil, receiving a token event triggers a full remote sync (fetching all tokens from the central server). If client is nil, the handler calls store.Reload() to refresh from the local database.

func (*WebhookReceiver) Path

func (wr *WebhookReceiver) Path() string

Path returns the URL path the receiver should be mounted on.

func (*WebhookReceiver) ServeHTTP

func (wr *WebhookReceiver) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles inbound webhook POST requests.

Jump to

Keyboard shortcuts

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