Skip to content

Commit

Permalink
Update Config interface
Browse files Browse the repository at this point in the history
 # Please enter the commit message for your changes. Lines starting
  • Loading branch information
cybergarage committed Dec 23, 2024
1 parent cca448d commit e437650
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 68 deletions.
50 changes: 25 additions & 25 deletions redis/config_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ const (
tlsCACertFile = "tls-ca-cert-file"
)

// ServerConfig is a configuration for the Redis server.
type ServerConfig struct {
// serverConfig is a configuration for the Redis server.
type serverConfig struct {
*configMap
ServerCert []byte
ServerKey []byte
CACerts []byte
TLSConfig *tls.Config
}

// NewDefaultServerConfig returns a default server configuration.
func NewDefaultServerConfig() *ServerConfig {
return &ServerConfig{
// newDefaultServerConfig returns a default server configuration.
func newDefaultServerConfig() *serverConfig {
return &serverConfig{
configMap: newConfig(),
ServerCert: nil,
ServerKey: nil,
Expand All @@ -50,12 +50,12 @@ func NewDefaultServerConfig() *ServerConfig {
}

// SetPort sets a listen port number.
func (cfg *ServerConfig) SetPort(port int) {
func (cfg *serverConfig) SetPort(port int) {
cfg.SetConfig(portConfig, strconv.Itoa(port))
}

// ConfigPort returns a listen port number.
func (cfg *ServerConfig) ConfigPort() int {
func (cfg *serverConfig) ConfigPort() int {
port, ok := cfg.ConfigInteger(portConfig)
if !ok {
return DefaultTLSPort
Expand All @@ -64,7 +64,7 @@ func (cfg *ServerConfig) ConfigPort() int {
}

// IsPortEnabled returns true if a listen port is enabled.
func (cfg *ServerConfig) IsPortEnabled() bool {
func (cfg *serverConfig) IsPortEnabled() bool {
port, ok := cfg.ConfigInteger(portConfig)
if !ok {
return false
Expand All @@ -73,12 +73,12 @@ func (cfg *ServerConfig) IsPortEnabled() bool {
}

// SetTLSPort sets a listen port number for TLS.
func (cfg *ServerConfig) SetTLSPort(port int) {
func (cfg *serverConfig) SetTLSPort(port int) {
cfg.SetConfig(tlsPortConfig, strconv.Itoa(port))
}

// ConfigTLSPort returns a listen port number for TLS.
func (cfg *ServerConfig) ConfigTLSPort() int {
func (cfg *serverConfig) ConfigTLSPort() int {
port, ok := cfg.ConfigInteger(tlsPortConfig)
if !ok {
return DefaultTLSPort
Expand All @@ -87,7 +87,7 @@ func (cfg *ServerConfig) ConfigTLSPort() int {
}

// IsTLSPortEnabled returns true if a listen port for TLS is enabled.
func (cfg *ServerConfig) IsTLSPortEnabled() bool {
func (cfg *serverConfig) IsTLSPortEnabled() bool {
port, ok := cfg.ConfigInteger(tlsPortConfig)
if !ok {
return false
Expand All @@ -96,7 +96,7 @@ func (cfg *ServerConfig) IsTLSPortEnabled() bool {
}

// SetTLSCertFile sets a certificate file.
func (cfg *ServerConfig) SetTLSCertFile(certFile string) error {
func (cfg *serverConfig) SetTLSCertFile(certFile string) error {
cert, err := os.ReadFile(certFile)
if err != nil {
return err
Expand All @@ -107,20 +107,20 @@ func (cfg *ServerConfig) SetTLSCertFile(certFile string) error {
}

// ConfigTLSCertFile returns a certificate file.
func (cfg *ServerConfig) ConfigTLSCertFile() (string, bool) {
func (cfg *serverConfig) ConfigTLSCertFile() (string, bool) {
return cfg.ConfigString(tlsCertFile)
}

// ConfigTLSCert returns a certificate.
func (cfg *ServerConfig) ConfigTLSCert() ([]byte, bool) {
func (cfg *serverConfig) ConfigTLSCert() ([]byte, bool) {
if cfg.ServerCert == nil {
return nil, false
}
return cfg.ServerCert, true
}

// SetTLSKeyFile sets a key file.
func (cfg *ServerConfig) SetTLSKeyFile(keyFile string) error {
func (cfg *serverConfig) SetTLSKeyFile(keyFile string) error {
key, err := os.ReadFile(keyFile)
if err != nil {
return err
Expand All @@ -131,20 +131,20 @@ func (cfg *ServerConfig) SetTLSKeyFile(keyFile string) error {
}

// ConfigTLSKeyFile returns a key file.
func (cfg *ServerConfig) ConfigTLSKeyFile() (string, bool) {
func (cfg *serverConfig) ConfigTLSKeyFile() (string, bool) {
return cfg.ConfigString(tlsKeyFile)
}

// ConfigTLSKey returns a key.
func (cfg *ServerConfig) ConfigTLSKey() ([]byte, bool) {
func (cfg *serverConfig) ConfigTLSKey() ([]byte, bool) {
if cfg.ServerKey == nil {
return nil, false
}
return cfg.ServerKey, true
}

// SetTLSCaCertFile sets a CA certificate file.
func (cfg *ServerConfig) SetTLSCaCertFile(caCertFile string) error {
func (cfg *serverConfig) SetTLSCaCertFile(caCertFile string) error {
rootCert, err := os.ReadFile(caCertFile)
if err != nil {
return err
Expand All @@ -155,42 +155,42 @@ func (cfg *ServerConfig) SetTLSCaCertFile(caCertFile string) error {
}

// ConfigTLSCACertFile returns a CA certificate file.
func (cfg *ServerConfig) ConfigTLSCACertFile() (string, bool) {
func (cfg *serverConfig) ConfigTLSCACertFile() (string, bool) {
return cfg.ConfigString(tlsCACertFile)
}

// ConfigTLSCACert returns a CA certificate.
func (cfg *ServerConfig) ConfigTLSCACert() ([]byte, bool) {
func (cfg *serverConfig) ConfigTLSCACert() ([]byte, bool) {
if cfg.CACerts == nil {
return nil, false
}
return cfg.CACerts, true
}

// SetTLSConfig sets a TLS configuration.
func (cfg *ServerConfig) SetTLSConfig(tlsConfig *tls.Config) {
func (cfg *serverConfig) SetTLSConfig(tlsConfig *tls.Config) {
cfg.TLSConfig = tlsConfig
}

// ConfigTLSConfig returns a TLS configuration.
func (cfg *ServerConfig) ConfigTLSConfig() (*tls.Config, bool) {
func (cfg *serverConfig) ConfigTLSConfig() (*tls.Config, bool) {
if cfg.TLSConfig == nil {
return nil, false
}
return cfg.TLSConfig, true
}

// SetRequirePass sets a password.
func (cfg *ServerConfig) SetRequirePass(password string) {
func (cfg *serverConfig) SetRequirePass(password string) {
cfg.SetConfig(requirePass, password)
}

// ConfigRequirePass returns a password.
func (cfg *ServerConfig) ConfigRequirePass() (string, bool) {
func (cfg *serverConfig) ConfigRequirePass() (string, bool) {
return cfg.ConfigString(requirePass)
}

// RemoveRequirePass removes a password.
func (cfg *ServerConfig) RemoveRequirePass() {
func (cfg *serverConfig) RemoveRequirePass() {
cfg.RemoveConfig(requirePass)
}
8 changes: 4 additions & 4 deletions redis/server_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

type server struct {
*ServerConfig
*serverConfig
*auth.AuthManager
*ConnManager
tracer.Tracer
Expand All @@ -45,7 +45,7 @@ type server struct {
// NewServer returns a new server instance.
func NewServer() Server {
server := &server{
ServerConfig: NewDefaultServerConfig(),
serverConfig: newDefaultServerConfig(),
AuthManager: auth.NewAuthManager(),
ConnManager: NewConnManager(),
Tracer: tracer.NullTracer,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (server *server) SetTracer(t tracer.Tracer) {

// Config returns the server configuration.
func (server *server) Config() Config {
return server.ServerConfig
return server.serverConfig
}

// SetAuthCommandHandler sets a auth handler to handle auth commands.
Expand Down Expand Up @@ -170,7 +170,7 @@ func (server *server) open() error {
if ok {
server.tlsConfig = tlsConfig
} else {
tlsConfig, err := NewTLSConfigFrom(server.ServerConfig)
tlsConfig, err := NewTLSConfigFrom(server.serverConfig)
if err != nil {
return err
}
Expand Down
39 changes: 0 additions & 39 deletions redistest/certs/certs_test.go

This file was deleted.

0 comments on commit e437650

Please sign in to comment.