You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

63 lines
1.4 KiB

package cmd
import (
"io/ioutil"
"os"
"github.com/hashicorp/hcl"
"maze.io/gate/pkg/core"
"maze.io/gate/pkg/core/identity"
"maze.io/gate/pkg/core/logger"
"maze.io/gate/pkg/net/secureshell"
"maze.io/gate/pkg/net/web"
)
// Config is the top configuration structure.
type Config struct {
SecureShell *secureshell.Server `hcl:"sshd"`
Web *web.Server `hcl:"httpd"`
Log logger.Config `hcl:"log"`
Identity *identity.Config `hcl:"identity"`
}
func LoadConfig(name string) (*Config, error) {
configData, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
}
config := &Config{
//SecureShell: &secureshell.DefaultServer,
//Web: &web.DefaultServer,
Log: logger.DefaultConfig,
}
if err = hcl.Unmarshal(configData, config); err != nil {
return nil, err
}
return config, nil
}
// Logger returns a configured Logger.
func (config *Config) Logger() *logger.Logger {
log := logger.New(os.Stdout)
log.Configure(config.Log)
logger.Default = log
return log
}
func (config *Config) IdentityProvider() (core.IdentityProvider, error) {
return config.Identity.Provider()
}
// Services returns all configured services.
func (config *Config) Services() (httpd *web.Server, services []core.Service) {
if config.SecureShell != nil {
services = append(services, config.SecureShell)
}
if config.Web != nil {
httpd = config.Web
services = append(services, config.Web)
}
return
}