Move debugd config to separate file

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-05-13 16:06:57 +02:00 committed by Malte Poll
parent 25b0ca2a06
commit baa7dbc1ef
5 changed files with 80 additions and 131 deletions

View file

@ -1,18 +1,18 @@
package config
import (
"errors"
"fmt"
"io/fs"
"github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/debugd/debugd/deploy"
"github.com/edgelesssys/constellation/debugd/ssh"
configc "github.com/edgelesssys/constellation/internal/config"
)
// CDBGConfig describes the constellation-cli config file and extends it with a new field "cdbg".
// CDBGConfig describes the constellation-cli config file.
type CDBGConfig struct {
ConstellationDebugConfig ConstellationDebugdConfig `yaml:"cdbg"`
configc.Config
}
// ConstellationDebugdConfig is the cdbg specific configuration.
@ -22,27 +22,13 @@ type ConstellationDebugdConfig struct {
SystemdUnits []deploy.SystemdUnit `yaml:"systemdUnits,omitempty"`
}
// Default returns a struct with the default config.
func Default() *CDBGConfig {
return &CDBGConfig{
ConstellationDebugConfig: ConstellationDebugdConfig{
AuthorizedKeys: []ssh.SSHKey{},
CoordinatorPath: "coordinator",
SystemdUnits: []deploy.SystemdUnit{},
},
Config: *configc.Default(),
}
}
// FromFile returns a default config that has been merged with a config file.
// If name is empty, the defaults are returned.
// FromFile reads a debug configuration.
func FromFile(fileHandler file.Handler, name string) (*CDBGConfig, error) {
conf := Default()
if name == "" {
return conf, nil
}
conf := &CDBGConfig{}
if err := fileHandler.ReadYAML(name, conf); err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("unable to find %s - consult the README on how to setup cdbg", name)
}
return nil, fmt.Errorf("could not load config from file %s: %w", name, err)
}
return conf, nil