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-06-29 09:26:29 -04:00
|
|
|
AuthorizedKeys []configc.UserKey `yaml:"authorizedKeys"`
|
|
|
|
BootstrapperPath string `yaml:"bootstrapperPath"`
|
|
|
|
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) {
|
2022-06-09 10:04:30 -04:00
|
|
|
return nil, fmt.Errorf("%s not found - consult the README on how to setup cdbg", name)
|
2022-05-13 10:06:57 -04:00
|
|
|
}
|
2022-06-09 10:04:30 -04:00
|
|
|
return nil, fmt.Errorf("loading config from file %s: %w", name, err)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
return conf, nil
|
|
|
|
}
|