2022-03-22 11:03:15 -04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-05-13 10:06:57 -04:00
|
|
|
"errors"
|
2022-03-22 11:03:15 -04:00
|
|
|
"fmt"
|
2022-05-13 10:06:57 -04:00
|
|
|
"io/fs"
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/debugd/debugd/deploy"
|
2022-05-17 12:42:00 -04:00
|
|
|
configc "github.com/edgelesssys/constellation/internal/config"
|
2022-05-16 11:32:00 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/file"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
2022-05-13 10:06:57 -04:00
|
|
|
// CDBGConfig describes the constellation-cli config file.
|
2022-03-22 11:03:15 -04:00
|
|
|
type CDBGConfig struct {
|
2022-05-13 05:56:43 -04:00
|
|
|
ConstellationDebugConfig ConstellationDebugdConfig `yaml:"cdbg"`
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConstellationDebugdConfig is the cdbg specific configuration.
|
|
|
|
type ConstellationDebugdConfig struct {
|
2022-05-17 12:42:00 -04:00
|
|
|
AuthorizedKeys []configc.UserKey `yaml:"authorizedKeys"`
|
2022-05-13 05:56:43 -04:00
|
|
|
CoordinatorPath string `yaml:"coordinatorPath"`
|
|
|
|
SystemdUnits []deploy.SystemdUnit `yaml:"systemdUnits,omitempty"`
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-05-13 10:06:57 -04:00
|
|
|
// FromFile reads a debug configuration.
|
2022-03-22 11:03:15 -04:00
|
|
|
func FromFile(fileHandler file.Handler, name string) (*CDBGConfig, error) {
|
2022-05-13 10:06:57 -04:00
|
|
|
conf := &CDBGConfig{}
|
2022-05-13 05:56:43 -04:00
|
|
|
if err := fileHandler.ReadYAML(name, conf); err != nil {
|
2022-05-13 10:06:57 -04:00
|
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
|
|
return nil, fmt.Errorf("unable to find %s - consult the README on how to setup cdbg", name)
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
return nil, fmt.Errorf("could not load config from file %s: %w", name, err)
|
|
|
|
}
|
|
|
|
return conf, nil
|
|
|
|
}
|