Procházet zdrojové kódy

initial work for porter update env-group command

Mohammed Nafees před 3 roky
rodič
revize
e7c332a76f

+ 2 - 2
api/client/k8s.go

@@ -104,8 +104,8 @@ func (c *Client) GetEnvGroup(
 	projectID, clusterID uint,
 	namespace string,
 	req *types.GetEnvGroupRequest,
-) (*types.EnvGroup, error) {
-	resp := &types.EnvGroup{}
+) (*types.GetEnvGroupResponse, error) {
+	resp := &types.GetEnvGroupResponse{}
 
 	err := c.getRequest(
 		fmt.Sprintf(

+ 0 - 1
api/server/handlers/namespace/get_env_group.go

@@ -68,7 +68,6 @@ func (c *GetEnvGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	stackId, err := stacks.GetStackForEnvGroup(c.Config(), cluster.ProjectID, cluster.ID, envGroup)
 
 	if err != nil {
-
 		if errors.Is(err, gorm.ErrRecordNotFound) {
 			c.WriteResult(w, r, &types.GetEnvGroupResponse{EnvGroup: envGroup})
 			return

+ 80 - 0
cli/cmd/deploy.go

@@ -1,6 +1,7 @@
 package cmd
 
 import (
+	"context"
 	"fmt"
 	"os"
 	"path/filepath"
@@ -203,6 +204,39 @@ the image that the application uses if no --values file is specified:
 	},
 }
 
+var updateEnvGroupCmd = &cobra.Command{
+	Use:     "env-group",
+	Aliases: []string{"eg", "envgroup"},
+	Short:   "Updates an environment group's variables, specified by the --name flag.",
+	Run: func(cmd *cobra.Command, args []string) {
+		color.New(color.FgRed).Println("need to specify an operation to continue")
+	},
+}
+
+var updateSetEnvGroupCmd = &cobra.Command{
+	Use:   "set",
+	Short: "Sets the desired value of an environment variable in an env group in the form VAR=VALUE.",
+	Run: func(cmd *cobra.Command, args []string) {
+		err := checkLoginAndRun(args, updateSetEnvGroup)
+
+		if err != nil {
+			os.Exit(1)
+		}
+	},
+}
+
+var updateUnsetEnvGroupCmd = &cobra.Command{
+	Use:   "unset",
+	Short: "Removes an environment variable from an env group.",
+	Run: func(cmd *cobra.Command, args []string) {
+		err := checkLoginAndRun(args, updateUnsetEnvGroup)
+
+		if err != nil {
+			os.Exit(1)
+		}
+	},
+}
+
 var app string
 var getEnvFileDest string
 var localPath string
@@ -213,6 +247,8 @@ var stream bool
 var buildFlagsEnv []string
 var forcePush bool
 var useCache bool
+var value string
+var version uint
 
 func init() {
 	buildFlagsEnv = []string{}
@@ -329,9 +365,27 @@ func init() {
 		"file destination for .env files",
 	)
 
+	updateEnvGroupCmd.PersistentFlags().StringVar(
+		&name,
+		"name",
+		"",
+		"the name of the environment group",
+	)
+
+	updateEnvGroupCmd.PersistentFlags().UintVar(
+		&version,
+		"version",
+		0,
+		"the version of the environment group",
+	)
+
+	updateEnvGroupCmd.AddCommand(updateSetEnvGroupCmd)
+	updateEnvGroupCmd.AddCommand(updateUnsetEnvGroupCmd)
+
 	updateCmd.AddCommand(updateBuildCmd)
 	updateCmd.AddCommand(updatePushCmd)
 	updateCmd.AddCommand(updateConfigCmd)
+	updateCmd.AddCommand(updateEnvGroupCmd)
 }
 
 func updateFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
@@ -438,6 +492,32 @@ func updateUpgrade(_ *types.GetAuthenticatedUserResponse, client *api.Client, ar
 	return updateUpgradeWithAgent(updateAgent)
 }
 
+func updateSetEnvGroup(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
+	if len(args) == 0 {
+		return fmt.Errorf("need variable in the form VAR=VALUE")
+	}
+
+	key, value, found := strings.Cut(args[0], "=")
+
+	if !found {
+		return fmt.Errorf("need variable in the form VAR=VALUE")
+	}
+
+	envGroup, err := client.GetEnvGroup(context.Background(), cliConf.Project, cliConf.Cluster, namespace, &types.GetEnvGroupRequest{
+		Name: name, Version: version,
+	})
+
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func updateUnsetEnvGroup(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
+	return nil
+}
+
 // HELPER METHODS
 func updateGetAgent(client *api.Client) (*deploy.DeployAgent, error) {
 	var buildMethod deploy.DeployBuildType