Prechádzať zdrojové kódy

warn and confirm when deploying home directory

Mohammed Nafees 4 rokov pred
rodič
commit
7fbfa61ce4
3 zmenil súbory, kde vykonal 56 pridanie a 4 odobranie
  1. 18 4
      cli/cmd/create.go
  2. 21 0
      cli/cmd/deploy.go
  3. 17 0
      cli/cmd/utils/prompt.go

+ 18 - 4
cli/cmd/create.go

@@ -12,7 +12,9 @@ import (
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
 	"github.com/porter-dev/porter/cli/cmd/gitutils"
+	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/spf13/cobra"
+	"k8s.io/client-go/util/homedir"
 	"sigs.k8s.io/yaml"
 )
 
@@ -175,20 +177,32 @@ func createFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args
 
 	var err error
 
-	// read the values if necessary
-	valuesObj, err := readValuesFile()
+	fullPath, err := filepath.Abs(localPath)
+
 	if err != nil {
 		return err
 	}
 
-	color.New(color.FgGreen).Printf("Creating %s release: %s\n", args[0], name)
+	if source == "local" && fullPath == homedir.HomeDir() {
+		proceed, err := utils.PromptConfirm("You are deploying your home directory. Do you want to continue?", false)
 
-	fullPath, err := filepath.Abs(localPath)
+		if err != nil {
+			return err
+		}
 
+		if !proceed {
+			return nil
+		}
+	}
+
+	// read the values if necessary
+	valuesObj, err := readValuesFile()
 	if err != nil {
 		return err
 	}
 
+	color.New(color.FgGreen).Printf("Creating %s release: %s\n", args[0], name)
+
 	var buildMethod deploy.DeployBuildType
 
 	if method != "" {

+ 21 - 0
cli/cmd/deploy.go

@@ -3,13 +3,16 @@ package cmd
 import (
 	"fmt"
 	"os"
+	"path/filepath"
 	"strings"
 
 	"github.com/fatih/color"
 	api "github.com/porter-dev/porter/api/client"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
+	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/spf13/cobra"
+	"k8s.io/client-go/util/homedir"
 )
 
 // updateCmd represents the "porter update" base command when called
@@ -318,6 +321,24 @@ func init() {
 }
 
 func updateFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
+	fullPath, err := filepath.Abs(localPath)
+
+	if err != nil {
+		return err
+	}
+
+	if source == "local" && fullPath == homedir.HomeDir() {
+		proceed, err := utils.PromptConfirm("You are deploying your home directory. Do you want to continue?", false)
+
+		if err != nil {
+			return err
+		}
+
+		if !proceed {
+			return nil
+		}
+	}
+
 	color.New(color.FgGreen).Println("Deploying app:", app)
 
 	updateAgent, err := updateGetAgent(client)

+ 17 - 0
cli/cmd/utils/prompt.go

@@ -92,3 +92,20 @@ func PromptMultiselect(prompt string, options []string) ([]string, error) {
 
 	return ans, err
 }
+
+func PromptConfirm(message string, defaultVal bool) (bool, error) {
+	value := false
+
+	prompt := &survey.Confirm{
+		Message: message,
+		Default: defaultVal,
+	}
+
+	err := survey.AskOne(prompt, &value)
+
+	if err != nil {
+		return false, err
+	}
+
+	return value, nil
+}