mirror of
				https://github.com/edgelesssys/constellation.git
				synced 2025-11-03 12:16:35 -05:00 
			
		
		
		
	* cli: move internal packages Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * cli: fix buildfiles Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * bazel: fix exclude dir Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * cli: move back libraries that will not be used by TF provider Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
		
			
				
	
	
		
			56 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
/*
 | 
						|
Copyright (c) Edgeless Systems GmbH
 | 
						|
 | 
						|
SPDX-License-Identifier: AGPL-3.0-only
 | 
						|
*/
 | 
						|
 | 
						|
package cmd
 | 
						|
 | 
						|
import (
 | 
						|
	"errors"
 | 
						|
	"fmt"
 | 
						|
	"os"
 | 
						|
 | 
						|
	"github.com/edgelesssys/constellation/v2/internal/constants"
 | 
						|
	"github.com/edgelesssys/constellation/v2/internal/file"
 | 
						|
	"github.com/edgelesssys/constellation/v2/internal/state"
 | 
						|
	"github.com/spf13/afero"
 | 
						|
	"github.com/spf13/cobra"
 | 
						|
)
 | 
						|
 | 
						|
func newMiniDownCmd() *cobra.Command {
 | 
						|
	cmd := &cobra.Command{
 | 
						|
		Use:   "down",
 | 
						|
		Short: "Destroy a MiniConstellation cluster",
 | 
						|
		Long:  "Destroy a MiniConstellation cluster.",
 | 
						|
		Args:  cobra.ExactArgs(0),
 | 
						|
		RunE:  runDown,
 | 
						|
	}
 | 
						|
	cmd.Flags().BoolP("yes", "y", false, "terminate the cluster without further confirmation")
 | 
						|
	return cmd
 | 
						|
}
 | 
						|
 | 
						|
func runDown(cmd *cobra.Command, args []string) error {
 | 
						|
	if err := checkForMiniCluster(file.NewHandler(afero.NewOsFs())); err != nil {
 | 
						|
		return fmt.Errorf("failed to destroy cluster: %w. Are you in the correct working directory?", err)
 | 
						|
	}
 | 
						|
 | 
						|
	err := runTerminate(cmd, args)
 | 
						|
	if removeErr := os.Remove(constants.MasterSecretFilename); removeErr != nil && !os.IsNotExist(removeErr) {
 | 
						|
		err = errors.Join(err, removeErr)
 | 
						|
	}
 | 
						|
	return err
 | 
						|
}
 | 
						|
 | 
						|
func checkForMiniCluster(fileHandler file.Handler) error {
 | 
						|
	stateFile, err := state.ReadFromFile(fileHandler, constants.StateFilename)
 | 
						|
	if err != nil {
 | 
						|
		return fmt.Errorf("reading state file: %w", err)
 | 
						|
	}
 | 
						|
 | 
						|
	if stateFile.Infrastructure.Name != constants.MiniConstellationName {
 | 
						|
		return errors.New("cluster is not a MiniConstellation cluster")
 | 
						|
	}
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 |