authmgr

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NATS      NATSConfig       `yaml:"nats"`
	Storage   StorageConfig    `yaml:"storage"`
	Logging   config.LogConfig `yaml:"logging"`
	Metrics   MetricsConfig    `yaml:"metrics"`
	Providers []ProviderConfig `yaml:"providers"`
}

func Load

func Load(configPath string) (*Config, error)

type Manager

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

Manager orchestrates authentication providers and token storage

func NewManager

func NewManager(nats *NATSClient, providerList []providers.Provider, log *slog.Logger, metrics *Metrics) *Manager

NewManager creates a new authentication manager

func (*Manager) Start

func (m *Manager) Start() error

Start begins the refresh loops for all providers

func (*Manager) Stop

func (m *Manager) Stop() error

Stop gracefully shuts down all refresh loops

type Metrics

type Metrics struct {
	AuthSuccessTotal     *prometheus.CounterVec
	AuthFailuresTotal    *prometheus.CounterVec
	AuthDuration         *prometheus.HistogramVec
	KVStoreFailuresTotal *prometheus.CounterVec
}

Metrics provides centralized metrics collection for the nats-auth-manager.

func NewMetrics

func NewMetrics(reg prometheus.Registerer) (*Metrics, error)

NewMetrics creates a new metrics instance and registers the collectors.

func (*Metrics) IncAuthFailure

func (m *Metrics) IncAuthFailure(providerID string)

IncAuthFailure increments the counter for failed authentications.

func (*Metrics) IncAuthSuccess

func (m *Metrics) IncAuthSuccess(providerID string)

IncAuthSuccess increments the counter for successful authentications.

func (*Metrics) IncKVStoreFailure

func (m *Metrics) IncKVStoreFailure(providerID string)

IncKVStoreFailure increments the counter for KV store failures.

func (*Metrics) ObserveAuthDuration

func (m *Metrics) ObserveAuthDuration(providerID string, seconds float64)

ObserveAuthDuration records the duration of an authentication attempt.

type MetricsConfig

type MetricsConfig struct {
	Enabled bool   `yaml:"enabled"`
	Address string `yaml:"address"`
}

type NATSClient

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

NATSClient provides minimal NATS KV write functionality No subscriptions, no consumers, no streams - just connect and write to KV bucket

func NewNATSClient

func NewNATSClient(cfg *NATSConfig, storageConfig *StorageConfig, log *slog.Logger) (*NATSClient, error)

NewNATSClient creates a NATS client and opens KV bucket

func NewNATSClientFromConn

func NewNATSClientFromConn(nc *nats.Conn, storageConfig *StorageConfig, log *slog.Logger) (*NATSClient, error)

NewNATSClientFromConn creates a NATSClient that reuses an existing NATS connection. Used when the auth-manager runs as a subsystem of shunt.

func (*NATSClient) Close

func (c *NATSClient) Close() error

Close gracefully closes the NATS connection. When using a shared connection, it skips draining since the owner manages the connection.

func (*NATSClient) StoreToken

func (c *NATSClient) StoreToken(ctx context.Context, key, token string) error

StoreToken writes a token to the KV bucket, applying keyPrefix if configured.

type NATSConfig

type NATSConfig struct {
	URLs      []string `yaml:"urls"`
	Username  string   `yaml:"username"`
	Password  string   `yaml:"password"`
	Token     string   `yaml:"token"`
	NKey      string   `yaml:"nkey"`
	CredsFile string   `yaml:"credsFile"`

	TLS struct {
		Enable   bool   `yaml:"enable"`
		CertFile string `yaml:"certFile"`
		KeyFile  string `yaml:"keyFile"`
		CAFile   string `yaml:"caFile"`
		Insecure bool   `yaml:"insecure"`
	} `yaml:"tls"`
}

type ProviderConfig

type ProviderConfig struct {
	ID            string `yaml:"id"`
	Type          string `yaml:"type"`
	KVKey         string `yaml:"kvKey"`
	RefreshBefore string `yaml:"refreshBefore"`
	RefreshEvery  string `yaml:"refreshEvery"`

	TokenURL     string   `yaml:"tokenUrl"`
	ClientID     string   `yaml:"clientId"`
	ClientSecret string   `yaml:"clientSecret"`
	Scopes       []string `yaml:"scopes"`

	AuthURL   string            `yaml:"authUrl"`
	Method    string            `yaml:"method"`
	Headers   map[string]string `yaml:"headers"`
	Body      string            `yaml:"body"`
	TokenPath string            `yaml:"tokenPath"`
}

type StorageConfig

type StorageConfig struct {
	Bucket        string `yaml:"bucket"`
	KeyPrefix     string `yaml:"keyPrefix"`
	AutoProvision bool   `yaml:"-"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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