Restructure config and constants

This commit is contained in:
katexochen 2022-04-06 10:36:58 +02:00 committed by Paul Meyer
parent 66bb632a69
commit 1a9b33d738
18 changed files with 134 additions and 112 deletions

View File

@ -57,7 +57,7 @@ add_dependencies(coordinator nitro)
add_custom_target(cli ALL add_custom_target(cli ALL
${CMAKE_COMMAND} -E env CGO_CFLAGS=${NITRO_CFLAGS} ${CMAKE_COMMAND} -E env CGO_CFLAGS=${NITRO_CFLAGS}
${CMAKE_COMMAND} -E env CGO_LDFLAGS=${NITRO_LDFLAGS} ${CMAKE_COMMAND} -E env CGO_LDFLAGS=${NITRO_LDFLAGS}
go build -o ${CMAKE_BINARY_DIR}/constellation -buildvcs=false -tags=aws,gcp -ldflags "-buildid='' -X github.com/edgelesssys/constellation/cli/defaults.Version=${PROJECT_VERSION}" go build -o ${CMAKE_BINARY_DIR}/constellation -buildvcs=false -tags=aws,gcp -ldflags "-buildid='' -X github.com/edgelesssys/constellation/internal/constants.CliVersion=${PROJECT_VERSION}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/cli) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/cli)
add_dependencies(cli nitro) add_dependencies(cli nitro)

View File

@ -6,7 +6,7 @@ import (
"io/fs" "io/fs"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -26,15 +26,15 @@ func newCreateCmd() *cobra.Command {
} }
// checkDirClean checks if files of a previous Constellation are left in the current working dir. // checkDirClean checks if files of a previous Constellation are left in the current working dir.
func checkDirClean(fileHandler file.Handler, config *config.Config) error { func checkDirClean(fileHandler file.Handler) error {
if _, err := fileHandler.Stat(*config.StatePath); !errors.Is(err, fs.ErrNotExist) { if _, err := fileHandler.Stat(constants.StateFilename); !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("file '%s' already exists in working directory, run 'constellation terminate' before creating a new one", *config.StatePath) return fmt.Errorf("file '%s' already exists in working directory, run 'constellation terminate' before creating a new one", constants.StateFilename)
} }
if _, err := fileHandler.Stat(*config.AdminConfPath); !errors.Is(err, fs.ErrNotExist) { if _, err := fileHandler.Stat(constants.AdminConfFilename); !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("file '%s' already exists in working directory, run 'constellation terminate' before creating a new one", *config.AdminConfPath) return fmt.Errorf("file '%s' already exists in working directory, run 'constellation terminate' before creating a new one", constants.AdminConfFilename)
} }
if _, err := fileHandler.Stat(*config.MasterSecretPath); !errors.Is(err, fs.ErrNotExist) { if _, err := fileHandler.Stat(constants.MasterSecretFilename); !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("file '%s' already exists in working directory, clean it up first", *config.MasterSecretPath) return fmt.Errorf("file '%s' already exists in working directory, clean it up first", constants.MasterSecretFilename)
} }
return nil return nil

View File

@ -13,6 +13,7 @@ import (
"github.com/edgelesssys/constellation/cli/ec2/client" "github.com/edgelesssys/constellation/cli/ec2/client"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
) )
func newCreateAWSCmd() *cobra.Command { func newCreateAWSCmd() *cobra.Command {
@ -23,7 +24,7 @@ func newCreateAWSCmd() *cobra.Command {
Example: "aws 1 4 2xlarge", Example: "aws 1 4 2xlarge",
Args: cobra.MatchAll( Args: cobra.MatchAll(
cobra.ExactArgs(3), cobra.ExactArgs(3),
isValidAWSCoordinatorCount(0), isValidAWSCoordinatorCount(0, 1),
isIntGreaterZeroArg(1), isIntGreaterZeroArg(1),
isEC2InstanceType(2), isEC2InstanceType(2),
), ),
@ -64,7 +65,7 @@ func runCreateAWS(cmd *cobra.Command, args []string) error {
// After the instances are running, they are tagged with the default tags. // After the instances are running, they are tagged with the default tags.
// On success, the state of the client is saved to the state file. // On success, the state of the client is saved to the state file.
func createAWS(cmd *cobra.Command, cl ec2client, fileHandler file.Handler, config *config.Config, size, name string, count int) (retErr error) { func createAWS(cmd *cobra.Command, cl ec2client, fileHandler file.Handler, config *config.Config, size, name string, count int) (retErr error) {
if err := checkDirClean(fileHandler, config); err != nil { if err := checkDirClean(fileHandler); err != nil {
return err return err
} }
@ -112,7 +113,7 @@ func createAWS(cmd *cobra.Command, cl ec2client, fileHandler file.Handler, confi
if err != nil { if err != nil {
return err return err
} }
if err := fileHandler.WriteJSON(*config.StatePath, stat, file.OptNone); err != nil { if err := fileHandler.WriteJSON(constants.StateFilename, stat, file.OptNone); err != nil {
return err return err
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/edgelesssys/constellation/cli/ec2" "github.com/edgelesssys/constellation/cli/ec2"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -138,7 +139,7 @@ func TestCreateAWS(t *testing.T) {
fs := afero.NewMemMapFs() fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs) fileHandler := file.NewHandler(fs)
if tc.existingState != nil { if tc.existingState != nil {
require.NoError(fileHandler.WriteJSON(*config.StatePath, *tc.existingState, file.OptNone)) require.NoError(fileHandler.WriteJSON(constants.StateFilename, *tc.existingState, file.OptNone))
} }
err := createAWS(cmd, tc.client, fileHandler, config, "xlarge", "name", 3) err := createAWS(cmd, tc.client, fileHandler, config, "xlarge", "name", 3)
@ -152,7 +153,7 @@ func TestCreateAWS(t *testing.T) {
} else { } else {
assert.NoError(err) assert.NoError(err)
var stat state.ConstellationState var stat state.ConstellationState
err := fileHandler.ReadJSON(*config.StatePath, &stat) err := fileHandler.ReadJSON(constants.StateFilename, &stat)
assert.NoError(err) assert.NoError(err)
assert.Equal(tc.stateExpected, stat) assert.Equal(tc.stateExpected, stat)
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/edgelesssys/constellation/cli/azure/client" "github.com/edgelesssys/constellation/cli/azure/client"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -71,7 +72,7 @@ func runCreateAzure(cmd *cobra.Command, args []string) error {
} }
func createAzure(cmd *cobra.Command, cl azureclient, fileHandler file.Handler, config *config.Config, size string, countCoordinators, countNodes int) (retErr error) { func createAzure(cmd *cobra.Command, cl azureclient, fileHandler file.Handler, config *config.Config, size string, countCoordinators, countNodes int) (retErr error) {
if err := checkDirClean(fileHandler, config); err != nil { if err := checkDirClean(fileHandler); err != nil {
return err return err
} }
@ -120,7 +121,7 @@ func createAzure(cmd *cobra.Command, cl azureclient, fileHandler file.Handler, c
if err != nil { if err != nil {
return err return err
} }
if err := fileHandler.WriteJSON(*config.StatePath, stat, file.OptNone); err != nil { if err := fileHandler.WriteJSON(constants.StateFilename, stat, file.OptNone); err != nil {
return err return err
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/edgelesssys/constellation/cli/cloudprovider" "github.com/edgelesssys/constellation/cli/cloudprovider"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -155,7 +156,7 @@ func TestCreateAzure(t *testing.T) {
fs := afero.NewMemMapFs() fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs) fileHandler := file.NewHandler(fs)
if tc.existingState != nil { if tc.existingState != nil {
require.NoError(fileHandler.WriteJSON(*config.StatePath, *tc.existingState, file.OptNone)) require.NoError(fileHandler.WriteJSON(constants.StateFilename, *tc.existingState, file.OptNone))
} }
err := createAzure(cmd, tc.client, fileHandler, config, "Standard_D2s_v3", 3, 2) err := createAzure(cmd, tc.client, fileHandler, config, "Standard_D2s_v3", 3, 2)
@ -168,7 +169,7 @@ func TestCreateAzure(t *testing.T) {
} else { } else {
assert.NoError(err) assert.NoError(err)
var state state.ConstellationState var state state.ConstellationState
err := fileHandler.ReadJSON(*config.StatePath, &state) err := fileHandler.ReadJSON(constants.StateFilename, &state)
assert.NoError(err) assert.NoError(err)
assert.Equal(tc.stateExpected, state) assert.Equal(tc.stateExpected, state)
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/gcp"
"github.com/edgelesssys/constellation/cli/gcp/client" "github.com/edgelesssys/constellation/cli/gcp/client"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -65,7 +66,7 @@ func runCreateGCP(cmd *cobra.Command, args []string) error {
} }
func createGCP(cmd *cobra.Command, cl gcpclient, fileHandler file.Handler, config *config.Config, size string, countCoordinators, countNodes int) (retErr error) { func createGCP(cmd *cobra.Command, cl gcpclient, fileHandler file.Handler, config *config.Config, size string, countCoordinators, countNodes int) (retErr error) {
if err := checkDirClean(fileHandler, config); err != nil { if err := checkDirClean(fileHandler); err != nil {
return err return err
} }
@ -114,7 +115,7 @@ func createGCP(cmd *cobra.Command, cl gcpclient, fileHandler file.Handler, confi
return err return err
} }
if err := fileHandler.WriteJSON(*config.StatePath, stat, file.OptNone); err != nil { if err := fileHandler.WriteJSON(constants.StateFilename, stat, file.OptNone); err != nil {
return err return err
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/gcp"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -153,7 +154,7 @@ func TestCreateGCP(t *testing.T) {
fs := afero.NewMemMapFs() fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs) fileHandler := file.NewHandler(fs)
if tc.existingState != nil { if tc.existingState != nil {
require.NoError(fileHandler.WriteJSON(*config.StatePath, *tc.existingState, file.OptNone)) require.NoError(fileHandler.WriteJSON(constants.StateFilename, *tc.existingState, file.OptNone))
} }
err := createGCP(cmd, tc.client, fileHandler, config, "n2d-standard-2", 3, 2) err := createGCP(cmd, tc.client, fileHandler, config, "n2d-standard-2", 3, 2)
@ -168,7 +169,7 @@ func TestCreateGCP(t *testing.T) {
} else { } else {
assert.NoError(err) assert.NoError(err)
var stat state.ConstellationState var stat state.ConstellationState
err := fileHandler.ReadJSON(*config.StatePath, &stat) err := fileHandler.ReadJSON(constants.StateFilename, &stat)
assert.NoError(err) assert.NoError(err)
assert.Equal(tc.stateExpected, stat) assert.Equal(tc.stateExpected, stat)
} }

View File

@ -4,15 +4,13 @@ import (
"testing" "testing"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestCheckDirClean(t *testing.T) { func TestCheckDirClean(t *testing.T) {
config := config.Default()
testCases := map[string]struct { testCases := map[string]struct {
fileHandler file.Handler fileHandler file.Handler
existingFiles []string existingFiles []string
@ -23,22 +21,22 @@ func TestCheckDirClean(t *testing.T) {
}, },
"adminconf exists": { "adminconf exists": {
fileHandler: file.NewHandler(afero.NewMemMapFs()), fileHandler: file.NewHandler(afero.NewMemMapFs()),
existingFiles: []string{*config.AdminConfPath}, existingFiles: []string{constants.AdminConfFilename},
wantErr: true, wantErr: true,
}, },
"master secret exists": { "master secret exists": {
fileHandler: file.NewHandler(afero.NewMemMapFs()), fileHandler: file.NewHandler(afero.NewMemMapFs()),
existingFiles: []string{*config.MasterSecretPath}, existingFiles: []string{constants.MasterSecretFilename},
wantErr: true, wantErr: true,
}, },
"state file exists": { "state file exists": {
fileHandler: file.NewHandler(afero.NewMemMapFs()), fileHandler: file.NewHandler(afero.NewMemMapFs()),
existingFiles: []string{*config.StatePath}, existingFiles: []string{constants.StateFilename},
wantErr: true, wantErr: true,
}, },
"multiple exist": { "multiple exist": {
fileHandler: file.NewHandler(afero.NewMemMapFs()), fileHandler: file.NewHandler(afero.NewMemMapFs()),
existingFiles: []string{*config.AdminConfPath, *config.MasterSecretPath, *config.StatePath}, existingFiles: []string{constants.AdminConfFilename, constants.MasterSecretFilename, constants.StateFilename},
wantErr: true, wantErr: true,
}, },
} }
@ -52,7 +50,7 @@ func TestCheckDirClean(t *testing.T) {
require.NoError(tc.fileHandler.Write(f, []byte{1, 2, 3}, file.OptNone)) require.NoError(tc.fileHandler.Write(f, []byte{1, 2, 3}, file.OptNone))
} }
err := checkDirClean(tc.fileHandler, config) err := checkDirClean(tc.fileHandler)
if tc.wantErr { if tc.wantErr {
assert.Error(err) assert.Error(err)

View File

@ -19,6 +19,7 @@ import (
coordinatorstate "github.com/edgelesssys/constellation/coordinator/state" coordinatorstate "github.com/edgelesssys/constellation/coordinator/state"
"github.com/edgelesssys/constellation/coordinator/util" "github.com/edgelesssys/constellation/coordinator/util"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
"github.com/kr/text" "github.com/kr/text"
wgquick "github.com/nmiculinic/wg-quick-go" wgquick "github.com/nmiculinic/wg-quick-go"
@ -72,13 +73,13 @@ func runInitialize(cmd *cobra.Command, args []string) error {
func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, serviceAccountCr serviceAccountCreator, func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, serviceAccountCr serviceAccountCreator,
fileHandler file.Handler, config *config.Config, waiter statusWaiter, vpnHandler vpnHandler, fileHandler file.Handler, config *config.Config, waiter statusWaiter, vpnHandler vpnHandler,
) error { ) error {
flagArgs, err := evalFlagArgs(cmd, fileHandler, config) flagArgs, err := evalFlagArgs(cmd, fileHandler)
if err != nil { if err != nil {
return err return err
} }
var stat state.ConstellationState var stat state.ConstellationState
err = fileHandler.ReadJSON(*config.StatePath, &stat) err = fileHandler.ReadJSON(constants.StateFilename, &stat)
if errors.Is(err, fs.ErrNotExist) { if errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("nothing to initialize: %w", err) return fmt.Errorf("nothing to initialize: %w", err)
} else if err != nil { } else if err != nil {
@ -101,7 +102,7 @@ func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, ser
if err != nil { if err != nil {
return err return err
} }
if err := fileHandler.WriteJSON(*config.StatePath, stat, file.OptOverwrite); err != nil { if err := fileHandler.WriteJSON(constants.StateFilename, stat, file.OptOverwrite); err != nil {
return err return err
} }
@ -134,7 +135,7 @@ func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, ser
return err return err
} }
err = result.writeOutput(cmd.OutOrStdout(), fileHandler, config) err = result.writeOutput(cmd.OutOrStdout(), fileHandler)
if err != nil { if err != nil {
return err return err
} }
@ -144,7 +145,7 @@ func initialize(ctx context.Context, cmd *cobra.Command, protCl protoClient, ser
return err return err
} }
if err := writeWGQuickFile(fileHandler, config, vpnHandler, vpnConfig); err != nil { if err := writeWGQuickFile(fileHandler, vpnHandler, vpnConfig); err != nil {
return fmt.Errorf("write wg-quick file: %w", err) return fmt.Errorf("write wg-quick file: %w", err)
} }
@ -223,15 +224,15 @@ type activationResult struct {
} }
// writeWGQuickFile writes the wg-quick file to the default path. // writeWGQuickFile writes the wg-quick file to the default path.
func writeWGQuickFile(fileHandler file.Handler, config *config.Config, vpnHandler vpnHandler, vpnConfig *wgquick.Config) error { func writeWGQuickFile(fileHandler file.Handler, vpnHandler vpnHandler, vpnConfig *wgquick.Config) error {
data, err := vpnHandler.Marshal(vpnConfig) data, err := vpnHandler.Marshal(vpnConfig)
if err != nil { if err != nil {
return err return err
} }
return fileHandler.Write(*config.WGQuickConfigPath, data, file.OptNone) return fileHandler.Write(constants.WGQuickConfigFilename, data, file.OptNone)
} }
func (r activationResult) writeOutput(wr io.Writer, fileHandler file.Handler, config *config.Config) error { func (r activationResult) writeOutput(wr io.Writer, fileHandler file.Handler) error {
fmt.Fprint(wr, "Your Constellation was successfully initialized.\n\n") fmt.Fprint(wr, "Your Constellation was successfully initialized.\n\n")
tw := tabwriter.NewWriter(wr, 0, 0, 2, ' ', 0) tw := tabwriter.NewWriter(wr, 0, 0, 2, ' ', 0)
@ -240,18 +241,18 @@ func (r activationResult) writeOutput(wr io.Writer, fileHandler file.Handler, co
writeRow(tw, "Coordinator's public key", r.coordinatorPubKey) writeRow(tw, "Coordinator's public key", r.coordinatorPubKey)
writeRow(tw, "Constellation's owner identifier", r.ownerID) writeRow(tw, "Constellation's owner identifier", r.ownerID)
writeRow(tw, "Constellation's unique identifier", r.clusterID) writeRow(tw, "Constellation's unique identifier", r.clusterID)
writeRow(tw, "WireGuard configuration file", *config.WGQuickConfigPath) writeRow(tw, "WireGuard configuration file", constants.WGQuickConfigFilename)
writeRow(tw, "Kubernetes configuration", *config.AdminConfPath) writeRow(tw, "Kubernetes configuration", constants.AdminConfFilename)
tw.Flush() tw.Flush()
fmt.Fprintln(wr) fmt.Fprintln(wr)
if err := fileHandler.Write(*config.AdminConfPath, []byte(r.kubeconfig), file.OptNone); err != nil { if err := fileHandler.Write(constants.AdminConfFilename, []byte(r.kubeconfig), file.OptNone); err != nil {
return fmt.Errorf("write kubeconfig: %w", err) return fmt.Errorf("write kubeconfig: %w", err)
} }
fmt.Fprintln(wr, "You can now connect to your Constellation by executing:") fmt.Fprintln(wr, "You can now connect to your Constellation by executing:")
fmt.Fprintf(wr, "\twg-quick up ./%s\n", *config.WGQuickConfigPath) fmt.Fprintf(wr, "\twg-quick up ./%s\n", constants.WGQuickConfigFilename)
fmt.Fprintf(wr, "\texport KUBECONFIG=\"$PWD/%s\"\n", *config.AdminConfPath) fmt.Fprintf(wr, "\texport KUBECONFIG=\"$PWD/%s\"\n", constants.AdminConfFilename)
return nil return nil
} }
@ -261,7 +262,7 @@ func writeRow(wr io.Writer, col1 string, col2 string) {
// evalFlagArgs gets the flag values and does preprocessing of these values like // evalFlagArgs gets the flag values and does preprocessing of these values like
// reading the content from file path flags and deriving other values from flag combinations. // reading the content from file path flags and deriving other values from flag combinations.
func evalFlagArgs(cmd *cobra.Command, fileHandler file.Handler, config *config.Config) (flagArgs, error) { func evalFlagArgs(cmd *cobra.Command, fileHandler file.Handler) (flagArgs, error) {
userPrivKeyPath, err := cmd.Flags().GetString("privatekey") userPrivKeyPath, err := cmd.Flags().GetString("privatekey")
if err != nil { if err != nil {
return flagArgs{}, err return flagArgs{}, err
@ -278,7 +279,7 @@ func evalFlagArgs(cmd *cobra.Command, fileHandler file.Handler, config *config.C
if err != nil { if err != nil {
return flagArgs{}, err return flagArgs{}, err
} }
masterSecret, err := readOrGeneratedMasterSecret(cmd.OutOrStdout(), fileHandler, masterSecretPath, config) masterSecret, err := readOrGeneratedMasterSecret(cmd.OutOrStdout(), fileHandler, masterSecretPath)
if err != nil { if err != nil {
return flagArgs{}, err return flagArgs{}, err
} }
@ -338,7 +339,7 @@ func ipsToEndpoints(ips []string, port string) []string {
} }
// readOrGeneratedMasterSecret reads a base64 encoded master secret from file or generates a new 32 byte secret. // readOrGeneratedMasterSecret reads a base64 encoded master secret from file or generates a new 32 byte secret.
func readOrGeneratedMasterSecret(w io.Writer, fileHandler file.Handler, filename string, config *config.Config) ([]byte, error) { func readOrGeneratedMasterSecret(w io.Writer, fileHandler file.Handler, filename string) ([]byte, error) {
if filename != "" { if filename != "" {
// Try to read the base64 secret from file // Try to read the base64 secret from file
encodedSecret, err := fileHandler.Read(filename) encodedSecret, err := fileHandler.Read(filename)
@ -360,10 +361,10 @@ func readOrGeneratedMasterSecret(w io.Writer, fileHandler file.Handler, filename
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := fileHandler.Write(*config.MasterSecretPath, []byte(base64.StdEncoding.EncodeToString(masterSecret)), file.OptNone); err != nil { if err := fileHandler.Write(constants.MasterSecretFilename, []byte(base64.StdEncoding.EncodeToString(masterSecret)), file.OptNone); err != nil {
return nil, err return nil, err
} }
fmt.Fprintf(w, "Your Constellation master secret was successfully written to ./%s\n", *config.MasterSecretPath) fmt.Fprintf(w, "Your Constellation master secret was successfully written to ./%s\n", constants.MasterSecretFilename)
return masterSecret, nil return masterSecret, nil
} }

View File

@ -15,6 +15,7 @@ import (
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/gcp"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
wgquick "github.com/nmiculinic/wg-quick-go" wgquick "github.com/nmiculinic/wg-quick-go"
"github.com/spf13/afero" "github.com/spf13/afero"
@ -336,7 +337,7 @@ func TestInitialize(t *testing.T) {
cmd.SetErr(&errOut) cmd.SetErr(&errOut)
fs := afero.NewMemMapFs() fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs) fileHandler := file.NewHandler(fs)
require.NoError(fileHandler.WriteJSON(*config.StatePath, tc.existingState, file.OptNone)) require.NoError(fileHandler.WriteJSON(constants.StateFilename, tc.existingState, file.OptNone))
// Write key file to filesystem and set path in flag. // Write key file to filesystem and set path in flag.
require.NoError(afero.Afero{Fs: fs}.WriteFile("privK", []byte(tc.privKey), 0o600)) require.NoError(afero.Afero{Fs: fs}.WriteFile("privK", []byte(tc.privKey), 0o600))
@ -376,16 +377,15 @@ func TestWriteOutput(t *testing.T) {
var out bytes.Buffer var out bytes.Buffer
testFs := afero.NewMemMapFs() testFs := afero.NewMemMapFs()
fileHandler := file.NewHandler(testFs) fileHandler := file.NewHandler(testFs)
config := config.Default()
err := result.writeOutput(&out, fileHandler, config) err := result.writeOutput(&out, fileHandler)
assert.NoError(err) assert.NoError(err)
assert.Contains(out.String(), result.clientVpnIP) assert.Contains(out.String(), result.clientVpnIP)
assert.Contains(out.String(), result.coordinatorPubIP) assert.Contains(out.String(), result.coordinatorPubIP)
assert.Contains(out.String(), result.coordinatorPubKey) assert.Contains(out.String(), result.coordinatorPubKey)
afs := afero.Afero{Fs: testFs} afs := afero.Afero{Fs: testFs}
adminConf, err := afs.ReadFile(*config.AdminConfPath) adminConf, err := afs.ReadFile(constants.AdminConfFilename)
assert.NoError(err) assert.NoError(err)
assert.Equal(result.kubeconfig, string(adminConf)) assert.Equal(result.kubeconfig, string(adminConf))
} }
@ -522,14 +522,13 @@ func TestReadOrGeneratedMasterSecret(t *testing.T) {
require := require.New(t) require := require.New(t)
fileHandler := file.NewHandler(tc.fs()) fileHandler := file.NewHandler(tc.fs())
config := config.Default()
if tc.createFile { if tc.createFile {
require.NoError(fileHandler.Write(tc.filename, []byte(tc.filecontent), file.OptNone)) require.NoError(fileHandler.Write(tc.filename, []byte(tc.filecontent), file.OptNone))
} }
var out bytes.Buffer var out bytes.Buffer
secret, err := readOrGeneratedMasterSecret(&out, fileHandler, tc.filename, config) secret, err := readOrGeneratedMasterSecret(&out, fileHandler, tc.filename)
if tc.errExpected { if tc.errExpected {
assert.Error(err) assert.Error(err)
@ -537,7 +536,7 @@ func TestReadOrGeneratedMasterSecret(t *testing.T) {
assert.NoError(err) assert.NoError(err)
if tc.filename == "" { if tc.filename == "" {
require.Contains(out.String(), *config.MasterSecretPath) require.Contains(out.String(), constants.MasterSecretFilename)
filename := strings.Split(out.String(), "./") filename := strings.Split(out.String(), "./")
tc.filename = strings.Trim(filename[1], "\n") tc.filename = strings.Trim(filename[1], "\n")
} }
@ -697,7 +696,7 @@ func TestAutoscaleFlag(t *testing.T) {
fs := afero.NewMemMapFs() fs := afero.NewMemMapFs()
fileHandler := file.NewHandler(fs) fileHandler := file.NewHandler(fs)
vpnHandler := stubVPNHandler{} vpnHandler := stubVPNHandler{}
require.NoError(fileHandler.WriteJSON(*config.StatePath, tc.existingState, file.OptNone)) require.NoError(fileHandler.WriteJSON(constants.StateFilename, tc.existingState, file.OptNone))
// Write key file to filesystem and set path in flag. // Write key file to filesystem and set path in flag.
require.NoError(afero.Afero{Fs: fs}.WriteFile("privK", []byte(tc.privKey), 0o600)) require.NoError(afero.Afero{Fs: fs}.WriteFile("privK", []byte(tc.privKey), 0o600))
@ -719,25 +718,21 @@ func TestAutoscaleFlag(t *testing.T) {
func TestWriteWGQuickFile(t *testing.T) { func TestWriteWGQuickFile(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
fileHandler file.Handler fileHandler file.Handler
config *config.Config
vpnHandler *stubVPNHandler vpnHandler *stubVPNHandler
vpnConfig *wgquick.Config vpnConfig *wgquick.Config
wantErr bool wantErr bool
}{ }{
"write wg quick file": { "write wg quick file": {
fileHandler: file.NewHandler(afero.NewMemMapFs()), fileHandler: file.NewHandler(afero.NewMemMapFs()),
config: &config.Config{WGQuickConfigPath: func(s string) *string { return &s }("a.conf")},
vpnHandler: &stubVPNHandler{marshalRes: "config"}, vpnHandler: &stubVPNHandler{marshalRes: "config"},
}, },
"marshal failed": { "marshal failed": {
fileHandler: file.NewHandler(afero.NewMemMapFs()), fileHandler: file.NewHandler(afero.NewMemMapFs()),
config: &config.Config{WGQuickConfigPath: func(s string) *string { return &s }("a.conf")},
vpnHandler: &stubVPNHandler{marshalErr: errors.New("some err")}, vpnHandler: &stubVPNHandler{marshalErr: errors.New("some err")},
wantErr: true, wantErr: true,
}, },
"write fails": { "write fails": {
fileHandler: file.NewHandler(afero.NewReadOnlyFs(afero.NewMemMapFs())), fileHandler: file.NewHandler(afero.NewReadOnlyFs(afero.NewMemMapFs())),
config: &config.Config{WGQuickConfigPath: func(s string) *string { return &s }("a.conf")},
vpnHandler: &stubVPNHandler{marshalRes: "config"}, vpnHandler: &stubVPNHandler{marshalRes: "config"},
wantErr: true, wantErr: true,
}, },
@ -747,13 +742,13 @@ func TestWriteWGQuickFile(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
err := writeWGQuickFile(tc.fileHandler, tc.config, tc.vpnHandler, tc.vpnConfig) err := writeWGQuickFile(tc.fileHandler, tc.vpnHandler, tc.vpnConfig)
if tc.wantErr { if tc.wantErr {
assert.Error(err) assert.Error(err)
} else { } else {
assert.NoError(err) assert.NoError(err)
file, err := tc.fileHandler.Read(*tc.config.WGQuickConfigPath) file, err := tc.fileHandler.Read(constants.WGQuickConfigFilename)
assert.NoError(err) assert.NoError(err)
assert.Contains(string(file), tc.vpnHandler.marshalRes) assert.Contains(string(file), tc.vpnHandler.marshalRes)
} }

View File

@ -14,6 +14,7 @@ import (
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
gcp "github.com/edgelesssys/constellation/cli/gcp/client" gcp "github.com/edgelesssys/constellation/cli/gcp/client"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
) )
@ -44,7 +45,7 @@ func runTerminate(cmd *cobra.Command, args []string) error {
func terminate(cmd *cobra.Command, fileHandler file.Handler, config *config.Config) error { func terminate(cmd *cobra.Command, fileHandler file.Handler, config *config.Config) error {
var stat state.ConstellationState var stat state.ConstellationState
if err := fileHandler.ReadJSON(*config.StatePath, &stat); err != nil { if err := fileHandler.ReadJSON(constants.StateFilename, &stat); err != nil {
return err return err
} }
@ -83,16 +84,16 @@ func terminate(cmd *cobra.Command, fileHandler file.Handler, config *config.Conf
cmd.Println("Your Constellation was terminated successfully.") cmd.Println("Your Constellation was terminated successfully.")
var retErr error var retErr error
if err := fileHandler.Remove(*config.StatePath); err != nil { if err := fileHandler.Remove(constants.StateFilename); err != nil {
retErr = multierr.Append(err, fmt.Errorf("failed to remove file '%s', please remove manually", *config.StatePath)) retErr = multierr.Append(err, fmt.Errorf("failed to remove file '%s', please remove manually", constants.StateFilename))
} }
if err := fileHandler.Remove(*config.AdminConfPath); err != nil && !errors.Is(err, fs.ErrNotExist) { if err := fileHandler.Remove(constants.AdminConfFilename); err != nil && !errors.Is(err, fs.ErrNotExist) {
retErr = multierr.Append(err, fmt.Errorf("failed to remove file '%s', please remove manually", *config.AdminConfPath)) retErr = multierr.Append(err, fmt.Errorf("failed to remove file '%s', please remove manually", constants.AdminConfFilename))
} }
if err := fileHandler.Remove(*config.WGQuickConfigPath); err != nil && !errors.Is(err, fs.ErrNotExist) { if err := fileHandler.Remove(constants.WGQuickConfigFilename); err != nil && !errors.Is(err, fs.ErrNotExist) {
retErr = multierr.Append(err, fmt.Errorf("failed to remove file '%s', please remove manually", *config.WGQuickConfigPath)) retErr = multierr.Append(err, fmt.Errorf("failed to remove file '%s', please remove manually", constants.WGQuickConfigFilename))
} }
return retErr return retErr

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -12,7 +12,7 @@ func newVersionCmd() *cobra.Command {
Long: `Display version of this CLI`, Long: `Display version of this CLI`,
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmd.Printf("CLI Version: v%s \n", config.Version) cmd.Printf("CLI Version: v%s \n", constants.CliVersion)
}, },
} }
return cmd return cmd

View File

@ -5,7 +5,7 @@ import (
"io" "io"
"testing" "testing"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/constants"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -21,5 +21,5 @@ func TestVersionCmd(t *testing.T) {
s, err := io.ReadAll(b) s, err := io.ReadAll(b)
assert.NoError(err) assert.NoError(err)
assert.Contains(string(s), config.Version) assert.Contains(string(s), constants.CliVersion)
} }

View File

@ -16,6 +16,7 @@ import (
depl "github.com/edgelesssys/constellation/debugd/debugd/deploy" depl "github.com/edgelesssys/constellation/debugd/debugd/deploy"
pb "github.com/edgelesssys/constellation/debugd/service" pb "github.com/edgelesssys/constellation/debugd/service"
"github.com/edgelesssys/constellation/debugd/ssh" "github.com/edgelesssys/constellation/debugd/ssh"
"github.com/edgelesssys/constellation/internal/constants"
statec "github.com/edgelesssys/constellation/internal/state" statec "github.com/edgelesssys/constellation/internal/state"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -66,7 +67,7 @@ func deploy(cmd *cobra.Command, fileHandler file.Handler, config *config.CDBGCon
ips = overrideIPs ips = overrideIPs
} else { } else {
var stat statec.ConstellationState var stat statec.ConstellationState
err := fileHandler.ReadJSON(*config.StatePath, &stat) err := fileHandler.ReadJSON(constants.StateFilename, &stat)
if errors.Is(err, fs.ErrNotExist) { if errors.Is(err, fs.ErrNotExist) {
log.Println("Unable to load statefile. Maybe you forgot to run \"constellation create ...\" first?") log.Println("Unable to load statefile. Maybe you forgot to run \"constellation create ...\" first?")
return fmt.Errorf("loading statefile failed: %w", err) return fmt.Errorf("loading statefile failed: %w", err)

View File

@ -11,13 +11,11 @@ import (
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
gcpClient "github.com/edgelesssys/constellation/cli/gcp/client" gcpClient "github.com/edgelesssys/constellation/cli/gcp/client"
"github.com/edgelesssys/constellation/coordinator/attestation/vtpm" "github.com/edgelesssys/constellation/coordinator/attestation/vtpm"
"github.com/edgelesssys/constellation/internal/constants"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
var ( var (
// Version is the CLI Version. Left as a separate variable to allow override during build.
Version = "0.0.0"
// gcpPCRs is a map of the expected PCR values for a GCP Constellation node. // gcpPCRs is a map of the expected PCR values for a GCP Constellation node.
// TODO: Get a full list once we have stable releases. // TODO: Get a full list once we have stable releases.
gcpPCRs = map[uint32][]byte{ gcpPCRs = map[uint32][]byte{
@ -34,22 +32,10 @@ var (
} }
) )
const (
coordinatorPort = 9000
enclaveSSHPort = 2222
sshPort = 22
wireguardPort = 51820
nvmeOverTCPPort = 8009
)
// Config defines a configuration used by the CLI. // Config defines a configuration used by the CLI.
// All fields in this struct and its child structs have pointer types // All fields in this struct and its child structs have pointer types
// to ensure the default values of the actual type is not confused with an omitted value. // to ensure the default values of the actual type is not confused with an omitted value.
type Config struct { type Config struct {
StatePath *string `json:"statepath,omitempty"`
AdminConfPath *string `json:"adminconfpath,omitempty"`
MasterSecretPath *string `json:"mastersecretpath,omitempty"`
WGQuickConfigPath *string `json:"wgquickconfigpath,omitempty"`
CoordinatorPort *string `json:"coordinatorport,omitempty"` CoordinatorPort *string `json:"coordinatorport,omitempty"`
AutoscalingNodeGroupsMin *int `json:"autoscalingnodegroupsmin,omitempty"` AutoscalingNodeGroupsMin *int `json:"autoscalingnodegroupsmin,omitempty"`
AutoscalingNodeGroupsMax *int `json:"autoscalingnodegroupsmax,omitempty"` AutoscalingNodeGroupsMax *int `json:"autoscalingnodegroupsmax,omitempty"`
@ -60,11 +46,7 @@ type Config struct {
// Default returns a struct with the default config. // Default returns a struct with the default config.
func Default() *Config { func Default() *Config {
return &Config{ return &Config{
StatePath: proto.String("constellation-state.json"), CoordinatorPort: proto.String(strconv.Itoa(constants.CoordinatorPort)),
AdminConfPath: proto.String("constellation-admin.conf"),
MasterSecretPath: proto.String("constellation-mastersecret.base64"),
WGQuickConfigPath: proto.String("wg0.conf"),
CoordinatorPort: proto.String(strconv.Itoa(coordinatorPort)),
AutoscalingNodeGroupsMin: intPtr(1), AutoscalingNodeGroupsMin: intPtr(1),
AutoscalingNodeGroupsMax: intPtr(10), AutoscalingNodeGroupsMax: intPtr(10),
StateDiskSizeGB: intPtr(30), StateDiskSizeGB: intPtr(30),
@ -87,36 +69,39 @@ func Default() *Config {
Description: "Coordinator default port", Description: "Coordinator default port",
Protocol: "TCP", Protocol: "TCP",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: coordinatorPort, Port: constants.CoordinatorPort,
}, },
{ {
Description: "Enclave SSH", Description: "Enclave SSH",
Protocol: "TCP", Protocol: "TCP",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: enclaveSSHPort, Port: constants.EnclaveSSHPort,
}, },
{ {
Description: "WireGuard default port", Description: "WireGuard default port",
Protocol: "UDP", Protocol: "UDP",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: wireguardPort, Port: constants.WireguardPort,
}, },
{ {
Description: "SSH", Description: "SSH",
Protocol: "TCP", Protocol: "TCP",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: sshPort, Port: constants.SSHPort,
}, },
{ {
Description: "NVMe over TCP", Description: "NVMe over TCP",
Protocol: "TCP", Protocol: "TCP",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: nvmeOverTCPPort, Port: constants.NVMEOverTCPPort,
}, },
}, },
}, },
}, },
Azure: &AzureConfig{ Azure: &AzureConfig{
SubscriptionID: proto.String("0d202bbb-4fa7-4af8-8125-58c269a05435"),
TenantID: proto.String("adb650a8-5da3-4b15-b4b0-3daf65ff7626"),
Location: proto.String("North Europe"),
Image: proto.String("/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/CONSTELLATION-IMAGES/providers/Microsoft.Compute/galleries/Constellation/images/constellation-coreos/versions/0.0.1649852687"), Image: proto.String("/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/CONSTELLATION-IMAGES/providers/Microsoft.Compute/galleries/Constellation/images/constellation-coreos/versions/0.0.1649852687"),
NetworkSecurityGroupInput: &azureClient.NetworkSecurityGroupInput{ NetworkSecurityGroupInput: &azureClient.NetworkSecurityGroupInput{
Ingress: cloudtypes.Firewall{ Ingress: cloudtypes.Firewall{
@ -125,21 +110,21 @@ func Default() *Config {
Description: "Coordinator default port", Description: "Coordinator default port",
Protocol: "tcp", Protocol: "tcp",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: coordinatorPort, Port: constants.CoordinatorPort,
}, },
{ {
Name: "wireguard", Name: "wireguard",
Description: "WireGuard default port", Description: "WireGuard default port",
Protocol: "udp", Protocol: "udp",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: wireguardPort, Port: constants.WireguardPort,
}, },
{ {
Name: "ssh", Name: "ssh",
Description: "SSH", Description: "SSH",
Protocol: "tcp", Protocol: "tcp",
IPRange: "0.0.0.0/0", IPRange: "0.0.0.0/0",
Port: sshPort, Port: constants.SSHPort,
}, },
}, },
}, },
@ -147,6 +132,9 @@ func Default() *Config {
UserAssignedIdentity: proto.String("/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/constellation-images/providers/Microsoft.ManagedIdentity/userAssignedIdentities/constellation-dev-identity"), UserAssignedIdentity: proto.String("/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/constellation-images/providers/Microsoft.ManagedIdentity/userAssignedIdentities/constellation-dev-identity"),
}, },
GCP: &GCPConfig{ GCP: &GCPConfig{
Project: proto.String("constellation-331613"),
Region: proto.String("europe-west3"),
Zone: proto.String("europe-west3-b"),
Image: proto.String("constellation-coreos-1649852687"), Image: proto.String("constellation-coreos-1649852687"),
FirewallInput: &gcpClient.FirewallInput{ FirewallInput: &gcpClient.FirewallInput{
Ingress: cloudtypes.Firewall{ Ingress: cloudtypes.Firewall{
@ -154,19 +142,19 @@ func Default() *Config {
Name: "coordinator", Name: "coordinator",
Description: "Coordinator default port", Description: "Coordinator default port",
Protocol: "tcp", Protocol: "tcp",
Port: coordinatorPort, Port: constants.CoordinatorPort,
}, },
{ {
Name: "wireguard", Name: "wireguard",
Description: "WireGuard default port", Description: "WireGuard default port",
Protocol: "udp", Protocol: "udp",
Port: wireguardPort, Port: constants.WireguardPort,
}, },
{ {
Name: "ssh", Name: "ssh",
Description: "SSH", Description: "SSH",
Protocol: "tcp", Protocol: "tcp",
Port: sshPort, Port: constants.SSHPort,
}, },
}, },
}, },
@ -218,6 +206,9 @@ type EC2Config struct {
// AzureConfig are Azure specific configuration values used by the CLI. // AzureConfig are Azure specific configuration values used by the CLI.
type AzureConfig struct { type AzureConfig struct {
SubscriptionID *string `json:"subscription,omitempty"` // TODO: This will be user input
TenantID *string `json:"tenant,omitempty"` // TODO: This will be user input
Location *string `json:"location,omitempty"` // TODO: This will be user input
Image *string `json:"image,omitempty"` Image *string `json:"image,omitempty"`
NetworkSecurityGroupInput *azureClient.NetworkSecurityGroupInput `json:"networksecuritygroupinput,omitempty"` NetworkSecurityGroupInput *azureClient.NetworkSecurityGroupInput `json:"networksecuritygroupinput,omitempty"`
PCRs *map[uint32][]byte `json:"pcrs,omitempty"` PCRs *map[uint32][]byte `json:"pcrs,omitempty"`
@ -226,6 +217,9 @@ type AzureConfig struct {
// GCPConfig are GCP specific configuration values used by the CLI. // GCPConfig are GCP specific configuration values used by the CLI.
type GCPConfig struct { type GCPConfig struct {
Project *string `json:"project,omitempty"` // TODO: This will be user input
Region *string `json:"region,omitempty"` // TODO: This will be user input
Zone *string `json:"zone,omitempty"` // TODO: This will be user input
Image *string `json:"image,omitempty"` Image *string `json:"image,omitempty"`
FirewallInput *gcpClient.FirewallInput `json:"firewallinput,omitempty"` FirewallInput *gcpClient.FirewallInput `json:"firewallinput,omitempty"`
VPCsInput *gcpClient.VPCsInput `json:"vpcsinput,omitempty"` VPCsInput *gcpClient.VPCsInput `json:"vpcsinput,omitempty"`

View File

@ -49,9 +49,9 @@ func TestFromFile(t *testing.T) {
wantErr bool wantErr bool
}{ }{
"overwrite fields": { "overwrite fields": {
from: &Config{StatePath: proto.String("test")}, from: &Config{CoordinatorPort: proto.String("1000")},
configName: configName, configName: configName,
wantResultMutator: func(c *Config) { c.StatePath = proto.String("test") }, wantResultMutator: func(c *Config) { c.CoordinatorPort = proto.String("1000") },
}, },
"overwrite slices": { "overwrite slices": {
from: &Config{Provider: someProviderConfig}, from: &Config{Provider: someProviderConfig},
@ -87,9 +87,6 @@ func TestFromFile(t *testing.T) {
require.NoError(err) require.NoError(err)
wantResult := Default() wantResult := Default()
tc.wantResultMutator(wantResult) tc.wantResultMutator(wantResult)
assert.EqualValues(wantResult.StatePath, result.StatePath)
assert.EqualValues(wantResult.AdminConfPath, result.AdminConfPath)
assert.EqualValues(wantResult.MasterSecretPath, result.MasterSecretPath)
assert.EqualValues(wantResult.CoordinatorPort, result.CoordinatorPort) assert.EqualValues(wantResult.CoordinatorPort, result.CoordinatorPort)
assert.EqualValues(wantResult.AutoscalingNodeGroupsMin, result.AutoscalingNodeGroupsMin) assert.EqualValues(wantResult.AutoscalingNodeGroupsMin, result.AutoscalingNodeGroupsMin)
assert.EqualValues(wantResult.AutoscalingNodeGroupsMax, result.AutoscalingNodeGroupsMax) assert.EqualValues(wantResult.AutoscalingNodeGroupsMax, result.AutoscalingNodeGroupsMax)

View File

@ -0,0 +1,29 @@
/*
Package constants contains the constants used by Constellation.
Constants should never be overwritable by command line flags or configuration files.
*/
package constants
const (
//
// Ports.
//
CoordinatorPort = 9000
EnclaveSSHPort = 2222
SSHPort = 22
WireguardPort = 51820
NVMEOverTCPPort = 8009
//
// Filenames.
//
StateFilename = "constellation-state.json"
AdminConfFilename = "constellation-admin.conf"
MasterSecretFilename = "constellation-mastersecret.base64"
WGQuickConfigFilename = "wg0.conf"
)
// CliVersion is the version of the CLI. Left as a separate variable to allow override during build.
var CliVersion = "0.0.0"