Skip to content
Closed
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
22 changes: 21 additions & 1 deletion internal/cmd/server/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ type inputModel struct {
ServerId string
}

// convertServerForYAML creates a map with UserData as base64 string for YAML output
func convertServerForYAML(server *iaas.Server) map[string]interface{} {
if server == nil {
return nil
}

// Marshal to JSON first to get the correct format for UserData
jsonData, err := json.Marshal(server)
if err != nil {
return nil
}

var serverMap map[string]interface{}
if err := json.Unmarshal(jsonData, &serverMap); err != nil {
return nil
}

return serverMap
}

Comment on lines +33 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to move this into the utils package and make the function more generic. So that it's not specific for iaas.Server and can be used by other types as well. In $ stackit server list -o yaml, we have the same issue and with a more generic utils function, we could reuse it there

func NewCmd(params *params.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("describe %s", serverIdArg),
Expand Down Expand Up @@ -118,7 +138,7 @@ 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())
details, err := yaml.MarshalWithOptions(convertServerForYAML(server), yaml.IndentSequence(true), yaml.UseJSONMarshaler())
if err != nil {
return fmt.Errorf("marshal server: %w", err)
}
Expand Down
Loading