Skip to content

Commit 5a3aa3b

Browse files
committed
feat(redis): region adjustments and migration to new SDK structure
relates to STACKITCLI-405 and STACKITCLI-376
1 parent c54ca1a commit 5a3aa3b

27 files changed

Lines changed: 317 additions & 303 deletions

docs/stackit_redis_instance_create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ stackit redis instance create [flags]
3030
--enable-monitoring Enable monitoring
3131
--graphite string Graphite host
3232
-h, --help Help for "stackit redis 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

docs/stackit_redis_instance_update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ stackit redis instance update INSTANCE_ID [flags]
2727
--enable-monitoring Enable monitoring
2828
--graphite string Graphite host
2929
-h, --help Help for "stackit redis 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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ require (
272272
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0
273273
github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0
274274
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0
275-
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6
275+
github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0
276276
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.9.0
277277
github.com/subosito/gotenv v1.6.0 // indirect
278278
golang.org/x/sys v0.43.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQ
634634
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw=
635635
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 h1:/8lmviszgrB+0Cz7HdhFELyTiTeqIs7LfnI6sNX4rW8=
636636
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0/go.mod h1:hnhvlLX1Y71R8KIQqLBeoSZqkU5ZJOG0J4wz0LeUdaw=
637-
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 h1:CXM9cZ9WeTyJd+Aw/hnJnDsKRVAQi4qgtd0RJ3zoPwo=
638-
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6/go.mod h1:KJNceOHRefjku1oVBoHG7idCS/SeW42WJ+55bN3AxrQ=
637+
github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0 h1:ckYMRXAGE2/vaxPeNGEuun9AGcFn/8xuu0ytfsiqfWU=
638+
github.com/stackitcloud/stackit-sdk-go/services/redis v1.1.0/go.mod h1:yjej6QfYoYdRIyKXlmbVz8fZYxbuUdl+QBkvLDPgA4k=
639639
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0 h1:JPP6a0ME1tZXr4iB69d/LtJsCAr58ENBadFaK9f48/c=
640640
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.24.0/go.mod h1:NEz3f+GV5G++BE9/MmZCsXJyCih7jtg0pZuSyG2sLEs=
641641
github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3 h1:AiGNJmpQ/f9cglaIQQ4SyePbtCI3K1DQLNvqVN9jKSo=

internal/cmd/redis/credentials/create/create.go

Lines changed: 12 additions & 15 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/redis"
20+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v2api"
2121
)
2222

2323
const (
@@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5858
return err
5959
}
6060

61-
instanceLabel, err := redisUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId)
61+
instanceLabel, err := redisUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.Region)
6262
if err != nil {
6363
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6464
instanceLabel = model.InstanceId
@@ -109,7 +109,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
109109
}
110110

111111
func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APIClient) redis.ApiCreateCredentialsRequest {
112-
req := apiClient.CreateCredentials(ctx, model.ProjectId, model.InstanceId)
112+
req := apiClient.DefaultAPI.CreateCredentials(ctx, model.ProjectId, model.Region, model.InstanceId)
113113
return req
114114
}
115115

@@ -122,30 +122,27 @@ func outputResult(p *print.Printer, model inputModel, instanceLabel string, resp
122122
}
123123
if !model.ShowPassword {
124124
if resp.Raw == nil {
125-
resp.Raw = &redis.RawCredentials{}
125+
resp.Raw = &redis.RawCredentials{Credentials: redis.Credentials{}}
126126
}
127-
if resp.Raw.Credentials == nil {
128-
resp.Raw.Credentials = &redis.Credentials{}
129-
}
130-
resp.Raw.Credentials.Password = utils.Ptr("hidden")
127+
resp.Raw.Credentials.Password = "hidden"
131128
}
132129

133130
return p.OutputResult(model.OutputFormat, resp, func() error {
134-
p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id))
131+
p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, resp.Id)
135132
// The username field cannot be set by the user, so we only display it if it's not returned empty
136-
if resp.HasRaw() && resp.Raw.Credentials != nil {
137-
if username := resp.Raw.Credentials.Username; username != nil && *username != "" {
138-
p.Outputf("Username: %s\n", utils.PtrString(username))
133+
if resp.HasRaw() {
134+
if username := resp.Raw.Credentials.Username; username != "" {
135+
p.Outputf("Username: %s\n", username)
139136
}
140137
if !model.ShowPassword {
141138
p.Outputf("Password: <hidden>\n")
142139
} else {
143-
p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password))
140+
p.Outputf("Password: %s\n", resp.Raw.Credentials.Password)
144141
}
145-
p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host))
142+
p.Outputf("Host: %s\n", resp.Raw.Credentials.Host)
146143
p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port))
147144
}
148-
p.Outputf("URI: %s\n", utils.PtrString(resp.Uri))
145+
p.Outputf("URI: %s\n", resp.Uri)
149146
return nil
150147
})
151148
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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/redis"
10+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
@@ -19,14 +19,16 @@ var projectIdFlag = globalflags.ProjectIdFlag
1919
type testCtxKey struct{}
2020

