Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cmd/esc/cli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ type Client interface {
duration time.Duration,
) (string, []EnvironmentDiagnostic, error)

// CheckEnvironment checks the given environment for errors.
//
// This call returns the checked environment's AST, values, schema, and any diagnostics issued by the
// evaluator.
CheckEnvironment(
ctx context.Context,
orgName string,
projectName string,
envName string,
opts ...CheckYAMLOption,
) (*esc.Environment, []EnvironmentDiagnostic, error)

// Deprecated: Use GetOpenEnvironmentWithProject instead
GetOpenEnvironment(ctx context.Context, orgName, envName, openEnvID string) (*esc.Environment, error)
// GetOpenEnvironmentWithProject returns the AST, values, and schema for the open environment with ID openEnvID in
Expand Down Expand Up @@ -835,6 +847,36 @@ func (pc *client) OpenYAMLEnvironment(
return resp.ID, nil, nil
}

func (pc *client) CheckEnvironment(
ctx context.Context,
orgName string,
projectName string,
envName string,
opts ...CheckYAMLOption,
) (*esc.Environment, []EnvironmentDiagnostic, error) {
path := fmt.Sprintf("/api/esc/environments/%v/%v/%v/check", orgName, projectName, envName)

queryObj := struct {
ShowSecrets bool `url:"showSecrets"`
}{
ShowSecrets: firstOrDefault(opts).ShowSecrets,
}

var resp esc.Environment
var errResp EnvironmentErrorResponse
err := pc.restCallWithOptions(ctx, http.MethodPost, path, queryObj, nil, &resp, httpCallOptions{
ErrorResponse: &errResp,
})
if err != nil {
var diags *EnvironmentErrorResponse
if errors.As(err, &diags) && diags.Code == http.StatusBadRequest && len(diags.Diagnostics) != 0 {
return nil, diags.Diagnostics, nil
}
return nil, nil, err
}
return &resp, nil, nil
}

// Deprecated
func (pc *client) GetOpenEnvironment(ctx context.Context, orgName, envName, openSessionID string) (*esc.Environment, error) {
return pc.GetOpenEnvironmentWithProject(ctx, orgName, DefaultProject, envName, openSessionID)
Expand Down
15 changes: 7 additions & 8 deletions cmd/esc/cli/env_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ func (get *envGetCommand) getEnvironment(
return nil, fmt.Errorf("getting environment definition: %w", err)
}
if len(path) == 0 {
return get.getEntireEnvironment(ctx, ref.orgName, def, showSecrets)
return get.getEntireEnvironment(ctx, ref, def, showSecrets)
}
return get.getEnvironmentMember(ctx, ref.orgName, ref.envName, def, path, showSecrets)
return get.getEnvironmentMember(ctx, ref, def, path, showSecrets)
}

func (get *envGetCommand) getEntireEnvironment(
ctx context.Context,
orgName string,
ref environmentRef,
def []byte,
showSecrets bool,
) (*envGetTemplateData, error) {
Expand All @@ -254,7 +254,7 @@ func (get *envGetCommand) getEntireEnvironment(
return &envGetTemplateData{Definition: string(def)}, nil
}

env, _, err := get.env.esc.client.CheckYAMLEnvironment(ctx, orgName, def, client.CheckYAMLOption{ShowSecrets: showSecrets})
env, _, err := get.env.esc.client.CheckEnvironment(ctx, ref.orgName, ref.projectName, ref.envName, client.CheckYAMLOption{ShowSecrets: showSecrets})
if err != nil {
return nil, fmt.Errorf("getting environment metadata: %w", err)
}
Expand All @@ -280,8 +280,7 @@ func (get *envGetCommand) getEntireEnvironment(

func (get *envGetCommand) getEnvironmentMember(
ctx context.Context,
orgName string,
envName string,
ref environmentRef,
def []byte,
path resource.PropertyPath,
showSecrets bool,
Expand All @@ -306,7 +305,7 @@ func (get *envGetCommand) getEnvironmentMember(
return &envGetTemplateData{Definition: def}, nil
}

env, _, err := get.env.esc.client.CheckYAMLEnvironment(ctx, orgName, def, client.CheckYAMLOption{ShowSecrets: showSecrets})
env, _, err := get.env.esc.client.CheckEnvironment(ctx, ref.orgName, ref.projectName, ref.envName, client.CheckYAMLOption{ShowSecrets: showSecrets})
if err != nil {
return nil, fmt.Errorf("getting environment metadata: %w", err)
}
Expand Down Expand Up @@ -349,7 +348,7 @@ func (get *envGetCommand) getEnvironmentMember(
rng := stacker.Range()
env := rng.Environment
if env == "<yaml>" {
env = envName
env = ref.envName
}
stack = append(stack, fmt.Sprintf("%v:%v:%v", env, rng.Begin.Line, rng.Begin.Column))
}
Expand Down
Loading