Skip to content

Commit

Permalink
support env pull for multiple deployment targets (#4277)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Feb 13, 2024
1 parent 55937d6 commit 7fda432
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion api/client/porter_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 10 additions & 4 deletions api/server/handlers/porter_app/app_env_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Expand Down

0 comments on commit 7fda432

Please sign in to comment.