2121
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
22-
var testClient = &redis.APIClient{}
22+
var testClient = &redis.APIClient{DefaultAPI: &redis.DefaultAPIService{}}
2323
var testProjectId = uuid.NewString()
2424
var testInstanceId = uuid.NewString()
25+
var testRegion = "eu01"
2526

2627
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2728
flagValues := map[string]string{
28-
projectIdFlag: testProjectId,
29-
instanceIdFlag: testInstanceId,
29+
projectIdFlag: testProjectId,
30+
instanceIdFlag: testInstanceId,
31+
globalflags.RegionFlag: testRegion,
3032
}
3133
for _, mod := range mods {
3234
mod(flagValues)
@@ -39,6 +41,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3941
GlobalFlagModel: &globalflags.GlobalFlagModel{
4042
ProjectId: testProjectId,
4143
Verbosity: globalflags.VerbosityDefault,
44+
Region: testRegion,
4245
},
4346
InstanceId: testInstanceId,
4447
}
@@ -49,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4952
}
5053

5154
func fixtureRequest(mods ...func(request *redis.ApiCreateCredentialsRequest)) redis.ApiCreateCredentialsRequest {
52-
request := testClient.CreateCredentials(testCtx, testProjectId, testInstanceId)
55+
request := testClient.DefaultAPI.CreateCredentials(testCtx, testProjectId, testRegion, testInstanceId)
5356
for _, mod := range mods {
5457
mod(&request)
5558
}
@@ -154,7 +157,7 @@ func TestBuildRequest(t *testing.T) {
154157
request := buildRequest(testCtx, tt.model, testClient)
155158

156159
diff := cmp.Diff(request, tt.expectedRequest,
157-
cmp.AllowUnexported(tt.expectedRequest),
160+
cmp.AllowUnexported(tt.expectedRequest, redis.DefaultAPIService{}),
158161
cmpopts.EquateComparable(testCtx),
159162
)
160163
if diff != "" {

internal/cmd/redis/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/redis"
20+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v2api"
2121
)
2222

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

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

65-
credentialsLabel, err := redisUtils.GetCredentialsUsername(ctx, apiClient, model.ProjectId, model.InstanceId, model.CredentialsId)
65+
credentialsLabel, err := redisUtils.GetCredentialsUsername(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.CredentialsId, model.Region)
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 *redis.APIClient) redis.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/redis/credentials/delete/delete_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +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/redis"
13+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v2api"
1414
)
1515

1616
var projectIdFlag = globalflags.ProjectIdFlag
1717

1818
type testCtxKey struct{}
1919

2020
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &redis.APIClient{}
21+
var testClient = &redis.APIClient{DefaultAPI: &redis.DefaultAPIService{}}
2222
var testProjectId = uuid.NewString()
2323
var testInstanceId = uuid.NewString()
2424
var testCredentialsId = uuid.NewString()
25+
var testRegion = "eu01"
2526

