Commit 555479c7 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Give SchemesPath and SchemesUpdateInterval sensible defaults also in irmaserver

parent 85ab5dc1
......@@ -17,6 +17,7 @@ import (
"github.com/privacybydesign/gabi"
"github.com/privacybydesign/gabi/big"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/fs"
"github.com/privacybydesign/irmago/server"
"github.com/sirupsen/logrus"
)
......@@ -54,7 +55,19 @@ func (s *Server) verifyConfiguration(configuration *server.Configuration) error
irma.Logger = s.conf.Logger
if s.conf.IrmaConfiguration == nil {
var err error
var (
err error
exists bool
)
if s.conf.SchemesPath == "" {
s.conf.SchemesPath = server.DefaultSchemesPath() // Returns an existing path
}
if exists, err = fs.PathExists(s.conf.SchemesPath); err != nil {
return server.LogError(err)
}
if !exists {
return server.LogError(errors.New("Nonexisting schemes_path provided"))
}
if s.conf.SchemesAssetsPath == "" {
s.conf.IrmaConfiguration, err = irma.NewConfiguration(s.conf.SchemesPath)
} else {
......@@ -69,16 +82,16 @@ func (s *Server) verifyConfiguration(configuration *server.Configuration) error
}
if len(s.conf.IrmaConfiguration.SchemeManagers) == 0 {
if s.conf.DownloadDefaultSchemes {
if err := s.conf.IrmaConfiguration.DownloadDefaultSchemes(); err != nil {
return server.LogError(err)
}
} else {
return server.LogError(errors.New("no schemes found in irma_configuration folder " + s.conf.IrmaConfiguration.Path))
s.conf.Logger.Infof("No schemes found in %s, downloading default (irma-demo and pbdf)", s.conf.SchemesPath)
if err := s.conf.IrmaConfiguration.DownloadDefaultSchemes(); err != nil {
return server.LogError(err)
}
}
if s.conf.SchemeUpdateInterval != 0 {
s.conf.IrmaConfiguration.AutoUpdateSchemes(uint(s.conf.SchemeUpdateInterval))
if s.conf.SchemesUpdateInterval == 0 {
s.conf.SchemesUpdateInterval = 60
}
if !s.conf.DisableSchemesUpdate {
s.conf.IrmaConfiguration.AutoUpdateSchemes(uint(s.conf.SchemesUpdateInterval))
}
if s.conf.IssuerPrivateKeys == nil {
......
......@@ -24,14 +24,16 @@ var Logger *logrus.Logger = logrus.StandardLogger()
type Configuration struct {
// irma_configuration. If not given, this will be popupated using SchemesPath.
IrmaConfiguration *irma.Configuration `json:"-"`
// Path to IRMA schemes to parse into IrmaConfiguration (only used if IrmaConfiguration == nil)
// Path to IRMA schemes to parse into IrmaConfiguration (only used if IrmaConfiguration == nil).
// If left empty, default value is taken using DefaultSchemesPath().
// If an empty folder is specified, default schemes (irma-demo and pbdf) are downloaded into it.
SchemesPath string `json:"schemes_path" mapstructure:"schemes_path"`
// If specified, schemes found here are copied into SchemesPath (only used if IrmaConfiguration == nil)
SchemesAssetsPath string `json:"schemes_assets_path" mapstructure:"schemes_assets_path"`
// Whether or not to download default IRMA schemes if the specified schemes path is empty
DownloadDefaultSchemes bool `json:"schemes_download_default" mapstructure:"schemes_download_default"`
// Update all schemes every x minutes (0 to disable)
SchemeUpdateInterval int `json:"schemes_update" mapstructure:"schemes_update"`
// Disable scheme updating
DisableSchemesUpdate bool `json:"disable_schemes_update" mapstructure:"disable_schemes_update"`
// Update all schemes every x minutes (default value 0 means 60) (use DisableSchemesUpdate to disable)
SchemesUpdateInterval int `json:"schemes_update" mapstructure:"schemes_update"`
// Path to issuer private keys to parse
IssuerPrivateKeysPath string `json:"privkeys" mapstructure:"privkeys"`
// Issuer private keys
......
......@@ -20,15 +20,16 @@ Specify -v to see the configuration.`,
if err := configure(command); err != nil {
die(errors.WrapPrefix(err, "Failed to read configuration from file, args, or env vars", 0))
}
interval := conf.SchemeUpdateInterval
download := conf.DownloadDefaultSchemes
conf.SchemeUpdateInterval = 0 // Hack: put this to 0 to prevent verifyConfiguration() from immediately updating schemes
conf.DownloadDefaultSchemes = false // and this to false to prevent default scheme downloading
// Hack: temporarily disable scheme updating to prevent verifyConfiguration() from immediately updating schemes
enabled := conf.DisableSchemesUpdate
conf.DisableSchemesUpdate = true
if _, err := requestorserver.New(conf); err != nil {
die(errors.WrapPrefix(err, "Invalid configuration", 0))
}
conf.SchemeUpdateInterval = interval // restore previous values before printing configuration
conf.DownloadDefaultSchemes = download
conf.DisableSchemesUpdate = enabled // restore previous value before printing configuration
bts, _ := json.MarshalIndent(conf, "", " ")
conf.Logger.Debug("Configuration: ", string(bts), "\n")
},
......
......@@ -185,11 +185,11 @@ func configure(cmd *cobra.Command) error {
// Read configuration from flags and/or environmental variables
conf = &requestorserver.Configuration{
Configuration: &server.Configuration{
DownloadDefaultSchemes: true, // If we get passed an empty schemes-path, download default schemes into it
SchemesPath: viper.GetString("schemes-path"),
SchemesAssetsPath: viper.GetString("schemes-assets-path"),
SchemeUpdateInterval: viper.GetInt("schemes-update"),
IssuerPrivateKeysPath: viper.GetString("privkeys"),
SchemesPath: viper.GetString("schemes-path"),
SchemesAssetsPath: viper.GetString("schemes-assets-path"),
SchemesUpdateInterval: viper.GetInt("schemes-update"),
DisableSchemesUpdate: viper.GetInt("schemes-update") == 0,
IssuerPrivateKeysPath: viper.GetString("privkeys"),
URL: viper.GetString("url"),
Email: viper.GetString("email"),
Logger: logger,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment