219 lines
7.4 KiB
Go
219 lines
7.4 KiB
Go
package bottinagenda
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/pflag"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
const (
|
|
defaultClientAPIHost = "localhost"
|
|
defaultClientAPIKey = ""
|
|
defaultClientAPIPort = 1313
|
|
defaultClientAPITLSEnabled = false
|
|
defaultClientAPITLSSkipVerify = false
|
|
defaultClientOutputstyle = "json"
|
|
|
|
defaultServerAPIBottinHost = "bottin_api"
|
|
defaultServerAPIBottinKey = "bottin"
|
|
defaultServerAPIBottinPort = 1312
|
|
defaultServerAPIBottinTLSEnabled = false
|
|
defaultServerAPIBottinTLSSkipVerify = false
|
|
defaultServerAPIHost = "api"
|
|
defaultServerAPIKey = "bottinagenda"
|
|
defaultServerAPIPort = 1313
|
|
defaultServerAPIPostgresDatabase = "bottinagenda"
|
|
defaultServerAPIPostgresHost = "db"
|
|
defaultServerAPIPostgresPassword = "bottinagenda"
|
|
defaultServerAPIPostgresPort = 5432
|
|
defaultServerAPIPostgresSSLMode = "prefer"
|
|
defaultServerAPIPostgresUser = "bottinagenda"
|
|
defaultServerAPITLSCertFile = "/etc/bottinagenda/cert.pem"
|
|
defaultServerAPITLSEnabled = false
|
|
defaultServerAPITLSKeyFile = "/etc/bottinagenda/key.pem"
|
|
|
|
defaultServerUIPort = 2313
|
|
)
|
|
|
|
func BindClientFlags(set *pflag.FlagSet) error {
|
|
if set == nil {
|
|
return fmt.Errorf("cannot bind client flags on nil flagSet")
|
|
}
|
|
|
|
set.String("client-api-host", defaultClientAPIHost, "Remote API server host")
|
|
if err := viper.BindPFlag("Client.API.Host", set.Lookup("client-api-host")); err != nil {
|
|
return err
|
|
}
|
|
|
|
set.String("client-api-key", defaultClientAPIKey, "Remote API server key")
|
|
if err := viper.BindPFlag("Client.API.Key", set.Lookup("client-api-key")); err != nil {
|
|
return err
|
|
}
|
|
|
|
set.Int("client-api-port", defaultClientAPIPort, "Remote API server port")
|
|
if err := viper.BindPFlag("Client.API.Port", set.Lookup("client-api-port")); err != nil {
|
|
return err
|
|
}
|
|
|
|
set.StringP("client-outputstyle", "o", defaultClientOutputstyle, "CLI output style")
|
|
if err := viper.BindPFlag("Client.OutputStyle", set.Lookup("client-outputstyle")); err != nil {
|
|
return err
|
|
}
|
|
|
|
set.Bool("client-api-tls-enabled", defaultClientAPITLSEnabled, "Remote API server TLS state")
|
|
if err := viper.BindPFlag("Client.API.TLS.Enabled", set.Lookup("client-api-tls-enabled")); err != nil {
|
|
return err
|
|
}
|
|
|
|
set.Bool("client-api-tls-skipverify", defaultClientAPITLSSkipVerify, "Do not verify remote API server TLS certificate")
|
|
if err := viper.BindPFlag("Client.API.TLS.SkipVerify", set.Lookup("client-api-tls-skipverify")); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func BindAPIServerFlags(set *pflag.FlagSet) error {
|
|
if set == nil {
|
|
return fmt.Errorf("cannot bind api server flags on nil flagSet")
|
|
}
|
|
|
|
// Server.API.Bottin.Host
|
|
set.String("server-api-bottin-host", defaultServerAPIBottinHost, "Bottin API server host")
|
|
if err := viper.BindPFlag("Server.API.Bottin.Host", set.Lookup("server-api-bottin-host")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Bottin.Key
|
|
set.String("server-api-bottin-key", defaultServerAPIBottinKey, "Bottin API server key")
|
|
if err := viper.BindPFlag("Server.API.Bottin.Key", set.Lookup("server-api-bottin-key")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Bottin.Port
|
|
set.Int("server-api-bottin-port", defaultServerAPIBottinPort, "Bottin API server port")
|
|
if err := viper.BindPFlag("Server.API.Bottin.Port", set.Lookup("server-api-bottin-port")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Bottin.TLS.Enabled
|
|
set.Bool("server-api-bottin-tls-enabled", defaultServerAPIBottinTLSEnabled, "Bottin API server TLS state")
|
|
if err := viper.BindPFlag("Server.API.Bottin.TLS.Enabled", set.Lookup("server-api-bottin-tls-enabled")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Bottin.TLS.SkipVerify
|
|
set.Bool("server-api-bottin-tls-skipverify", defaultServerAPIBottinTLSSkipVerify, "Do not verify bottin API server TLS certificate")
|
|
if err := viper.BindPFlag("Server.API.Bottin.TLS.SkipVerify", set.Lookup("server-api-bottin-tls-skipverify")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Host
|
|
set.String("server-api-host", defaultServerAPIHost, "API server host")
|
|
if err := viper.BindPFlag("Server.API.Host", set.Lookup("server-api-host")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Key
|
|
set.String("server-api-key", defaultServerAPIKey, "API server key")
|
|
if err := viper.BindPFlag("Server.API.Key", set.Lookup("server-api-key")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Port
|
|
set.Int("server-api-port", defaultServerAPIPort, "API server port")
|
|
if err := viper.BindPFlag("Server.API.Port", set.Lookup("server-api-port")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Postgres.Database
|
|
set.String("server-api-postgres-database", defaultServerAPIPostgresDatabase, "API server postgres database")
|
|
if err := viper.BindPFlag("Server.API.Postgres.Database", set.Lookup("server-api-postgres-database")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Postgres.Host
|
|
set.String("server-api-postgres-host", defaultServerAPIPostgresHost, "API server postgres host")
|
|
if err := viper.BindPFlag("Server.API.Postgres.Host", set.Lookup("server-api-postgres-host")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Postgres.Password
|
|
set.String("server-api-postgres-password", defaultServerAPIPostgresPassword, "API server postgres password")
|
|
if err := viper.BindPFlag("Server.API.Postgres.Password", set.Lookup("server-api-postgres-password")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Postgres.Port
|
|
set.Int("server-api-postgres-port", defaultServerAPIPostgresPort, "API server postgres port")
|
|
if err := viper.BindPFlag("Server.API.Postgres.Port", set.Lookup("server-api-postgres-port")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Postgres.SSLMode
|
|
set.String("server-api-postgres-sslmode", defaultServerAPIPostgresSSLMode, "API server postgres SSL mode")
|
|
if err := viper.BindPFlag("Server.API.Postgres.SSLMode", set.Lookup("server-api-postgres-sslmode")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.Postgres.User
|
|
set.String("server-api-postgres-user", defaultServerAPIPostgresUser, "API server postgres user")
|
|
if err := viper.BindPFlag("Server.API.Postgres.User", set.Lookup("server-api-postgres-user")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.TLS.CertFile
|
|
set.String("server-api-tls-certfile", defaultServerAPITLSCertFile, "API server TLS certificate file")
|
|
if err := viper.BindPFlag("Server.API.TLS.CertFile", set.Lookup("server-api-tls-certfile")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.TLS.Enabled
|
|
set.Bool("server-api-tls-enabled", defaultServerAPITLSEnabled, "API server TLS state")
|
|
if err := viper.BindPFlag("Server.API.TLS.Enabled", set.Lookup("server-api-tls-enabled")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.API.TLS.KeyFile
|
|
set.String("server-api-tls-keyfile", defaultServerAPITLSKeyFile, "API server TLS private key file")
|
|
if err := viper.BindPFlag("Server.API.TLS.KeyFile", set.Lookup("server-api-tls-keyfile")); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func BindUIServerFlags(set *pflag.FlagSet) error {
|
|
// Server.UI.API.Host
|
|
// TODO
|
|
|
|
// Server.UI.API.Key
|
|
// TODO
|
|
|
|
// Server.UI.API.Port
|
|
// TODO
|
|
|
|
// Server.UI.API.TLS.Enabled
|
|
// TODO
|
|
|
|
// Server.UI.API.TLS.SkipVerify
|
|
// TODO
|
|
|
|
// Server.UI.Host
|
|
// TODO
|
|
|
|
// Server.UI.Password
|
|
// TODO
|
|
|
|
// Server.UI.Port
|
|
set.Int("server-ui-port", defaultServerUIPort, "UI server port")
|
|
if err := viper.BindPFlag("Server.UI.Port", set.Lookup("server-ui-port")); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Server.UI.Username
|
|
// TODO
|
|
|
|
return fmt.Errorf("BindUIServerFlags not implemented")
|
|
}
|