Skip to content

Commit 8c0a014

Browse files
feat(opensearch): opensearch sdk migration
1 parent f4e5858 commit 8c0a014

27 files changed

Lines changed: 488 additions & 539 deletions

docs/stackit_opensearch_instance_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ stackit opensearch instance create [flags]
3030
--enable-monitoring Enable monitoring
3131
--graphite string Graphite host
3232
-h, --help Help for "stackit opensearch instance create"
33-
--metrics-frequency int Metrics frequency
33+
--metrics-frequency int32 Metrics frequency
3434
--metrics-prefix string Metrics prefix
3535
--monitoring-instance-id string Monitoring instance ID
3636
-n, --name string Instance name
3737
--plan-id string Plan ID
3838
--plan-name string Plan name
39-
--plugin strings Plugin
39+
--plugin strings Plugins (multiple of: [repository-s3, repository-azure, analysis-phonetic]) (default [])
4040
--syslog strings Syslog
4141
--version string Instance OpenSearch version
4242
```

docs/stackit_opensearch_instance_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ stackit opensearch instance update INSTANCE_ID [flags]
2727
--enable-monitoring Enable monitoring
2828
--graphite string Graphite host
2929
-h, --help Help for "stackit opensearch instance update"
30-
--metrics-frequency int Metrics frequency
30+
--metrics-frequency int32 Metrics frequency
3131
--metrics-prefix string Metrics prefix
3232
--monitoring-instance-id string Monitoring instance ID
3333
--plan-id string Plan ID
3434
--plan-name string Plan name
35-
--plugin strings Plugin
35+
--plugin strings Plugins (multiple of: [repository-s3, repository-azure, analysis-phonetic]) (default [])
3636
--syslog strings Syslog
3737
--version string Instance OpenSearch version
3838
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1
2727
github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2
2828
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.12.0
29-
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6
29+
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0
3030
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
3131
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0
3232
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.9.0 h1:T+ll3lS0
624624
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.9.0/go.mod h1:QsPtoqAYvumyPU6ToX/5j1PbudN+VSTuvh6mp154ecM=
625625
github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0 h1:KhuWPXr1hl8BFLGLSi6wjxh5o6OQXH9amfquMhYQROU=
626626
github.com/stackitcloud/stackit-sdk-go/services/observability v0.24.0/go.mod h1:0fEZQHm729mBdvg4sNrAhM6KmHROHJSeS2FwCMRk46k=
627-
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6 h1:oTVx1+O177Ojn8OvXIOUbRSwtx7L59jhxDPrZEQFOfQ=
628-
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6/go.mod h1:6ZBeCCY6qG8w1oK7osf61Egyv3mp7Ahv6GDGxiarDGo=
627+
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0 h1:hooc/E9Qabn8xno1NUd3uJQfUbW5KoY6mgURlnd776c=
628+
github.com/stackitcloud/stackit-sdk-go/services/opensearch v1.1.0/go.mod h1:L+NlfC1hilLOqlLLukCj/UDnxlnNrc/oMikcw3Ansyw=
629629
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQx954yI8fuQmxXwRf/myqAdLg2KvxImp00g=
630630
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw=
631631
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v1.1.0 h1:HRJwodJX4aOn/487zaqJIKw13yIj4T6dn7/kEHLxeTg=

internal/cmd/opensearch/credentials/create/create.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
88

99
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
10+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -17,7 +17,6 @@ import (
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client"
1919
opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils"
20-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2120
)
2221

2322
const (
@@ -58,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5857
return err
5958
}
6059

61-
instanceLabel, err := opensearchUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId)
60+
instanceLabel, err := opensearchUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
6261
if err != nil {
6362
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6463
instanceLabel = model.InstanceId
@@ -109,35 +108,35 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
109108
}
110109

111110
func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch.APIClient) opensearch.ApiCreateCredentialsRequest {
112-
req := apiClient.CreateCredentials(ctx, model.ProjectId, model.InstanceId)
111+
req := apiClient.DefaultAPI.CreateCredentials(ctx, model.ProjectId, model.Region, model.InstanceId)
113112
return req
114113
}
115114

116115
func outputResult(p *print.Printer, outputFormat string, showPassword bool, instanceLabel string, resp *opensearch.CredentialsResponse) error {
117-
if resp == nil || resp.Raw == nil || resp.Raw.Credentials == nil || resp.Uri == nil {
116+
if resp == nil || resp.Raw == nil {
118117
return fmt.Errorf("response or response content is nil")
119118
}
120119

121120
if !showPassword {
122-
resp.Raw.Credentials.Password = utils.Ptr("hidden")
121+
resp.Raw.Credentials.Password = "hidden"
123122
}
124123

125124
return p.OutputResult(outputFormat, resp, func() error {
126-
p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id))
125+
p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, resp.Id)
127126
// The username field cannot be set by the user so we only display it if it's not returned empty
128-
if resp.HasRaw() && resp.Raw.Credentials != nil {
129-
if username := resp.Raw.Credentials.Username; username != nil && *username != "" {
130-
p.Outputf("Username: %s\n", *username)
127+
if resp.HasRaw() {
128+
if username := resp.Raw.Credentials.Username; username != "" {
129+
p.Outputf("Username: %s\n", username)
131130
}
132131
if !showPassword {
133132
p.Outputf("Password: <hidden>\n")
134133
} else {
135-
p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password))
134+
p.Outputf("Password: %s\n", resp.Raw.Credentials.Password)
136135
}
137-
p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host))
138-
p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port))
136+
p.Outputf("Host: %s\n", resp.Raw.Credentials.Host)
137+
p.Outputf("Port: %d\n", resp.Raw.Credentials.Port)
139138
}
140-
p.Outputf("URI: %s\n", *resp.Uri)
139+
p.Outputf("URI: %s\n", resp.Uri)
141140
return nil
142141
})
143142
}

internal/cmd/opensearch/credentials/create/create_test.go

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/google/go-cmp/cmp/cmpopts"
99
"github.com/google/uuid"
10-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
10+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
15-
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1615
)
1716

1817
type testCtxKey struct{}
1918

20-
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &opensearch.APIClient{}
22-
var testProjectId = uuid.NewString()
23-
var testInstanceId = uuid.NewString()
19+
var (
20+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21+
testClient = &opensearch.APIClient{DefaultAPI: &opensearch.DefaultAPIService{}}
22+
testProjectId = uuid.NewString()
23+
testRegion = "eu01"
24+
testInstanceId = uuid.NewString()
25+
)
2426

2527
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2628
flagValues := map[string]string{
2729
globalflags.ProjectIdFlag: testProjectId,
30+
globalflags.RegionFlag: testRegion,
2831
instanceIdFlag: testInstanceId,
2932
}
3033
for _, mod := range mods {
@@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3740
model := &inputModel{
3841
GlobalFlagModel: &globalflags.GlobalFlagModel{
3942
ProjectId: testProjectId,
43+
Region: testRegion,
4044
Verbosity: globalflags.VerbosityDefault,
4145
},
4246
InstanceId: testInstanceId,
@@ -48,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4852
}
4953

5054
func fixtureRequest(mods ...func(request *opensearch.ApiCreateCredentialsRequest)) opensearch.ApiCreateCredentialsRequest {
51-
request := testClient.CreateCredentials(testCtx, testProjectId, testInstanceId)
55+
request := testClient.DefaultAPI.CreateCredentials(testCtx, testProjectId, testRegion, testInstanceId)
5256
for _, mod := range mods {
5357
mod(&request)
5458
}
@@ -154,7 +158,7 @@ func TestBuildRequest(t *testing.T) {
154158

155159
diff := cmp.Diff(request, tt.expectedRequest,
156160
cmp.AllowUnexported(tt.expectedRequest),
157-
cmpopts.EquateComparable(testCtx),
161+
cmpopts.EquateComparable(testCtx, opensearch.DefaultAPIService{}),
158162
)
159163
if diff != "" {
160164
t.Fatalf("Data does not match: %s", diff)
@@ -181,41 +185,18 @@ func TestOutputResult(t *testing.T) {
181185
wantErr: true,
182186
},
183187
{
184-
name: "set no raw in response",
185-
args: args{
186-
resp: &opensearch.CredentialsResponse{
187-
Uri: utils.Ptr("https://opensearch.example.com"),
188-
},
189-
},
190-
wantErr: true,
191-
},
192-
{
193-
name: "set empty raw in response",
194-
args: args{
195-
resp: &opensearch.CredentialsResponse{
196-
Raw: &opensearch.RawCredentials{},
197-
Uri: utils.Ptr("https://opensearch.example.com"),
198-
},
199-
},
200-
wantErr: true,
201-
},
202-
{
203-
name: "set raw but no uri in response",
188+
name: "set uri but no raw in response",
204189
args: args{
205190
resp: &opensearch.CredentialsResponse{
206-
Raw: &opensearch.RawCredentials{
207-
Credentials: &opensearch.Credentials{},
208-
},
191+
Uri: "https://opensearch.example.com",
209192
},
210193
},
211194
wantErr: true,
212195
},
213196
{
214-
name: "set uri but no raw in response",
197+
name: "empty response should not cause panic when password should be hidden",
215198
args: args{
216-
resp: &opensearch.CredentialsResponse{
217-
Uri: utils.Ptr("https://opensearch.example.com"),
218-
},
199+
showPassword: false,
219200
},
220201
wantErr: true,
221202
},
@@ -224,9 +205,9 @@ func TestOutputResult(t *testing.T) {
224205
args: args{
225206
resp: &opensearch.CredentialsResponse{
226207
Raw: &opensearch.RawCredentials{
227-
Credentials: &opensearch.Credentials{},
208+
Credentials: opensearch.Credentials{},
228209
},
229-
Uri: utils.Ptr("https://opensearch.example.com"),
210+
Uri: "https://opensearch.example.com",
230211
},
231212
},
232213
wantErr: false,

internal/cmd/opensearch/credentials/delete/delete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1818

1919
"github.com/spf13/cobra"
20-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
20+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api"
2121
)
2222

2323
const (
@@ -56,13 +56,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5656
return err
5757
}
5858

59-
instanceLabel, err := opensearchUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId)
59+
instanceLabel, err := opensearchUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
6060
if err != nil {
6161
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6262
instanceLabel = model.InstanceId
6363
}
6464

65-
credentialsLabel, err := opensearchUtils.GetCredentialsUsername(ctx, apiClient, model.ProjectId, model.InstanceId, model.CredentialsId)
65+
credentialsLabel, err := opensearchUtils.GetCredentialsUsername(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId, model.CredentialsId)
6666
if err != nil {
6767
params.Printer.Debug(print.ErrorLevel, "get credentials user name: %v", err)
6868
credentialsLabel = model.CredentialsId
@@ -115,6 +115,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
115115
}
116116

117117
func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch.APIClient) opensearch.ApiDeleteCredentialsRequest {
118-
req := apiClient.DeleteCredentials(ctx, model.ProjectId, model.InstanceId, model.CredentialsId)
118+
req := apiClient.DefaultAPI.DeleteCredentials(ctx, model.ProjectId, model.Region, model.InstanceId, model.CredentialsId)
119119
return req
120120
}

internal/cmd/opensearch/credentials/delete/delete_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ import (
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/google/uuid"
13-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
13+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api"
1414
)
1515

1616
type testCtxKey struct{}
1717

18-
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
19-
var testClient = &opensearch.APIClient{}
20-
var testProjectId = uuid.NewString()
21-
var testInstanceId = uuid.NewString()
22-
var testCredentialsId = uuid.NewString()
18+
var (
19+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
20+
testClient = &opensearch.APIClient{DefaultAPI: &opensearch.DefaultAPIService{}}
21+
testProjectId = uuid.NewString()
22+
testRegion = "eu01"
23+
testInstanceId = uuid.NewString()
24+
testCredentialsId = uuid.NewString()
25+
)
2326

2427
func fixtureArgValues(mods ...func(argValues []string)) []string {
2528
argValues := []string{
@@ -34,6 +37,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3437
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3538
flagValues := map[string]string{
3639
globalflags.ProjectIdFlag: testProjectId,
40+
globalflags.RegionFlag: testRegion,
3741
instanceIdFlag: testInstanceId,
3842
}
3943
for _, mod := range mods {
@@ -46,6 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4650
model := &inputModel{
4751
GlobalFlagModel: &globalflags.GlobalFlagModel{
4852
ProjectId: testProjectId,
53+
Region: testRegion,
4954
Verbosity: globalflags.VerbosityDefault,
5055
},
5156
InstanceId: testInstanceId,
@@ -58,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5863
}
5964

6065
func fixtureRequest(mods ...func(request *opensearch.ApiDeleteCredentialsRequest)) opensearch.ApiDeleteCredentialsRequest {
61-
request := testClient.DeleteCredentials(testCtx, testProjectId, testInstanceId, testCredentialsId)
66+
request := testClient.DefaultAPI.DeleteCredentials(testCtx, testProjectId, testRegion, testInstanceId, testCredentialsId)
6267
for _, mod := range mods {
6368
mod(&request)
6469
}
@@ -186,7 +191,7 @@ func TestBuildRequest(t *testing.T) {
186191

187192
diff := cmp.Diff(request, tt.expectedRequest,
188193
cmp.AllowUnexported(tt.expectedRequest),
189-
cmpopts.EquateComparable(testCtx),
194+
cmpopts.EquateComparable(testCtx, opensearch.DefaultAPIService{}),
190195
)
191196
if diff != "" {
192197
t.Fatalf("Data does not match: %s", diff)

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1919

2020
"github.com/spf13/cobra"
21-
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
21+
opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api"
2222
)
2323

2424
const (
@@ -100,34 +100,33 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
100100
}
101101

102102
func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch.APIClient) opensearch.ApiGetCredentialsRequest {
103-
req := apiClient.GetCredentials(ctx, model.ProjectId, model.InstanceId, model.CredentialsId)
103+
req := apiClient.DefaultAPI.GetCredentials(ctx, model.ProjectId, model.Region, model.InstanceId, model.CredentialsId)
104104
return req
105105
}
106106

107107
func outputResult(p *print.Printer, outputFormat string, credentials *opensearch.CredentialsResponse) error {
108-
if credentials == nil {
109-
return fmt.Errorf("credentials is nil")
110-
}
111-
112108
return p.OutputResult(outputFormat, credentials, func() error {
109+
if credentials == nil {
110+
return fmt.Errorf("credentials is nil")
111+
}
113112
table := tables.NewTable()
114-
table.AddRow("ID", utils.PtrString(credentials.Id))
113+
table.AddRow("ID", credentials.Id)
115114
table.AddSeparator()
116115
// The username field cannot be set by the user so we only display it if it's not returned empty
117-
if credentials.HasRaw() && credentials.Raw.Credentials != nil {
118-
if username := credentials.Raw.Credentials.Username; username != nil && *username != "" {
119-
table.AddRow("USERNAME", *username)
116+
if credentials.HasRaw() {
117+
if username := credentials.Raw.Credentials.Username; username != "" {
118+
table.AddRow("USERNAME", username)
120119
table.AddSeparator()
121120
}
122-
table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password))
121+
table.AddRow("PASSWORD", credentials.Raw.Credentials.Password)
123122
table.AddSeparator()
124123
table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri))
125124
table.AddSeparator()
126-
table.AddRow("HOST", utils.PtrString(credentials.Raw.Credentials.Host))
125+
table.AddRow("HOST", credentials.Raw.Credentials.Host)
127126
hosts := credentials.Raw.Credentials.Hosts
128-
if hosts != nil && len(*hosts) > 0 {
127+
if len(hosts) > 0 {
129128
table.AddSeparator()
130-
table.AddRow("HOSTS", strings.Join(*hosts, "\n"))
129+
table.AddRow("HOSTS", strings.Join(hosts, "\n"))
131130
}
132131
}
133132
err := table.Display(p)

0 commit comments

Comments
 (0)