Move cli/cmd into cli/internal

This commit is contained in:
katexochen 2022-06-08 08:14:28 +02:00
parent d71e97a940
commit c3ebd3d3cd
34 changed files with 45 additions and 32 deletions

View File

@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"github.com/edgelesssys/constellation/cli/internal/cmd"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/spf13/cobra"
)
@ -34,13 +35,13 @@ func NewRootCmd() *cobra.Command {
rootCmd.PersistentFlags().String("config", constants.ConfigFilename, "path to the configuration file")
must(rootCmd.MarkPersistentFlagFilename("config", "json"))
rootCmd.AddCommand(newConfigCmd())
rootCmd.AddCommand(newCreateCmd())
rootCmd.AddCommand(newInitCmd())
rootCmd.AddCommand(newVerifyCmd())
rootCmd.AddCommand(newRecoverCmd())
rootCmd.AddCommand(newTerminateCmd())
rootCmd.AddCommand(newVersionCmd())
rootCmd.AddCommand(cmd.NewConfigCmd())
rootCmd.AddCommand(cmd.NewCreateCmd())
rootCmd.AddCommand(cmd.NewInitCmd())
rootCmd.AddCommand(cmd.NewVerifyCmd())
rootCmd.AddCommand(cmd.NewRecoverCmd())
rootCmd.AddCommand(cmd.NewTerminateCmd())
rootCmd.AddCommand(cmd.NewVersionCmd())
return rootCmd
}

View File

