reenable config ini
This commit is contained in:
parent
e541eb6298
commit
c2d67f63fa
2 changed files with 29 additions and 20 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
|
|
@ -43,17 +43,23 @@ func main() {
|
|||
return nil
|
||||
})
|
||||
|
||||
dumpConfig := func(){
|
||||
dumpConfig := func() {
|
||||
ini := flags.NewIniParser(parser)
|
||||
ini.Write(os.Stdout, flags.IniIncludeDefaults)
|
||||
}
|
||||
}
|
||||
|
||||
// dumpini
|
||||
addSubCommand(parser, "dumpconfig", "dump current config ini to stdout", func(args []string) error {
|
||||
dumpConfig()
|
||||
return nil
|
||||
})
|
||||
|
||||
config := &piperdConfig{}
|
||||
config := &struct {
|
||||
piperdConfig
|
||||
|
||||
Logfile string `long:"log" description:"Logfile path. Leave empty or any error occurs will fall back to stdout" env:"SSHPIPERD_LOG_PATH" ini-name:"log-path"`
|
||||
ConfigFile flags.Filename `long:"config" description:"Config file path. Higher priority than arg options and environment variables" default:"/etc/sshpiperd.ini" no-ini:"true"`
|
||||
}{}
|
||||
addOpt(parser, "sshpiperd", config)
|
||||
|
||||
// registry upstream
|
||||
|
|
@ -81,19 +87,28 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
// TODO
|
||||
// load from ini
|
||||
//ini := flags.NewIniParser(parser)
|
||||
//err = ini.ParseFile(globalConfig.Config)
|
||||
o := parser.FindOptionByLongName("config")
|
||||
ini := flags.NewIniParser(parser)
|
||||
err := ini.ParseFile(string(config.ConfigFile))
|
||||
|
||||
//fmt.Println(err)
|
||||
if err != nil {
|
||||
// set by user or
|
||||
if !o.IsSetDefault() {
|
||||
fmt.Printf("load config file %v failed %v", config.ConfigFile, err)
|
||||
fmt.Println()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// init log
|
||||
initLogger(config.Logfile)
|
||||
|
||||
// start to serve
|
||||
if parser.Active == nil {
|
||||
showVersion()
|
||||
dumpConfig()
|
||||
|
||||
startPiper(config)
|
||||
showVersion()
|
||||
dumpConfig()
|
||||
|
||||
startPiper(&config.piperdConfig)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,9 @@ import (
|
|||
)
|
||||
|
||||
type piperdConfig struct {
|
||||
Config string `long:"config" description:"Config file path. Higher priority than arg options and environment variables" default:"/etc/sshpiperd.ini" no-ini:"true"`
|
||||
|
||||
ListenAddr string `short:"l" long:"listen" description:"Listening Address" default:"0.0.0.0" env:"SSHPIPERD_LISTENADDR" ini-name:"listen-address"`
|
||||
Port uint `short:"p" long:"port" description:"Listening Port" default:"2222" env:"SSHPIPERD_PORT" ini-name:"listen-port"`
|
||||
PiperKeyFile string `short:"i" long:"server-key" description:"Server key file for SSH Piper" default:"/etc/ssh/ssh_host_rsa_key" env:"SSHPIPERD_SERVER_KEY" ini-name:"server-key"`
|
||||
Logfile string `long:"log" description:"Logfile path. Leave empty or any error occurs will fall back to stdout" env:"SSHPIPERD_LOG_PATH" ini-name:"log-path"`
|
||||
|
||||
UpstreamDriver string `short:"d" long:"upstream-driver" description:"Upstream provider driver" default:"workingdir" env:"SSHPIPERD_UPSTREAM_DRIVER"`
|
||||
ChallengerDriver string `short:"c" long:"challenger-driver" description:"Additional challenger name, e.g. pam, empty for no additional challenge" env:"SSHPIPERD_CHALLENGER"`
|
||||
|
|
@ -25,10 +22,7 @@ type piperdConfig struct {
|
|||
|
||||
func startPiper(config *piperdConfig) {
|
||||
|
||||
// init log
|
||||
initLogger(config.Logfile)
|
||||
|
||||
logger.Println("sshpiper is about to start")
|
||||
logger.Println("sshpiper is about to start")
|
||||
|
||||
// init upstream
|
||||
upstream := upstream.Get(config.UpstreamDriver)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue