Skip to content

Commit 7f0862a

Browse files
committed
fix: server describe and list commands output the userdata in base64 in yaml
1 parent 9dfc1f3 commit 7f0862a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

internal/cmd/server/describe/describe.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/goccy/go-yaml"
2020
"github.com/spf13/cobra"
21+
sdkutils "github.com/stackitcloud/stackit-sdk-go/core/utils"
2122
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
2223
)
2324

@@ -118,7 +119,11 @@ func outputResult(p *print.Printer, outputFormat string, server *iaas.Server) er
118119

119120
return nil
120121
case print.YAMLOutputFormat:
121-
details, err := yaml.MarshalWithOptions(server, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
122+
converted, err := sdkutils.ConvertForYAML(server)
123+
if err != nil {
124+
return fmt.Errorf("convert server for YAML: %w", err)
125+
}
126+
details, err := yaml.MarshalWithOptions(converted, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
122127
if err != nil {
123128
return fmt.Errorf("marshal server: %w", err)
124129
}

internal/cmd/server/list/list.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/goccy/go-yaml"
2121
"github.com/spf13/cobra"
22+
sdkutils "github.com/stackitcloud/stackit-sdk-go/core/utils"
2223
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
2324
)
2425

@@ -158,7 +159,17 @@ func outputResult(p *print.Printer, outputFormat string, servers []iaas.Server)
158159

159160
return nil
160161
case print.YAMLOutputFormat:
161-
details, err := yaml.MarshalWithOptions(servers, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
162+
// Convert each server to map with base64 encoded byte arrays
163+
convertedServers := make([]map[string]interface{}, len(servers))
164+
for i, server := range servers {
165+
converted, err := sdkutils.ConvertForYAML(server)
166+
if err != nil {
167+
return fmt.Errorf("convert server for YAML: %w", err)
168+
}
169+
convertedServers[i] = converted
170+
}
171+
172+
details, err := yaml.MarshalWithOptions(convertedServers, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
162173
if err != nil {
163174
return fmt.Errorf("marshal server: %w", err)
164175
}

0 commit comments

Comments
 (0)