AB#2064 Feat/config/dev config to config (#139)

Renamed dev-config to config, additionally changed cdbg config to yaml.
This commit is contained in:
Fabian Kammel 2022-05-13 11:56:43 +02:00 committed by GitHub
parent fde7304d78
commit 83857b142c
20 changed files with 175 additions and 189 deletions

View file

@ -28,20 +28,20 @@ var deployCmd = &cobra.Command{
Use: "deploy",
Short: "Deploys a self-compiled coordinator binary and SSH keys on the current constellation",
Long: `Deploys a self-compiled coordinator binary and SSH keys on the current constellation.
Uses dev-config provided by --dev-config and reads constellation config from its default location.
Uses config provided by --config and reads constellation config from its default location.
If required, you can override the IP addresses that are used for a deployment by specifying "--ips" and a list of IP addresses.
Specifying --coordinator will upload the coordinator from the specified path.`,
RunE: runDeploy,
Example: "cdbg deploy --dev-config /path/to/dev-config\ncdbg deploy --coordinator /path/to/coordinator --ips 192.0.2.1,192.0.2.2,192.0.2.3 --dev-config /path/to/dev-config",
Example: "cdbg deploy --config /path/to/config\ncdbg deploy --coordinator /path/to/coordinator --ips 192.0.2.1,192.0.2.2,192.0.2.3 --config /path/to/config",
}
func runDeploy(cmd *cobra.Command, args []string) error {
devConfigName, err := cmd.Flags().GetString("dev-config")
configName, err := cmd.Flags().GetString("config")
if err != nil {
return err
}
fileHandler := file.NewHandler(afero.NewOsFs())
config, err := config.FromFile(fileHandler, devConfigName)
config, err := config.FromFile(fileHandler, configName)
if err != nil {
return err
}
@ -178,7 +178,7 @@ func init() {
rootCmd.AddCommand(deployCmd)
deployCmd.Flags().StringSlice("ips", nil, "override the ips that the coordinator will be uploaded to (defaults to ips from constellation config)")
deployCmd.Flags().String("coordinator", "", "override the path to the coordinator binary uploaded to instances (defaults to path set in dev-config)")
deployCmd.Flags().String("coordinator", "", "override the path to the coordinator binary uploaded to instances (defaults to path set in config)")
}
type fileToStreamReader interface {

View file

@ -3,6 +3,7 @@ package cmd
import (
"os"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/cobra"
)
@ -21,6 +22,5 @@ func Execute() {
}
func init() {
rootCmd.PersistentFlags().String("dev-config", "", "debugd config file (required)")
_ = rootCmd.MarkPersistentFlagRequired("dev-config")
rootCmd.PersistentFlags().String("config", constants.ConfigFilename, "debugd config file")
}

View file

@ -11,15 +11,15 @@ import (
// CDBGConfig describes the constellation-cli config file and extends it with a new field "cdbg".
type CDBGConfig struct {
ConstellationDebugConfig ConstellationDebugdConfig `json:"cdbg"`
configc.Config ``
ConstellationDebugConfig ConstellationDebugdConfig `yaml:"cdbg"`
configc.Config
}
// ConstellationDebugdConfig is the cdbg specific configuration.
type ConstellationDebugdConfig struct {
AuthorizedKeys []ssh.SSHKey `json:"authorized_keys"`
CoordinatorPath string `json:"coordinator_path"`
SystemdUnits []deploy.SystemdUnit `json:"systemd_units,omitempty"`
AuthorizedKeys []ssh.SSHKey `yaml:"authorizedKeys"`
CoordinatorPath string `yaml:"coordinatorPath"`
SystemdUnits []deploy.SystemdUnit `yaml:"systemdUnits,omitempty"`
}
// Default returns a struct with the default config.
@ -42,7 +42,7 @@ func FromFile(fileHandler file.Handler, name string) (*CDBGConfig, error) {
return conf, nil
}
if err := fileHandler.ReadJSON(name, conf); err != nil {
if err := fileHandler.ReadYAML(name, conf); err != nil {
return nil, fmt.Errorf("could not load config from file %s: %w", name, err)
}
return conf, nil

View file

@ -34,8 +34,8 @@ type ServiceManagerRequest struct {
// SystemdUnit describes a systemd service file including the unit name and contents.
type SystemdUnit struct {
Name string `json:"name"`
Contents string `json:"contents"`
Name string `yaml:"name"`
Contents string `yaml:"contents"`
}
// ServiceManager receives ServiceManagerRequests and units via channels and performs the requests / creates the unit files.

View file

@ -2,6 +2,6 @@ package ssh
// SSHKey describes a public ssh key.
type SSHKey struct {
Username string `json:"user"`
KeyValue string `json:"pubkey"`
Username string `yaml:"user"`
KeyValue string `yaml:"pubkey"`
}