Răsfoiți Sursa

support env pull for multiple deployment targets (#4277)

ianedwards 2 ani în urmă
părinte
comite
7fda43221a

+ 4 - 1
api/client/porter_app.go

@@ -500,10 +500,13 @@ func (c *Client) GetAppEnvVariables(
 	ctx context.Context,
 	projectID uint, clusterID uint,
 	appName string,
+	deploymentTargetName string,
 ) (*porter_app.AppEnvVariablesResponse, error) {
 	resp := &porter_app.AppEnvVariablesResponse{}
 
-	req := &porter_app.AppEnvVariablesRequest{}
+	req := &porter_app.AppEnvVariablesRequest{
+		DeploymentTargetName: deploymentTargetName,
+	}
 
 	err := c.getRequest(
 		fmt.Sprintf(

+ 10 - 4
api/server/handlers/porter_app/app_env_variables.go

@@ -39,7 +39,8 @@ type EnvVariables struct {
 
 // AppEnvVariablesRequest is the request object for the /apps/{porter_app_name}/env-variables endpoint
 type AppEnvVariablesRequest struct {
-	DeploymentTargetID string `schema:"deployment_target_id"`
+	DeploymentTargetID   string `schema:"deployment_target_id"`
+	DeploymentTargetName string `schema:"deployment_target_name"`
 }
 
 // AppEnvVariablesResponse is the response object for the /apps/{porter_app_name}/env-variables endpoint
@@ -73,12 +74,17 @@ func (c *AppEnvVariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 
 	// optional deployment target id - if not provided, use the cluster's default
 	deploymentTargetID := request.DeploymentTargetID
-	telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTargetID})
+	deploymentTargetName := request.DeploymentTargetName
+	telemetry.WithAttributes(span,
+		telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTargetID},
+		telemetry.AttributeKV{Key: "deployment-target-name", Value: deploymentTargetName},
+	)
 
 	var deploymentTargetIdentifer *porterv1.DeploymentTargetIdentifier
-	if deploymentTargetID != "" {
+	if deploymentTargetID != "" || deploymentTargetName != "" {
 		deploymentTargetIdentifer = &porterv1.DeploymentTargetIdentifier{
-			Id: deploymentTargetID,
+			Id:   deploymentTargetID,
+			Name: deploymentTargetName,
 		}
 	}
 

+ 2 - 1
cli/cmd/commands/env.go

@@ -48,6 +48,7 @@ Optionally, specify a file to write the environment variables to. Otherwise the
 	pullCommand.Flags().StringVarP(&appName, "app", "a", "", "app name")
 	pullCommand.Flags().StringVarP(&envGroupName, "group", "g", "", "environment group name")
 	pullCommand.Flags().StringVarP(&envFilePath, "file", "f", "", "file to write environment variables to")
+	pullCommand.Flags().StringVarP(&deploymentTargetName, "target", "x", "", "the name of the deployment target for the app")
 
 	envCmd.AddCommand(pullCommand)
 
@@ -67,7 +68,7 @@ func pullEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, clie
 	if appName != "" {
 		color.New(color.FgGreen).Printf("Pulling environment variables for app %s...\n", appName) // nolint:errcheck,gosec
 
-		envVarsResp, err := client.GetAppEnvVariables(ctx, cliConf.Project, cliConf.Cluster, appName)
+		envVarsResp, err := client.GetAppEnvVariables(ctx, cliConf.Project, cliConf.Cluster, appName, deploymentTargetName)
 		if err != nil {
 			return fmt.Errorf("could not get app env variables: %w", err)
 		}