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