Skip to content

Commit 001684e

Browse files
feat(opensearch) describe also prints host and hosts if available (#1346)
1 parent 3a8aede commit 001684e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

internal/cmd/opensearch/credentials/describe/describe.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package describe
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
89

@@ -121,6 +122,13 @@ func outputResult(p *print.Printer, outputFormat string, credentials *opensearch
121122
table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password))
122123
table.AddSeparator()
123124
table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri))
125+
table.AddSeparator()
126+
table.AddRow("HOST", utils.PtrString(credentials.Raw.Credentials.Host))
127+
hosts := credentials.Raw.Credentials.Hosts
128+
if hosts != nil && len(*hosts) > 0 {
129+
table.AddSeparator()
130+
table.AddRow("HOSTS", strings.Join(*hosts, "\n"))
131+
}
124132
}
125133
err := table.Display(p)
126134
if err != nil {

internal/cmd/opensearch/credentials/describe/describe_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
89

910
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
@@ -220,6 +221,35 @@ func TestOutputResult(t *testing.T) {
220221
},
221222
wantErr: false,
222223
},
224+
{
225+
name: "host and hosts",
226+
args: args{
227+
credentials: &opensearch.CredentialsResponse{
228+
Raw: &opensearch.RawCredentials{
229+
Credentials: &opensearch.Credentials{
230+
Host: utils.Ptr("host"),
231+
Hosts: utils.Ptr([]string{
232+
"hosts-a",
233+
"hosts-b",
234+
}),
235+
},
236+
},
237+
},
238+
},
239+
},
240+
{
241+
name: "raw credentials nil host & hosts",
242+
args: args{
243+
credentials: &opensearch.CredentialsResponse{
244+
Raw: &opensearch.RawCredentials{
245+
Credentials: &opensearch.Credentials{
246+
Host: nil,
247+
Hosts: nil,
248+
},
249+
},
250+
},
251+
},
252+
},
223253
}
224254
p := print.NewPrinter()
225255
p.Cmd = NewCmd(&types.CmdParams{Printer: p})

0 commit comments

Comments
 (0)