@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"
)
func newConfigCmd() *cobra.Command {
func NewConfigCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Work with the Constellation configuration file",

View File

@ -15,7 +15,8 @@ import (
"github.com/spf13/cobra"
)
func newCreateCmd() *cobra.Command {
// NewCreateCmd returns a new cobra.Command for the create command.
func NewCreateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create {aws|azure|gcp}",
Short: "Create instances on a cloud platform for your Constellation cluster",
@ -208,6 +209,12 @@ func createCompletion(cmd *cobra.Command, args []string, toComplete string) ([]s
}
}
func must(err error) {
if err != nil {
panic(err)
}
}
func instanceTypeCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 1 {
return []string{}, cobra.ShellCompDirectiveError

View File

@ -34,7 +34,7 @@ func TestCreateArgumentValidation(t *testing.T) {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
err := newCreateCmd().ValidateArgs(tc.args)
err := NewCreateCmd().ValidateArgs(tc.args)
if tc.wantErr {
assert.Error(err)
@ -225,7 +225,7 @@ func TestCreate(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
cmd := newCreateCmd()
cmd := NewCreateCmd()
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})
cmd.SetIn(bytes.NewBufferString(tc.stdin))

View File

@ -35,7 +35,8 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func newInitCmd() *cobra.Command {
// NewInitCmd returns a new cobra.Command for the init command.
func NewInitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize the Constellation cluster",

View File

@ -24,7 +24,7 @@ import (
func TestInitArgumentValidation(t *testing.T) {
assert := assert.New(t)
cmd := newInitCmd()
cmd := NewInitCmd()
assert.NoError(cmd.ValidateArgs(nil))
assert.Error(cmd.ValidateArgs([]string{"something"}))
assert.Error(cmd.ValidateArgs([]string{"sth", "sth"}))
@ -285,7 +285,7 @@ func TestInitialize(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
cmd := newInitCmd()
cmd := NewInitCmd()
var out bytes.Buffer
cmd.SetOut(&out)
var errOut bytes.Buffer
@ -592,7 +592,7 @@ func TestAutoscaleFlag(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
cmd := newInitCmd()
cmd := NewInitCmd()
var out bytes.Buffer
cmd.SetOut(&out)
var errOut bytes.Buffer

View File

@ -20,7 +20,8 @@ import (
var diskUUIDRegexp = regexp.MustCompile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
func newRecoverCmd() *cobra.Command {
// NewRecoverCmd returns a new cobra.Command for the recover command.
func NewRecoverCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "recover",
Short: "Recover a completely stopped Constellation cluster",

View File

@ -27,7 +27,7 @@ func TestRecoverCmdArgumentValidation(t *testing.T) {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
cmd := newRecoverCmd()
cmd := NewRecoverCmd()
err := cmd.ValidateArgs(tc.args)
if tc.wantErr {
@ -160,7 +160,7 @@ func TestRecover(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
cmd := newRecoverCmd()
cmd := NewRecoverCmd()
cmd.Flags().String("config", "", "") // register persisten flag manually
out := &bytes.Buffer{}
cmd.SetOut(out)
@ -255,7 +255,7 @@ func TestParseRecoverFlags(t *testing.T) {
fs := afero.NewMemMapFs()
require.NoError(afero.WriteFile(fs, "constellation-mastersecret.base64", []byte("Y29uc3RlbGxhdGlvbi1tYXN0ZXItc2VjcmV0LWxlbmc="), 0o777))
cmd := newRecoverCmd()
cmd := NewRecoverCmd()
cmd.Flags().String("config", "", "") // register persistent flag manually
require.NoError(cmd.ParseFlags(tc.args))
flags, err := parseRecoverFlags(cmd, file.NewHandler(fs))

View File

@ -15,7 +15,8 @@ import (
"github.com/edgelesssys/constellation/internal/state"
)
func newTerminateCmd() *cobra.Command {
// NewTerminateCmd returns a new cobra.Command for the terminate command.
func NewTerminateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "terminate",
Short: "Terminate a Constellation cluster",

View File

@ -27,7 +27,7 @@ func TestTerminateCmdArgumentValidation(t *testing.T) {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
cmd := newTerminateCmd()
cmd := NewTerminateCmd()
err := cmd.ValidateArgs(tc.args)
if tc.wantErr {
@ -105,7 +105,7 @@ func TestTerminate(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
cmd := newTerminateCmd()
cmd := NewTerminateCmd()
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})

View File

@ -15,7 +15,8 @@ import (
rpcStatus "google.golang.org/grpc/status"
)
func newVerifyCmd() *cobra.Command {
// NewVerifyCmd returns a new cobra.Command for the verify command.
func NewVerifyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "verify {aws|azure|gcp}",
Short: "Verify the confidential properties of a Constellation cluster",

View File

@ -32,7 +32,7 @@ func TestVerifyCmdArgumentValidation(t *testing.T) {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
cmd := newVerifyCmd()
cmd := NewVerifyCmd()
err := cmd.ValidateArgs(tc.args)
if tc.wantErr {
@ -132,7 +132,7 @@ func TestVerify(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
cmd := newVerifyCmd()
cmd := NewVerifyCmd()
cmd.Flags().String("config", "", "") // register persisten flag manually
out := &bytes.Buffer{}
cmd.SetOut(out)

View File

@ -5,7 +5,8 @@ import (
"github.com/spf13/cobra"
)
func newVersionCmd() *cobra.Command {
// NewVerifyCmd returns a new cobra.Command for the verify command.
func NewVersionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Display version of this CLI",

View File

@ -12,7 +12,7 @@ import (
func TestVersionCmd(t *testing.T) {
assert := assert.New(t)
cmd := newVersionCmd()
cmd := NewVersionCmd()
b := &bytes.Buffer{}
cmd.SetOut(b)

View File

@ -7,7 +7,7 @@ import (
"os"
"os/exec"
"github.com/edgelesssys/constellation/cli/qemu"
"github.com/edgelesssys/constellation/internal/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/state"
)
@ -41,17 +41,17 @@ func transformState(tfOut terraformOutput) state.ConstellationState {
Name: "qemu",
UID: "debug",
CloudProvider: "qemu",
QEMUNodes: qemu.Instances{},
QEMUCoordinators: qemu.Instances{},
QEMUNodes: cloudtypes.Instances{},
QEMUCoordinators: cloudtypes.Instances{},
}
for i, ip := range tfOut.ControlPlaneIPs.Value {
conState.QEMUCoordinators[fmt.Sprintf("control-plane-%d", i)] = qemu.Instance{
conState.QEMUCoordinators[fmt.Sprintf("control-plane-%d", i)] = cloudtypes.Instance{
PublicIP: ip,
PrivateIP: ip,
}
}
for i, ip := range tfOut.WorkerIPs.Value {
conState.QEMUNodes[fmt.Sprintf("worker-%d", i)] = qemu.Instance{
conState.QEMUNodes[fmt.Sprintf("worker-%d", i)] = cloudtypes.Instance{
PublicIP: ip,
PrivateIP: ip,
}