config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	EnvConfig            = "RBAC_CONFIG"
	EnvPolicyKey         = "RBAC_POLICY_KEY"
	EnvPolicyKeyPrev     = "RBAC_POLICY_KEY_PREV"
	EnvCachePassword     = "RBAC_CACHE_PASSWORD"
	DefaultFileName      = "config.yaml"
	DefaultHTTPPort      = 8080
	DefaultHTTPSPort     = 8443
	DefaultGRPCPort      = 9080
	DefaultGRPCTLSPort   = 9443
	DefaultHTTPHost      = "0.0.0.0"
	DefaultAdminUser     = "admin"
	DefaultAdminPassword = "admin"
	DefaultAdminHost     = "127.0.0.1"
	DefaultAdminPort     = 9090
	DefaultLogLevel      = "info"
	DefaultLogFile       = "logs/rbac.log"
)

Variables

This section is empty.

Functions

func WatchFile

func WatchFile(path string, stop <-chan struct{}, onChange func()) error

WatchFile calls onChange after the file is created, written, or replaced.

Types

type Admin

type Admin struct {
	Enable   bool   `mapstructure:"enable"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
}

func ReadAdmin

func ReadAdmin(path string) (Admin, error)

ReadAdmin loads only the admin section. Empty username/password become admin/admin.

type CA

type CA struct {
	Dir string `mapstructure:"dir"`
}

type Cache

type Cache struct {
	Enable   bool   `mapstructure:"enable"`
	Kind     string `mapstructure:"kind"`
	Addr     string `mapstructure:"addr"`
	Password string `mapstructure:"password"`
	DB       int    `mapstructure:"db"`
}

type Config

type Config struct {
	// Path is the resolved config file (absolute when possible).
	Path string `mapstructure:"-"`
	// Origin is env, flag, or default.
	Origin Origin `mapstructure:"-"`
	Log    Log    `mapstructure:"log"`
	Policy Policy `mapstructure:"policy"`
	CA     CA     `mapstructure:"ca"`
	Cache  Cache  `mapstructure:"cache"`
	Server Server `mapstructure:"server"`
	Admin  Admin  `mapstructure:"admin"`
	// contains filtered or unexported fields
}

func Load

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

Load reads YAML via viper, then ensures policy.crypto and policy.key exist. Missing default file uses built-in defaults; RBAC_CONFIG / --config must exist.

func (*Config) AdminAddr

func (c *Config) AdminAddr() string

func (*Config) AdminEnabled

func (c *Config) AdminEnabled() bool

func (*Config) AdminHost

func (c *Config) AdminHost() string

func (*Config) AdminPassword

func (c *Config) AdminPassword() string

func (*Config) AdminPort

func (c *Config) AdminPort() int

func (*Config) AdminUsername

func (c *Config) AdminUsername() string

func (*Config) Algorithm

func (c *Config) Algorithm() (crypto.Algorithm, error)

func (*Config) CADir

func (c *Config) CADir() string

func (*Config) CacheEnabled

func (c *Config) CacheEnabled() bool

func (*Config) CachePassword

func (c *Config) CachePassword() string

func (*Config) EncryptEnabled

func (c *Config) EncryptEnabled() bool

func (*Config) GRPCAddr added in v0.1.1

func (c *Config) GRPCAddr() string

func (*Config) GRPCEnabled added in v0.1.1

func (c *Config) GRPCEnabled() bool

func (*Config) GRPCPort added in v0.1.1

func (c *Config) GRPCPort() int

func (*Config) GRPCTLSAddr added in v0.1.1

func (c *Config) GRPCTLSAddr() string

func (*Config) GRPCTLSEnabled added in v0.1.1

func (c *Config) GRPCTLSEnabled() bool

func (*Config) GRPCTLSPort added in v0.1.1

func (c *Config) GRPCTLSPort() int

func (*Config) HTTPAddr

func (c *Config) HTTPAddr() string

func (*Config) HTTPEnabled

func (c *Config) HTTPEnabled() bool

func (*Config) HTTPHost

func (c *Config) HTTPHost() string

func (*Config) HTTPPort

func (c *Config) HTTPPort() int

func (*Config) HTTPSAddr

func (c *Config) HTTPSAddr() string

func (*Config) HTTPSEnabled

func (c *Config) HTTPSEnabled() bool

func (*Config) HTTPSPort

func (c *Config) HTTPSPort() int

func (*Config) KeyBytes

func (c *Config) KeyBytes() []byte

func (*Config) LogDebug

func (c *Config) LogDebug() bool

func (*Config) LogFile

func (c *Config) LogFile() string

func (*Config) LogLevel

func (c *Config) LogLevel() string

func (*Config) PolicyPath

func (c *Config) PolicyPath() string

func (*Config) PrevKeyBytes

func (c *Config) PrevKeyBytes() []byte

type GRPCEndpoint added in v0.1.1

type GRPCEndpoint struct {
	Enable bool `mapstructure:"enable"`
	Port   int  `mapstructure:"port"`
}

GRPCEndpoint is plaintext gRPC (h2c). Host defaults to server.http.host.

type GRPCTLSEndpoint added in v0.1.1

type GRPCTLSEndpoint struct {
	Enable bool `mapstructure:"enable"`
	Port   int  `mapstructure:"port"`
}

GRPCTLSEndpoint is gRPC over TLS, reusing the HTTPS server certificate.

type HTTPEndpoint

type HTTPEndpoint struct {
	Enable bool   `mapstructure:"enable"`
	Host   string `mapstructure:"host"`
	Port   int    `mapstructure:"port"`
}

type HTTPSEndpoint

type HTTPSEndpoint struct {
	Enable bool `mapstructure:"enable"`
	Port   int  `mapstructure:"port"`
}

type Log

type Log struct {
	Level string `mapstructure:"level"`
	File  string `mapstructure:"file"`
	Debug bool   `mapstructure:"debug"`
}

Log controls structured logging output.

type Origin

type Origin string

Origin is how the config file path was chosen. Precedence: RBAC_CONFIG > --config > <cwd>/config.yaml.

const (
	OriginEnv     Origin = "env"
	OriginFlag    Origin = "flag"
	OriginDefault Origin = "default"
)

func ResolvePath

func ResolvePath(flagPath string) (path string, origin Origin)

type Policy

type Policy struct {
	Dir     string `mapstructure:"dir"`
	Encrypt *bool  `mapstructure:"encrypt"`
	Crypto  string `mapstructure:"crypto"`
	Key     string `mapstructure:"key"`
}

type Server

type Server struct {
	HTTP    HTTPEndpoint    `mapstructure:"http"`
	HTTPS   HTTPSEndpoint   `mapstructure:"https"`
	GRPC    GRPCEndpoint    `mapstructure:"grpc"`
	GRPCTLS GRPCTLSEndpoint `mapstructure:"grpc_tls"`
}

Jump to

Keyboard shortcuts

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