Skip to content
Merged
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
7 changes: 7 additions & 0 deletions docs/runware_serverless_apps_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Show details for a serverless application

### Synopsis

Show details for a serverless application.

JSON and YAML include environment variable names with each value replaced by
[redacted]. Read a value with 'apps env list'.

```
runware serverless apps show <appId> [flags]
```
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/serverless/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func newAppsShowCmd(logger *log.Logger) *cobra.Command {
return &cobra.Command{
Use: "show <appId>",
Short: "Show details for a serverless application",
Long: `Show details for a serverless application.

JSON and YAML include environment variable names with each value replaced by
[redacted]. Read a value with 'apps env list'.`,
Example: ` # show details for an application
runware serverless apps show my-app`,
Args: cobra.ExactArgs(1),
Expand Down
29 changes: 29 additions & 0 deletions internal/cmd/serverless/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const (
colConcurrency = "Concurrency"
)

// redactedEnvValue replaces a plaintext environment value in JSON and YAML
// app output. apps env list is the command that prints the real value.
const redactedEnvValue = "[redacted]"

// appResult wraps a single app for table/json/yaml display.
type appResult serverlessapi.App

Expand Down Expand Up @@ -80,6 +84,31 @@ func (r appResult) Rows() [][]any {
}
}

// MarshalJSON redacts plaintext environment values. The table already omits
// them; JSON would otherwise print the value field from the app payload.
func (r appResult) MarshalJSON() ([]byte, error) {
return json.Marshal(r.withRedactedEnv())
}

// MarshalYAML redacts plaintext environment values, matching MarshalJSON.
func (r appResult) MarshalYAML() (any, error) {
return r.withRedactedEnv(), nil
}

func (r appResult) withRedactedEnv() serverlessapi.App {
app := serverlessapi.App(r)
if len(app.EnvironmentVariables) == 0 {
return app
}
env := make([]serverlessapi.EnvironmentVariable, len(app.EnvironmentVariables))
copy(env, app.EnvironmentVariables)
for i := range env {
env[i].Value = redactedEnvValue
}
app.EnvironmentVariables = env
return app
}

// appsResult wraps an app list for table display.
type appsResult []serverlessapi.App

Expand Down
41 changes: 41 additions & 0 deletions internal/cmd/serverless/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package serverless

import (
"bytes"
"encoding/json"
"slices"
"strings"
"testing"
"time"

"gopkg.in/yaml.v3"

"github.com/google/uuid"
serverlessapi "github.com/runware/runware-cli/internal/api/serverless"
"github.com/runware/runware-cli/internal/output"
Expand Down Expand Up @@ -340,6 +343,44 @@ func TestAppResult_IncludesConfiguration(t *testing.T) {
}
}

func TestAppResult_RedactsEnvironmentValues(t *testing.T) {
r := appResult{
AppId: testAppID,
EnvironmentVariables: []serverlessapi.EnvironmentVariable{
{
Key: testEnvKey,
Value: testEnvValue,
},
},
}

js, err := json.Marshal(r)
if err != nil {
t.Fatalf("json: %v", err)
}
if strings.Contains(string(js), testEnvValue) || !strings.Contains(string(js), redactedEnvValue) {
t.Fatalf("json = %s", js)
}
if !strings.Contains(string(js), testEnvKey) {
t.Fatalf("json dropped the variable name: %s", js)
}

ym, err := yaml.Marshal(r)
if err != nil {
t.Fatalf("yaml: %v", err)
}
if strings.Contains(string(ym), testEnvValue) || !strings.Contains(string(ym), redactedEnvValue) {
t.Fatalf("yaml = %s", ym)
}
if !strings.Contains(string(ym), testEnvKey) {
t.Fatalf("yaml dropped the variable name: %s", ym)
}

if r.EnvironmentVariables[0].Value != testEnvValue {
t.Fatalf("redaction mutated the app: %q", r.EnvironmentVariables[0].Value)
}
}

func TestPrintPage_TableWritesNextCursorToErrOut(t *testing.T) {
next := "page-2"
page := serverlessapi.Page[serverlessapi.App]{
Expand Down
Loading