Skip to content

Commit 8c9edfa

Browse files
feat(opensearch): region adjustments and migration to new SDK structure (#1474)
relates to STACKITTCLI-372
1 parent f4e5858 commit 8c9edfa

27 files changed

Lines changed: 501 additions & 549 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: 21 additions & 19 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
@@ -77,7 +76,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7776
return fmt.Errorf("create OpenSearch credentials: %w", err)
7877
}
7978

80-
return outputResult(params.Printer, model.OutputFormat, model.ShowPassword, instanceLabel, resp)
79+
return outputResult(params.Printer, *model, instanceLabel, resp)
8180
},
8281
}
8382
configureFlags(cmd)
@@ -109,35 +108,38 @@ 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

116-
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 {
115+
func outputResult(p *print.Printer, model inputModel, instanceLabel string, resp *opensearch.CredentialsResponse) error {
116+
if model.GlobalFlagModel == nil {
117+
return fmt.Errorf("no global flags defined")
118+
}
119+
if resp == nil || resp.Raw == nil {
118120
return fmt.Errorf("response or response content is nil")
119121
}
120122

121-
if !showPassword {
122-
resp.Raw.Credentials.Password = utils.Ptr("hidden")
123+
if !model.ShowPassword {
124+
resp.Raw.Credentials.Password = "hidden"
123125
}
124126

125-
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))
127+
return p.OutputResult(model.OutputFormat, resp, func() error {
128+
p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, resp.Id)
127129
// 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)
130+
if resp.HasRaw() {
131+
if username := resp.Raw.Credentials.Username; username != "" {
132+
p.Outputf("Username: %s\n", username)
131133
}
132-
if !showPassword {
134+
if !model.ShowPassword {
133135
p.Outputf("Password: <hidden>\n")
134136
} else {
135-
p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password))
137+
p.Outputf("Password: %s\n", resp.Raw.Credentials.Password)
136138
}
137-
p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host))
138-
p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port))
139+
p.Outputf("Host: %s\n", resp.Raw.Credentials.Host)
140+
p.Outputf("Port: %d\n", resp.Raw.Credentials.Port)
139141
}
140-
p.Outputf("URI: %s\n", *resp.Uri)
142+
p.Outputf("URI: %s\n", resp.Uri)
141143
return nil
142144
})
143145
}

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

Lines changed: 25 additions & 39 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)
@@ -165,8 +169,7 @@ func TestBuildRequest(t *testing.T) {
165169

166170
func TestOutputResult(t *testing.T) {
167171
type args struct {
168-
outputFormat string
169-
showPassword bool
172+
model inputModel
170173
instanceLabel string
171174
resp *opensearch.CredentialsResponse
172175
}
@@ -181,40 +184,20 @@ func TestOutputResult(t *testing.T) {
181184
wantErr: true,
182185
},
183186
{
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",
187+
name: "set uri but no raw in response",
204188
args: args{
205189
resp: &opensearch.CredentialsResponse{
206-
Raw: &opensearch.RawCredentials{
207-
Credentials: &opensearch.Credentials{},
208-
},
190+
Uri: "https://opensearch.example.com",
209191
},
210192
},
211193
wantErr: true,
212194
},
213195
{
214-
name: "set uri but no raw in response",
196+
name: "empty response should not cause panic when password should be hidden",
215197
args: args{
216-
resp: &opensearch.CredentialsResponse{
217-
Uri: utils.Ptr("https://opensearch.example.com"),
198+
model: inputModel{
199+
GlobalFlagModel: &globalflags.GlobalFlagModel{},
200+
ShowPassword: false,
218201
},
219202
},
220203
wantErr: true,
@@ -224,9 +207,12 @@ func TestOutputResult(t *testing.T) {
224207
args: args{
225208
resp: &opensearch.CredentialsResponse{
226209
Raw: &opensearch.RawCredentials{
227-
Credentials: &opensearch.Credentials{},
210+
Credentials: opensearch.Credentials{},
228211
},
229-
Uri: utils.Ptr("https://opensearch.example.com"),
212+
Uri: "https://opensearch.example.com",
213+
},
214+
model: inputModel{
215+
GlobalFlagModel: &globalflags.GlobalFlagModel{},
230216
},
231217
},
232218
wantErr: false,
@@ -235,7 +221,7 @@ func TestOutputResult(t *testing.T) {
235221
params := testparams.NewTestParams()
236222
for _, tt := range tests {
237223
t.Run(tt.name, func(t *testing.T) {
238-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.showPassword, tt.args.instanceLabel, tt.args.resp); (err != nil) != tt.wantErr {
224+
if err := outputResult(params.Printer, tt.args.model, tt.args.instanceLabel, tt.args.resp); (err != nil) != tt.wantErr {
239225
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
240226
}
241227
})

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)

0 commit comments

Comments
 (0)