From 7f0862a65633a40c742a9d8eb6e12e924adc4d57 Mon Sep 17 00:00:00 2001 From: Benjosh95 Date: Tue, 9 Sep 2025 08:44:33 +0200 Subject: [PATCH 1/2] fix: server describe and list commands output the userdata in base64 in yaml --- internal/cmd/server/describe/describe.go | 7 ++++++- internal/cmd/server/list/list.go | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/cmd/server/describe/describe.go b/internal/cmd/server/describe/describe.go index 85444e6ec..e6d1755bb 100644 --- a/internal/cmd/server/describe/describe.go +++ b/internal/cmd/server/describe/describe.go @@ -18,6 +18,7 @@ import ( "github.com/goccy/go-yaml" "github.com/spf13/cobra" + sdkutils "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" ) @@ -118,7 +119,11 @@ func outputResult(p *print.Printer, outputFormat string, server *iaas.Server) er return nil case print.YAMLOutputFormat: - details, err := yaml.MarshalWithOptions(server, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) + converted, err := sdkutils.ConvertForYAML(server) + if err != nil { + return fmt.Errorf("convert server for YAML: %w", err) + } + details, err := yaml.MarshalWithOptions(converted, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) if err != nil { return fmt.Errorf("marshal server: %w", err) } diff --git a/internal/cmd/server/list/list.go b/internal/cmd/server/list/list.go index 29eb51222..544f4ee14 100644 --- a/internal/cmd/server/list/list.go +++ b/internal/cmd/server/list/list.go @@ -19,6 +19,7 @@ import ( "github.com/goccy/go-yaml" "github.com/spf13/cobra" + sdkutils "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" ) @@ -158,7 +159,17 @@ func outputResult(p *print.Printer, outputFormat string, servers []iaas.Server) return nil case print.YAMLOutputFormat: - details, err := yaml.MarshalWithOptions(servers, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) + // Convert each server to map with base64 encoded byte arrays + convertedServers := make([]map[string]interface{}, len(servers)) + for i, server := range servers { + converted, err := sdkutils.ConvertForYAML(server) + if err != nil { + return fmt.Errorf("convert server for YAML: %w", err) + } + convertedServers[i] = converted + } + + details, err := yaml.MarshalWithOptions(convertedServers, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) if err != nil { return fmt.Errorf("marshal server: %w", err) } From 5926b4f4722618bf3e44cce79c102cb79c4c488f Mon Sep 17 00:00:00 2001 From: Benjosh95 Date: Tue, 9 Sep 2025 09:01:24 +0200 Subject: [PATCH 2/2] adjust naming --- internal/cmd/server/describe/describe.go | 2 +- internal/cmd/server/list/list.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/server/describe/describe.go b/internal/cmd/server/describe/describe.go index e6d1755bb..50a1065c8 100644 --- a/internal/cmd/server/describe/describe.go +++ b/internal/cmd/server/describe/describe.go @@ -119,7 +119,7 @@ func outputResult(p *print.Printer, outputFormat string, server *iaas.Server) er return nil case print.YAMLOutputFormat: - converted, err := sdkutils.ConvertForYAML(server) + converted, err := sdkutils.ConvertByteArraysToBase64(server) if err != nil { return fmt.Errorf("convert server for YAML: %w", err) } diff --git a/internal/cmd/server/list/list.go b/internal/cmd/server/list/list.go index 544f4ee14..850f3d228 100644 --- a/internal/cmd/server/list/list.go +++ b/internal/cmd/server/list/list.go @@ -162,7 +162,7 @@ func outputResult(p *print.Printer, outputFormat string, servers []iaas.Server) // Convert each server to map with base64 encoded byte arrays convertedServers := make([]map[string]interface{}, len(servers)) for i, server := range servers { - converted, err := sdkutils.ConvertForYAML(server) + converted, err := sdkutils.ConvertByteArraysToBase64(server) if err != nil { return fmt.Errorf("convert server for YAML: %w", err) }