66 "fmt"
77
88 "github.com/goccy/go-yaml"
9+ "github.com/spf13/cobra"
910 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
1011 "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1112 "github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -15,8 +16,6 @@ import (
1516 "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client"
1617 opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils"
1718 "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
18-
19- "github.com/spf13/cobra"
2019 "github.com/stackitcloud/stackit-sdk-go/services/opensearch"
2120)
2221
@@ -79,7 +78,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7978 return fmt .Errorf ("create OpenSearch credentials: %w" , err )
8079 }
8180
82- return outputResult (p , model , instanceLabel , resp )
81+ return outputResult (p , model . OutputFormat , model . ShowPassword , instanceLabel , resp )
8382 },
8483 }
8584 configureFlags (cmd )
@@ -123,11 +122,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch.
123122 return req
124123}
125124
126- func outputResult (p * print.Printer , model * inputModel , instanceLabel string , resp * opensearch.CredentialsResponse ) error {
127- if ! model .ShowPassword {
125+ func outputResult (p * print.Printer , outputFormat string , showPassword bool , instanceLabel string , resp * opensearch.CredentialsResponse ) error {
126+ if resp == nil || resp .Raw == nil || resp .Raw .Credentials == nil || resp .Uri == nil {
127+ return fmt .Errorf ("response or response content is nil" )
128+ }
129+
130+ if ! showPassword {
128131 resp .Raw .Credentials .Password = utils .Ptr ("hidden" )
129132 }
130- switch model . OutputFormat {
133+ switch outputFormat {
131134 case print .JSONOutputFormat :
132135 details , err := json .MarshalIndent (resp , "" , " " )
133136 if err != nil {
@@ -151,7 +154,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res
151154 if username := resp .Raw .Credentials .Username ; username != nil && * username != "" {
152155 p .Outputf ("Username: %s\n " , * username )
153156 }
154- if ! model . ShowPassword {
157+ if ! showPassword {
155158 p .Outputf ("Password: <hidden>\n " )
156159 } else {
157160 p .Outputf ("Password: %s\n " , utils .PtrString (resp .Raw .Credentials .Password ))
0 commit comments