2627
func fixtureArgValues(mods ...func(argValues []string)) []string {
2728
argValues := []string{
@@ -35,8 +36,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3536

3637
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3738
flagValues := map[string]string{
38-
projectIdFlag: testProjectId,
39-
instanceIdFlag: testInstanceId,
39+
projectIdFlag: testProjectId,
40+
instanceIdFlag: testInstanceId,
41+
globalflags.RegionFlag: testRegion,
4042
}
4143
for _, mod := range mods {
4244
mod(flagValues)
@@ -49,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4951
GlobalFlagModel: &globalflags.GlobalFlagModel{
5052
ProjectId: testProjectId,
5153
Verbosity: globalflags.VerbosityDefault,
54+
Region: testRegion,
5255
},
5356
InstanceId: testInstanceId,
5457
CredentialsId: testCredentialsId,
@@ -60,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6063
}
6164

6265
func fixtureRequest(mods ...func(request *redis.ApiDeleteCredentialsRequest)) redis.ApiDeleteCredentialsRequest {
63-
request := testClient.DeleteCredentials(testCtx, testProjectId, testInstanceId, testCredentialsId)
66+
request := testClient.DefaultAPI.DeleteCredentials(testCtx, testProjectId, testRegion, testInstanceId, testCredentialsId)
6467
for _, mod := range mods {
6568
mod(&request)
6669
}
@@ -187,7 +190,7 @@ func TestBuildRequest(t *testing.T) {
187190
request := buildRequest(testCtx, tt.model, testClient)
188191

189192
diff := cmp.Diff(request, tt.expectedRequest,
190-
cmp.AllowUnexported(tt.expectedRequest),
193+
cmp.AllowUnexported(tt.expectedRequest, redis.DefaultAPIService{}),
191194
cmpopts.EquateComparable(testCtx),
192195
)
193196
if diff != "" {

internal/cmd/redis/credentials/describe/describe.go

Lines changed: 7 additions & 7 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/redis"
20+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v2api"
2121
)
2222

2323
const (
@@ -99,7 +99,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
9999
}
100100

101101
func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APIClient) redis.ApiGetCredentialsRequest {
102-
req := apiClient.GetCredentials(ctx, model.ProjectId, model.InstanceId, model.CredentialsId)
102+
req := apiClient.DefaultAPI.GetCredentials(ctx, model.ProjectId, model.Region, model.InstanceId, model.CredentialsId)
103103
return req
104104
}
105105

@@ -110,15 +110,15 @@ func outputResult(p *print.Printer, outputFormat string, credentials *redis.Cred
110110

111111
return p.OutputResult(outputFormat, credentials, func() error {
112112
table := tables.NewTable()
113-
table.AddRow("ID", utils.PtrString(credentials.Id))
113+
table.AddRow("ID", credentials.Id)
114114
table.AddSeparator()
115115
// The username field cannot be set by the user so we only display it if it's not returned empty
116-
if credentials.HasRaw() && credentials.Raw.Credentials != nil {
117-
if username := credentials.Raw.Credentials.Username; username != nil && *username != "" {
118-
table.AddRow("USERNAME", *username)
116+
if credentials.HasRaw() {
117+
if username := credentials.Raw.Credentials.Username; username != "" {
118+
table.AddRow("USERNAME", username)
119119
table.AddSeparator()
120120
}
121-
table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password))
121+
table.AddRow("PASSWORD", credentials.Raw.Credentials.Password)
122122
table.AddSeparator()
123123
table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri))
124124
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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/redis"
10+
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v2api"
1111

1212
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
@@ -19,10 +19,11 @@ var projectIdFlag = globalflags.ProjectIdFlag
1919
type testCtxKey struct{}
2020

2121
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
22-
var testClient = &redis.APIClient{}
22+
var testClient = &redis.APIClient{DefaultAPI: &redis.DefaultAPIService{}}
2323
var testProjectId = uuid.NewString()
2424
var testInstanceId = uuid.NewString()
2525
var testCredentialsId = uuid.NewString()
26+
var testRegion = "eu01"
2627

2728
func fixtureArgValues(mods ...func(argValues []string)) []string {
2829
argValues := []string{
@@ -36,8 +37,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {
3637

3738
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3839
flagValues := map[string]string{
39-
projectIdFlag: testProjectId,
40-
instanceIdFlag: testInstanceId,
40+
projectIdFlag: testProjectId,
41+
instanceIdFlag: testInstanceId,
42+
globalflags.RegionFlag: testRegion,
4143
}
4244
for _, mod := range mods {
4345
mod(flagValues)
@@ -50,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5052
GlobalFlagModel: &globalflags.GlobalFlagModel{
5153
ProjectId: testProjectId,
5254
Verbosity: globalflags.VerbosityDefault,
55+
Region: testRegion,
5356
},
5457
InstanceId: testInstanceId,
5558
CredentialsId: testCredentialsId,
@@ -61,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6164
}
6265

6366
func fixtureRequest(mods ...func(request *redis.ApiGetCredentialsRequest)) redis.ApiGetCredentialsRequest {
64-
request := testClient.GetCredentials(testCtx, testProjectId, testInstanceId, testCredentialsId)
67+
request := testClient.DefaultAPI.GetCredentials(testCtx, testProjectId, testRegion, testInstanceId, testCredentialsId)
6568
for _, mod := range mods {
6669
mod(&request)
6770
}
@@ -188,7 +191,7 @@ func TestBuildRequest(t *testing.T) {
188191
request := buildRequest(testCtx, tt.model, testClient)
189192

190193
diff := cmp.Diff(request, tt.expectedRequest,
191-
cmp.AllowUnexported(tt.expectedRequest),
194+
cmp.AllowUnexported(tt.expectedRequest, redis.DefaultAPIService{}),
192195
cmpopts.EquateComparable(testCtx),
193196
)
194197
if diff != "" {

0 commit comments

Comments
 (0)