diff --git a/go.mod b/go.mod index bbeb1c719..d6a62f130 100644 --- a/go.mod +++ b/go.mod @@ -22,13 +22,13 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3 - github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 + github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0 github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1 github.com/stackitcloud/stackit-sdk-go/services/logs v0.5.2 github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.8 github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.24.6 github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 - github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.18.5 + github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.23.0 github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3 github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.14.3 github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 diff --git a/go.sum b/go.sum index a7ea442e3..debdbf812 100644 --- a/go.sum +++ b/go.sum @@ -596,8 +596,6 @@ github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YE github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I= github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA= github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA= -github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0 h1:V9+885qkSv621rZZatg1YE5ENM1ElALxQDJsh+hDIUg= -github.com/stackitcloud/stackit-sdk-go/services/alb v0.10.0/go.mod h1:V6+MolxM/M2FWyWZA+FRFKEzzUe10MU9eEVfMvxHGi8= github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2 h1:hGzfOJjlCRoFpri5eYIiwhE27qu02pKZLprKvbsTC/w= github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2/go.mod h1:eK6oRB5Tmpt6KbXQ4UYBGg2LgW5bPtVoncL9E8JSRww= github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu04j5tj6nfZ2r0l6v4VXC0/tYOGe4sA5Addra8= @@ -610,8 +608,8 @@ github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 h1:TxChb2qbO82JiQEBY github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3/go.mod h1:KVWvQHb7CQLD9DzA4Np3WmakiCCsrHaCXvFEnOQ7nPk= github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3 h1:VIjkSofZz9utOOkBdNZCIb07P/JdKc1kHV1P8Rq9dLc= github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3/go.mod h1:EJk1Ss9GTel2NPIu/w3+x9XcQcEd2k3ibea5aQDzVhQ= -github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 h1:W57+XRa8wTLsi5CV9Tqa7mGgt/PvlRM//RurXSmvII8= -github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5/go.mod h1:lTWjW57eAq1bwfM6nsNinhoBr3MHFW/GaFasdAsYfDM= +github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0 h1:H4V3H8qSKOaOalIrf4nAPDHhXnHYGs6SDGuK8Zj41Zo= +github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0/go.mod h1:Ts06id0KejUlQWbpR+/rm+tKng6QkTuFV1VQTPJ4dA4= github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1 h1:7ZSrwps/zI41rl+xYkG4osld8cyAwssyl/UZ/Iu/F2g= github.com/stackitcloud/stackit-sdk-go/services/intake v0.7.1/go.mod h1:ZIvwBZwEMFO+YfJLCNXqabslI0Fp9zxV7ZBwlZjk7uE= github.com/stackitcloud/stackit-sdk-go/services/kms v1.3.2 h1:2ulSL2IkIAKND59eAjbEhVkOoBMyvm48ojwz1a3t0U0= @@ -638,8 +636,8 @@ github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 h1:/8lmviszgrB+ github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0/go.mod h1:hnhvlLX1Y71R8KIQqLBeoSZqkU5ZJOG0J4wz0LeUdaw= github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 h1:CXM9cZ9WeTyJd+Aw/hnJnDsKRVAQi4qgtd0RJ3zoPwo= github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6/go.mod h1:KJNceOHRefjku1oVBoHG7idCS/SeW42WJ+55bN3AxrQ= -github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.18.5 h1:MZ5aTO2NQ1Jecmi67ByGskve5nKXHl91fE+z+vFjxt4= -github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.18.5/go.mod h1:CJLmdqWvJm5/3+lXPDKu8k4WXs2UG8euGoqQX5xE79k= +github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.23.0 h1:u2C3oHNcc41Ba5cUqSPuqviDrYSRhpaC5+ELbuHHdwM= +github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.23.0/go.mod h1:NEz3f+GV5G++BE9/MmZCsXJyCih7jtg0pZuSyG2sLEs= github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3 h1:AiGNJmpQ/f9cglaIQQ4SyePbtCI3K1DQLNvqVN9jKSo= github.com/stackitcloud/stackit-sdk-go/services/runcommand v1.4.3/go.mod h1:U/q0V89fvCF2O1ZJfi68/Chie9YY/5s7xBHI1Klq7wA= github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.14.3 h1:3hZSg3z+4AXa5LbR2Vl38VmSA83ABItE63E53LuyWv8= diff --git a/internal/cmd/affinity-groups/create/create.go b/internal/cmd/affinity-groups/create/create.go index 0a38cd35f..6528e54f8 100644 --- a/internal/cmd/affinity-groups/create/create.go +++ b/internal/cmd/affinity-groups/create/create.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -88,11 +88,11 @@ func configureFlags(cmd *cobra.Command) { } func buildRequest(ctx context.Context, model inputModel, apiClient *iaas.APIClient) iaas.ApiCreateAffinityGroupRequest { - req := apiClient.CreateAffinityGroup(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreateAffinityGroup(ctx, model.ProjectId, model.Region) req = req.CreateAffinityGroupPayload( iaas.CreateAffinityGroupPayload{ - Name: utils.Ptr(model.Name), - Policy: utils.Ptr(model.Policy), + Name: model.Name, + Policy: model.Policy, }, ) return req diff --git a/internal/cmd/affinity-groups/create/create_test.go b/internal/cmd/affinity-groups/create/create_test.go index 38f958e6a..e547a4990 100644 --- a/internal/cmd/affinity-groups/create/create_test.go +++ b/internal/cmd/affinity-groups/create/create_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -26,7 +26,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() ) @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateAffinityGroupRequest)) iaas.ApiCreateAffinityGroupRequest { - request := testClient.CreateAffinityGroup(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateAffinityGroup(testCtx, testProjectId, testRegion) request = request.CreateAffinityGroupPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -71,8 +71,8 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateAffinityGroupRequest)) i func fixturePayload(mods ...func(payload *iaas.CreateAffinityGroupPayload)) iaas.CreateAffinityGroupPayload { payload := iaas.CreateAffinityGroupPayload{ - Name: utils.Ptr(testName), - Policy: utils.Ptr(testPolicy), + Name: testName, + Policy: testPolicy, } for _, mod := range mods { mod(&payload) @@ -147,7 +147,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx)) + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{})) if diff != "" { t.Fatalf("Request does not match: %s", diff) } @@ -173,9 +173,9 @@ func TestOutputResult(t *testing.T) { model: *fixtureInputModel(), response: iaas.AffinityGroup{ Id: utils.Ptr(testProjectId), - Members: utils.Ptr([]string{uuid.NewString(), uuid.NewString()}), - Name: utils.Ptr("test-project"), - Policy: utils.Ptr("hard-affinity"), + Members: []string{uuid.NewString(), uuid.NewString()}, + Name: "test-project", + Policy: "hard-affinity", }, isValid: true, }, diff --git a/internal/cmd/affinity-groups/delete/delete.go b/internal/cmd/affinity-groups/delete/delete.go index d37005653..87f6b2487 100644 --- a/internal/cmd/affinity-groups/delete/delete.go +++ b/internal/cmd/affinity-groups/delete/delete.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -60,7 +60,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { projectLabel = model.ProjectId } - affinityGroupLabel, err := iaasUtils.GetAffinityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.AffinityGroupId) + affinityGroupLabel, err := iaasUtils.GetAffinityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.AffinityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get affinity group name: %v", err) affinityGroupLabel = model.AffinityGroupId @@ -87,7 +87,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } func buildRequest(ctx context.Context, model inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteAffinityGroupRequest { - return apiClient.DeleteAffinityGroup(ctx, model.ProjectId, model.Region, model.AffinityGroupId) + return apiClient.DefaultAPI.DeleteAffinityGroup(ctx, model.ProjectId, model.Region, model.AffinityGroupId) } func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputModel, error) { diff --git a/internal/cmd/affinity-groups/delete/delete_test.go b/internal/cmd/affinity-groups/delete/delete_test.go index a726ba95e..67ed31ab9 100644 --- a/internal/cmd/affinity-groups/delete/delete_test.go +++ b/internal/cmd/affinity-groups/delete/delete_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), &testCtxKey{}, "test") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testAffinityGroupId = uuid.NewString() @@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteAffinityGroupRequest)) iaas.ApiDeleteAffinityGroupRequest { - request := testClient.DeleteAffinityGroup(testCtx, testProjectId, testRegion, testAffinityGroupId) + request := testClient.DefaultAPI.DeleteAffinityGroup(testCtx, testProjectId, testRegion, testAffinityGroupId) for _, mod := range mods { mod(&request) } @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/affinity-groups/describe/describe.go b/internal/cmd/affinity-groups/describe/describe.go index 7fda51352..a2f377f36 100644 --- a/internal/cmd/affinity-groups/describe/describe.go +++ b/internal/cmd/affinity-groups/describe/describe.go @@ -3,11 +3,12 @@ package describe import ( "context" "fmt" + "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -70,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } func buildRequest(ctx context.Context, model inputModel, apiClient *iaas.APIClient) iaas.ApiGetAffinityGroupRequest { - return apiClient.GetAffinityGroup(ctx, model.ProjectId, model.Region, model.AffinityGroupId) + return apiClient.DefaultAPI.GetAffinityGroup(ctx, model.ProjectId, model.Region, model.AffinityGroupId) } func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputModel, error) { @@ -101,16 +102,12 @@ func outputResult(p *print.Printer, model inputModel, resp iaas.AffinityGroup) e table.AddRow("ID", utils.PtrString(resp.Id)) table.AddSeparator() } - if resp.Name != nil { - table.AddRow("NAME", utils.PtrString(resp.Name)) - table.AddSeparator() - } - if resp.Policy != nil { - table.AddRow("POLICY", utils.PtrString(resp.Policy)) - table.AddSeparator() - } + table.AddRow("NAME", resp.Name) + table.AddSeparator() + table.AddRow("POLICY", resp.Policy) + table.AddSeparator() if resp.HasMembers() { - table.AddRow("Members", utils.JoinStringPtr(resp.Members, ", ")) + table.AddRow("Members", strings.Join(resp.Members, ", ")) table.AddSeparator() } diff --git a/internal/cmd/affinity-groups/describe/describe_test.go b/internal/cmd/affinity-groups/describe/describe_test.go index b8229c446..116ed2f8f 100644 --- a/internal/cmd/affinity-groups/describe/describe_test.go +++ b/internal/cmd/affinity-groups/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), &testCtxKey{}, "test") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testAffinityGroupId = uuid.NewString() @@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetAffinityGroupRequest)) iaas.ApiGetAffinityGroupRequest { - request := testClient.GetAffinityGroup(testCtx, testProjectId, testRegion, testAffinityGroupId) + request := testClient.DefaultAPI.GetAffinityGroup(testCtx, testProjectId, testRegion, testAffinityGroupId) for _, mod := range mods { mod(&request) } @@ -173,7 +173,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/affinity-groups/list/list.go b/internal/cmd/affinity-groups/list/list.go index fb75bf2f3..006a94fb5 100644 --- a/internal/cmd/affinity-groups/list/list.go +++ b/internal/cmd/affinity-groups/list/list.go @@ -10,7 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -88,7 +88,7 @@ func configureFlags(cmd *cobra.Command) { } func buildRequest(ctx context.Context, model inputModel, apiClient *iaas.APIClient) iaas.ApiListAffinityGroupsRequest { - return apiClient.ListAffinityGroups(ctx, model.ProjectId, model.Region) + return apiClient.DefaultAPI.ListAffinityGroups(ctx, model.ProjectId, model.Region) } func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) { @@ -125,8 +125,8 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, items []i for _, item := range items { table.AddRow( utils.PtrString(item.Id), - utils.PtrString(item.Name), - utils.PtrString(item.Policy), + item.Name, + item.Policy, ) table.AddSeparator() } diff --git a/internal/cmd/affinity-groups/list/list_test.go b/internal/cmd/affinity-groups/list/list_test.go index 88f5ca635..973445dcd 100644 --- a/internal/cmd/affinity-groups/list/list_test.go +++ b/internal/cmd/affinity-groups/list/list_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -26,7 +26,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() ) @@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListAffinityGroupsRequest)) iaas.ApiListAffinityGroupsRequest { - request := testClient.ListAffinityGroups(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListAffinityGroups(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -132,7 +132,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx)) + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{})) if diff != "" { t.Fatalf("Request does not match: %s", diff) } diff --git a/internal/cmd/image/create/create.go b/internal/cmd/image/create/create.go index fd1a20975..09568f247 100644 --- a/internal/cmd/image/create/create.go +++ b/internal/cmd/image/create/create.go @@ -13,7 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -72,11 +72,11 @@ type imageConfig struct { type inputModel struct { *globalflags.GlobalFlagModel - Id *string + Id string Name string DiskFormat string LocalFilePath string - Labels *map[string]string + Labels map[string]any Config *imageConfig MinDiskSize *int64 MinRam *int64 @@ -146,7 +146,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !ok { return fmt.Errorf("create image: no upload URL has been provided") } - if err := uploadAsync(ctx, params.Printer, model, file, url); err != nil { + if err := uploadAsync(ctx, params.Printer, model, file, *url); err != nil { return err } @@ -304,7 +304,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, Name: name, DiskFormat: flags.FlagToStringValue(p, cmd, diskFormatFlag), LocalFilePath: flags.FlagToStringValue(p, cmd, localFilePathFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelsFlag), NoProgressIndicator: flags.FlagToBoolPointer(p, cmd, noProgressIndicatorFlag), Config: &imageConfig{ Architecture: flags.FlagToStringPointer(p, cmd, architectureFlag), @@ -332,16 +332,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateImageRequest { - request := apiClient.CreateImage(ctx, model.ProjectId, model.Region). + request := apiClient.DefaultAPI.CreateImage(ctx, model.ProjectId, model.Region). CreateImagePayload(createPayload(ctx, model)) return request } func createPayload(_ context.Context, model *inputModel) iaas.CreateImagePayload { payload := iaas.CreateImagePayload{ - DiskFormat: &model.DiskFormat, - Name: &model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + DiskFormat: model.DiskFormat, + Name: model.Name, + Labels: model.Labels, MinDiskSize: model.MinDiskSize, MinRam: model.MinRam, Protected: model.Protected, @@ -356,34 +356,34 @@ func createPayload(_ context.Context, model *inputModel) iaas.CreateImagePayload payload.Config.BootMenu = model.Config.BootMenu } if config.CdromBus != nil { - payload.Config.CdromBus = iaas.NewNullableString(model.Config.CdromBus) + payload.Config.CdromBus = *iaas.NewNullableString(model.Config.CdromBus) } if config.DiskBus != nil { - payload.Config.DiskBus = iaas.NewNullableString(config.DiskBus) + payload.Config.DiskBus = *iaas.NewNullableString(config.DiskBus) } if config.NicModel != nil { - payload.Config.NicModel = iaas.NewNullableString(config.NicModel) + payload.Config.NicModel = *iaas.NewNullableString(config.NicModel) } if config.OperatingSystem != nil { payload.Config.OperatingSystem = config.OperatingSystem } if config.OperatingSystemDistro != nil { - payload.Config.OperatingSystemDistro = iaas.NewNullableString(config.OperatingSystemDistro) + payload.Config.OperatingSystemDistro = *iaas.NewNullableString(config.OperatingSystemDistro) } if config.OperatingSystemVersion != nil { - payload.Config.OperatingSystemVersion = iaas.NewNullableString(config.OperatingSystemVersion) + payload.Config.OperatingSystemVersion = *iaas.NewNullableString(config.OperatingSystemVersion) } if config.RescueBus != nil { - payload.Config.RescueBus = iaas.NewNullableString(config.RescueBus) + payload.Config.RescueBus = *iaas.NewNullableString(config.RescueBus) } if config.RescueDevice != nil { - payload.Config.RescueDevice = iaas.NewNullableString(config.RescueDevice) + payload.Config.RescueDevice = *iaas.NewNullableString(config.RescueDevice) } if config.SecureBoot != nil { payload.Config.SecureBoot = config.SecureBoot } if config.VideoModel != nil { - payload.Config.VideoModel = iaas.NewNullableString(config.VideoModel) + payload.Config.VideoModel = *iaas.NewNullableString(config.VideoModel) } if config.VirtioScsi != nil { payload.Config.VirtioScsi = config.VirtioScsi @@ -403,7 +403,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *iaas.ImageCreateRes } return p.OutputResult(outputFormat, resp, func() error { - p.Outputf("Created image %q with id %s\n", model.Name, utils.PtrString(model.Id)) + p.Outputf("Created image %q with id %s\n", model.Name, model.Id) return nil }) } diff --git a/internal/cmd/image/create/create_test.go b/internal/cmd/image/create/create_test.go index db11a69ea..2e4ba2ee8 100644 --- a/internal/cmd/image/create/create_test.go +++ b/internal/cmd/image/create/create_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -47,7 +47,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() ) @@ -84,8 +84,8 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st return flagValues } -func parseLabels(labelstring string) map[string]string { - labels := map[string]string{} +func parseLabels(labelstring string) map[string]any { + labels := map[string]any{} for _, part := range strings.Split(labelstring, ",") { v := strings.Split(part, "=") labels[v[0]] = v[1] @@ -104,7 +104,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Name: testName, DiskFormat: testDiskFormat, LocalFilePath: testLocalImagePath, - Labels: utils.Ptr(parseLabels(testLabels)), + Labels: parseLabels(testLabels), Config: &imageConfig{ Architecture: utils.Ptr(testArchitecture), BootMenu: utils.Ptr(testBootmenu), @@ -136,28 +136,28 @@ func fixtureCreatePayload(mods ...func(payload *iaas.CreateImagePayload)) (paylo Config: &iaas.ImageConfig{ Architecture: utils.Ptr(testArchitecture), BootMenu: utils.Ptr(testBootmenu), - CdromBus: iaas.NewNullableString(utils.Ptr(testCdRomBus)), - DiskBus: iaas.NewNullableString(utils.Ptr(testDiskBus)), - NicModel: iaas.NewNullableString(utils.Ptr(testNicModel)), + CdromBus: *iaas.NewNullableString(utils.Ptr(testCdRomBus)), + DiskBus: *iaas.NewNullableString(utils.Ptr(testDiskBus)), + NicModel: *iaas.NewNullableString(utils.Ptr(testNicModel)), OperatingSystem: utils.Ptr(testOperatingSystem), - OperatingSystemDistro: iaas.NewNullableString(utils.Ptr(testOperatingSystemDistro)), - OperatingSystemVersion: iaas.NewNullableString(utils.Ptr(testOperatingSystemVersion)), - RescueBus: iaas.NewNullableString(utils.Ptr(testRescueBus)), - RescueDevice: iaas.NewNullableString(utils.Ptr(testRescueDevice)), + OperatingSystemDistro: *iaas.NewNullableString(utils.Ptr(testOperatingSystemDistro)), + OperatingSystemVersion: *iaas.NewNullableString(utils.Ptr(testOperatingSystemVersion)), + RescueBus: *iaas.NewNullableString(utils.Ptr(testRescueBus)), + RescueDevice: *iaas.NewNullableString(utils.Ptr(testRescueDevice)), SecureBoot: utils.Ptr(testSecureBoot), Uefi: utils.Ptr(testUefi), - VideoModel: iaas.NewNullableString(utils.Ptr(testVideoModel)), + VideoModel: *iaas.NewNullableString(utils.Ptr(testVideoModel)), VirtioScsi: utils.Ptr(testVirtioScsi), }, - DiskFormat: utils.Ptr(testDiskFormat), - Labels: &map[string]interface{}{ + DiskFormat: testDiskFormat, + Labels: map[string]any{ "foo": "FOO", "bar": "BAR", "baz": "BAZ", }, MinDiskSize: utils.Ptr(testDiskSize), MinRam: utils.Ptr(testRamSize), - Name: utils.Ptr(testName), + Name: testName, Protected: utils.Ptr(testProtected), } for _, mod := range mods { @@ -167,7 +167,7 @@ func fixtureCreatePayload(mods ...func(payload *iaas.CreateImagePayload)) (paylo } func fixtureRequest(mods ...func(request *iaas.ApiCreateImageRequest)) iaas.ApiCreateImageRequest { - request := testClient.CreateImage(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateImage(testCtx, testProjectId, testRegion) request = request.CreateImagePayload(fixtureCreatePayload()) @@ -241,7 +241,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = &map[string]string{ + model.Labels = map[string]any{ "foo": "bar", } }), @@ -308,7 +308,7 @@ func TestBuildRequest(t *testing.T) { model.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateImageRequest) { - *request = (*request).CreateImagePayload(fixtureCreatePayload(func(payload *iaas.CreateImagePayload) { + *request = request.CreateImagePayload(fixtureCreatePayload(func(payload *iaas.CreateImagePayload) { payload.Labels = nil })) }), @@ -319,8 +319,8 @@ func TestBuildRequest(t *testing.T) { model.Config.CdromBus = utils.Ptr("foobar") }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateImageRequest) { - *request = (*request).CreateImagePayload(fixtureCreatePayload(func(payload *iaas.CreateImagePayload) { - payload.Config.CdromBus = iaas.NewNullableString(utils.Ptr("foobar")) + *request = request.CreateImagePayload(fixtureCreatePayload(func(payload *iaas.CreateImagePayload) { + payload.Config.CdromBus = *iaas.NewNullableString(utils.Ptr("foobar")) })) }), }, @@ -330,7 +330,7 @@ func TestBuildRequest(t *testing.T) { model.Config.Uefi = false }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateImageRequest) { - *request = (*request).CreateImagePayload(fixtureCreatePayload(func(payload *iaas.CreateImagePayload) { + *request = request.CreateImagePayload(fixtureCreatePayload(func(payload *iaas.CreateImagePayload) { payload.Config.Uefi = utils.Ptr(false) })) }), @@ -342,7 +342,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/image/delete/delete.go b/internal/cmd/image/delete/delete.go index b41431710..82f5ecbf2 100644 --- a/internal/cmd/image/delete/delete.go +++ b/internal/cmd/image/delete/delete.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { projectLabel = model.ProjectId } - imageName, err := iaasUtils.GetImageName(ctx, apiClient, model.ProjectId, model.Region, model.ImageId) + imageName, err := iaasUtils.GetImageName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ImageId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get image name: %v", err) imageName = model.ImageId @@ -98,6 +98,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteImageRequest { - request := apiClient.DeleteImage(ctx, model.ProjectId, model.Region, model.ImageId) + request := apiClient.DefaultAPI.DeleteImage(ctx, model.ProjectId, model.Region, model.ImageId) return request } diff --git a/internal/cmd/image/delete/delete_test.go b/internal/cmd/image/delete/delete_test.go index 6b0b068ec..88ffcd16d 100644 --- a/internal/cmd/image/delete/delete_test.go +++ b/internal/cmd/image/delete/delete_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testImageId = uuid.NewString() ) @@ -54,7 +54,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteImageRequest)) iaas.ApiDeleteImageRequest { - request := testClient.DeleteImage(testCtx, testProjectId, testRegion, testImageId) + request := testClient.DefaultAPI.DeleteImage(testCtx, testProjectId, testRegion, testImageId) for _, mod := range mods { mod(&request) } @@ -182,7 +182,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/image/describe/describe.go b/internal/cmd/image/describe/describe.go index 9bcdd4ca5..1659dd002 100644 --- a/internal/cmd/image/describe/describe.go +++ b/internal/cmd/image/describe/describe.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetImageRequest { - request := apiClient.GetImage(ctx, model.ProjectId, model.Region, model.ImageId) + request := apiClient.DefaultAPI.GetImage(ctx, model.ProjectId, model.Region, model.ImageId) return request } @@ -99,18 +99,14 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.Image) error table.AddRow("ID", *id) table.AddSeparator() } - if name := resp.Name; name != nil { - table.AddRow("NAME", *name) - table.AddSeparator() - } + table.AddRow("NAME", resp.Name) + table.AddSeparator() if status := resp.Status; status != nil { table.AddRow("STATUS", *status) table.AddSeparator() } - if format := resp.DiskFormat; format != nil { - table.AddRow("FORMAT", *format) - table.AddSeparator() - } + table.AddRow("FORMAT", resp.DiskFormat) + table.AddSeparator() if diskSize := resp.MinDiskSize; diskSize != nil { table.AddRow("DISK SIZE", *diskSize) table.AddSeparator() @@ -128,11 +124,11 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.Image) error table.AddRow("OPERATING SYSTEM", *os) table.AddSeparator() } - if distro := config.OperatingSystemDistro; distro != nil && distro.IsSet() { + if distro := config.OperatingSystemDistro; distro.IsSet() { table.AddRow("OPERATING SYSTEM DISTRIBUTION", *distro.Get()) table.AddSeparator() } - if version := config.OperatingSystemVersion; version != nil && version.IsSet() { + if version := config.OperatingSystemVersion; version.IsSet() { table.AddRow("OPERATING SYSTEM VERSION", *version.Get()) table.AddSeparator() } @@ -142,9 +138,9 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.Image) error } } - if resp.Labels != nil && len(*resp.Labels) > 0 { + if resp.Labels != nil && len(resp.Labels) > 0 { labels := []string{} - for key, value := range *resp.Labels { + for key, value := range resp.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/image/describe/describe_test.go b/internal/cmd/image/describe/describe_test.go index ae79c51f9..1c740ef90 100644 --- a/internal/cmd/image/describe/describe_test.go +++ b/internal/cmd/image/describe/describe_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" ) @@ -23,7 +23,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testImageId = []string{uuid.NewString()} ) @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetImageRequest)) iaas.ApiGetImageRequest { - request := testClient.GetImage(testCtx, testProjectId, testRegion, testImageId[0]) + request := testClient.DefaultAPI.GetImage(testCtx, testProjectId, testRegion, testImageId[0]) for _, mod := range mods { mod(&request) } @@ -194,7 +194,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -230,24 +230,24 @@ func TestOutputResult(t *testing.T) { args: args{ resp: &iaas.Image{ Id: utils.Ptr(uuid.NewString()), - Name: utils.Ptr("Image"), + Name: "Image", Status: utils.Ptr("STATUS"), - DiskFormat: utils.Ptr("format"), + DiskFormat: "format", MinDiskSize: utils.Ptr(int64(0)), MinRam: utils.Ptr(int64(0)), Config: &iaas.ImageConfig{ Architecture: utils.Ptr("architecture"), OperatingSystem: utils.Ptr("os"), - OperatingSystemDistro: iaas.NewNullableString(utils.Ptr("os distro")), - OperatingSystemVersion: iaas.NewNullableString(utils.Ptr("0.00.0")), + OperatingSystemDistro: *iaas.NewNullableString(utils.Ptr("os distro")), + OperatingSystemVersion: *iaas.NewNullableString(utils.Ptr("0.00.0")), Uefi: utils.Ptr(true), }, - Labels: utils.Ptr(map[string]any{ + Labels: map[string]any{ "label1": true, "label2": false, "label3": 42, "foo": "bar", - }), + }, }, }, wantErr: false, diff --git a/internal/cmd/image/list/list.go b/internal/cmd/image/list/list.go index 26fccfa24..9accc8bbb 100644 --- a/internal/cmd/image/list/list.go +++ b/internal/cmd/image/list/list.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -135,7 +135,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListImagesRequest { - request := apiClient.ListImages(ctx, model.ProjectId, model.Region) + request := apiClient.DefaultAPI.ListImages(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { request = request.LabelSelector(*model.LabelSelector) } @@ -171,10 +171,10 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, items []i if v := cfg.OperatingSystem; v != nil { os = *v } - if v := cfg.OperatingSystemDistro; v != nil && v.IsSet() { + if v := cfg.OperatingSystemDistro; v.IsSet() { distro = *v.Get() } - if v := cfg.OperatingSystemVersion; v != nil && v.IsSet() { + if v := cfg.OperatingSystemVersion; v.IsSet() { version = *v.Get() } } @@ -186,14 +186,14 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, items []i } table.AddRow(utils.PtrString(item.Id), - utils.PtrString(item.Name), + item.Name, os, architecture, distro, version, scope, owner, - utils.JoinStringKeysPtr(*item.Labels, ",")) + utils.JoinStringKeysPtr(item.Labels, ",")) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/image/list/list_test.go b/internal/cmd/image/list/list_test.go index 417e1d6af..ab4a984e6 100644 --- a/internal/cmd/image/list/list_test.go +++ b/internal/cmd/image/list/list_test.go @@ -14,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -25,7 +25,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testLabels = "fooKey=fooValue,barKey=barValue,bazKey=bazValue" testLimit int64 = 10 @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListImagesRequest)) iaas.ApiListImagesRequest { - request := testClient.ListImages(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListImages(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabels) for _, mod := range mods { mod(&request) @@ -157,7 +157,7 @@ func TestBuildRequest(t *testing.T) { model.LabelSelector = utils.Ptr("") }), expectedRequest: fixtureRequest(func(request *iaas.ApiListImagesRequest) { - *request = (*request).LabelSelector("") + *request = request.LabelSelector("") }), }, { @@ -166,7 +166,7 @@ func TestBuildRequest(t *testing.T) { model.LabelSelector = utils.Ptr("foo=bar") }), expectedRequest: fixtureRequest(func(request *iaas.ApiListImagesRequest) { - *request = (*request).LabelSelector("foo=bar") + *request = request.LabelSelector("foo=bar") }), }, } @@ -176,7 +176,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/image/update/update.go b/internal/cmd/image/update/update.go index f039a1fac..9e8912778 100644 --- a/internal/cmd/image/update/update.go +++ b/internal/cmd/image/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -60,7 +60,7 @@ type inputModel struct { Id string Name *string DiskFormat *string - Labels *map[string]string + Labels map[string]any Config *imageConfig MinDiskSize *int64 MinRam *int64 @@ -134,7 +134,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { projectLabel = model.ProjectId } - imageLabel, err := iaasUtils.GetImageName(ctx, apiClient, model.ProjectId, model.Region, model.Id) + imageLabel, err := iaasUtils.GetImageName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.Id) if err != nil { params.Printer.Debug(print.WarningLevel, "cannot retrieve image name: %v", err) imageLabel = model.Id @@ -153,7 +153,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("update image: %w", err) } - params.Printer.Info("Updated image \"%v\" for %q\n", utils.PtrString(resp.Name), projectLabel) + params.Printer.Info("Updated image \"%v\" for %q\n", resp.Name, projectLabel) return nil }, @@ -203,7 +203,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM Name: flags.FlagToStringPointer(p, cmd, nameFlag), DiskFormat: flags.FlagToStringPointer(p, cmd, diskFormatFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelsFlag), Config: &imageConfig{ Architecture: flags.FlagToStringPointer(p, cmd, architectureFlag), BootMenu: flags.FlagToBoolPointer(p, cmd, bootMenuFlag), @@ -238,12 +238,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateImageRequest { - request := apiClient.UpdateImage(ctx, model.ProjectId, model.Region, model.Id) + request := apiClient.DefaultAPI.UpdateImage(ctx, model.ProjectId, model.Region, model.Id) payload := iaas.NewUpdateImagePayload() // Config *ImageConfig `json:"config,omitempty"` payload.DiskFormat = model.DiskFormat - payload.Labels = utils.ConvertStringMapToInterfaceMap(model.Labels) + payload.Labels = model.Labels payload.MinDiskSize = model.MinDiskSize payload.MinRam = model.MinRam payload.Name = model.Name @@ -256,28 +256,28 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli payload.Config.BootMenu = model.Config.BootMenu } if model.Config.CdromBus != nil { - payload.Config.CdromBus = iaas.NewNullableString(model.Config.CdromBus) + payload.Config.CdromBus = *iaas.NewNullableString(model.Config.CdromBus) } if model.Config.DiskBus != nil { - payload.Config.DiskBus = iaas.NewNullableString(model.Config.DiskBus) + payload.Config.DiskBus = *iaas.NewNullableString(model.Config.DiskBus) } if model.Config.NicModel != nil { - payload.Config.NicModel = iaas.NewNullableString(model.Config.NicModel) + payload.Config.NicModel = *iaas.NewNullableString(model.Config.NicModel) } if model.Config.OperatingSystem != nil { payload.Config.OperatingSystem = model.Config.OperatingSystem } if model.Config.OperatingSystemDistro != nil { - payload.Config.OperatingSystemDistro = iaas.NewNullableString(model.Config.OperatingSystemDistro) + payload.Config.OperatingSystemDistro = *iaas.NewNullableString(model.Config.OperatingSystemDistro) } if model.Config.OperatingSystemVersion != nil { - payload.Config.OperatingSystemVersion = iaas.NewNullableString(model.Config.OperatingSystemVersion) + payload.Config.OperatingSystemVersion = *iaas.NewNullableString(model.Config.OperatingSystemVersion) } if model.Config.RescueBus != nil { - payload.Config.RescueBus = iaas.NewNullableString(model.Config.RescueBus) + payload.Config.RescueBus = *iaas.NewNullableString(model.Config.RescueBus) } if model.Config.RescueDevice != nil { - payload.Config.RescueDevice = iaas.NewNullableString(model.Config.RescueDevice) + payload.Config.RescueDevice = *iaas.NewNullableString(model.Config.RescueDevice) } if model.Config.SecureBoot != nil { payload.Config.SecureBoot = model.Config.SecureBoot @@ -286,7 +286,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli payload.Config.Uefi = model.Config.Uefi } if model.Config.VideoModel != nil { - payload.Config.VideoModel = iaas.NewNullableString(model.Config.VideoModel) + payload.Config.VideoModel = *iaas.NewNullableString(model.Config.VideoModel) } if model.Config.VirtioScsi != nil { payload.Config.VirtioScsi = model.Config.VirtioScsi diff --git a/internal/cmd/image/update/update_test.go b/internal/cmd/image/update/update_test.go index b9d08002b..25bcba44c 100644 --- a/internal/cmd/image/update/update_test.go +++ b/internal/cmd/image/update/update_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -24,7 +24,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testImageId = []string{uuid.NewString()} @@ -80,8 +80,8 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st return flagValues } -func parseLabels(labelstring string) map[string]string { - labels := map[string]string{} +func parseLabels(labelstring string) map[string]any { + labels := map[string]any{} for _, part := range strings.Split(labelstring, ",") { v := strings.Split(part, "=") labels[v[0]] = v[1] @@ -100,7 +100,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Id: testImageId[0], Name: &testName, DiskFormat: &testDiskFormat, - Labels: utils.Ptr(parseLabels(testLabels)), + Labels: parseLabels(testLabels), Config: &imageConfig{ BootMenu: &testBootmenu, CdromBus: &testCdRomBus, @@ -130,21 +130,21 @@ func fixtureCreatePayload(mods ...func(payload *iaas.UpdateImagePayload)) (paylo payload = iaas.UpdateImagePayload{ Config: &iaas.ImageConfig{ BootMenu: &testBootmenu, - CdromBus: iaas.NewNullableString(&testCdRomBus), - DiskBus: iaas.NewNullableString(&testDiskBus), - NicModel: iaas.NewNullableString(&testNicModel), + CdromBus: *iaas.NewNullableString(&testCdRomBus), + DiskBus: *iaas.NewNullableString(&testDiskBus), + NicModel: *iaas.NewNullableString(&testNicModel), OperatingSystem: &testOperatingSystem, - OperatingSystemDistro: iaas.NewNullableString(&testOperatingSystemDistro), - OperatingSystemVersion: iaas.NewNullableString(&testOperatingSystemVersion), - RescueBus: iaas.NewNullableString(&testRescueBus), - RescueDevice: iaas.NewNullableString(&testRescueDevice), + OperatingSystemDistro: *iaas.NewNullableString(&testOperatingSystemDistro), + OperatingSystemVersion: *iaas.NewNullableString(&testOperatingSystemVersion), + RescueBus: *iaas.NewNullableString(&testRescueBus), + RescueDevice: *iaas.NewNullableString(&testRescueDevice), SecureBoot: &testSecureBoot, Uefi: &testUefi, - VideoModel: iaas.NewNullableString(&testVideoModel), + VideoModel: *iaas.NewNullableString(&testVideoModel), VirtioScsi: &testVirtioScsi, }, DiskFormat: &testDiskFormat, - Labels: &map[string]interface{}{ + Labels: map[string]any{ "foo": "FOO", "bar": "BAR", "baz": "BAZ", @@ -161,7 +161,7 @@ func fixtureCreatePayload(mods ...func(payload *iaas.UpdateImagePayload)) (paylo } func fixtureRequest(mods ...func(*iaas.ApiUpdateImageRequest)) iaas.ApiUpdateImageRequest { - request := testClient.UpdateImage(testCtx, testProjectId, testRegion, testImageId[0]) + request := testClient.DefaultAPI.UpdateImage(testCtx, testProjectId, testRegion, testImageId[0]) request = request.UpdateImagePayload(fixtureCreatePayload()) @@ -253,7 +253,7 @@ func TestParseInput(t *testing.T) { args: testImageId, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = &map[string]string{ + model.Labels = map[string]any{ "foo": "bar", } }), @@ -394,7 +394,7 @@ func TestBuildRequest(t *testing.T) { model.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateImageRequest) { - *request = (*request).UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { + *request = request.UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { payload.Labels = nil })) }), @@ -405,7 +405,7 @@ func TestBuildRequest(t *testing.T) { model.Name = utils.Ptr("something else") }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateImageRequest) { - *request = (*request).UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { + *request = request.UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { payload.Name = utils.Ptr("something else") })) }), @@ -416,7 +416,7 @@ func TestBuildRequest(t *testing.T) { model.Config.CdromBus = utils.Ptr("something else") }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateImageRequest) { - *request = (*request).UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { + *request = request.UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { payload.Config.CdromBus.Set(utils.Ptr("something else")) })) }), @@ -427,7 +427,7 @@ func TestBuildRequest(t *testing.T) { model.Config = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateImageRequest) { - *request = (*request).UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { + *request = request.UpdateImagePayload(fixtureCreatePayload(func(payload *iaas.UpdateImagePayload) { payload.Config = nil })) }), @@ -439,7 +439,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest, iaas.NullableString{}), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/key-pair/create/create.go b/internal/cmd/key-pair/create/create.go index 5bb18ef2e..a3ee15022 100644 --- a/internal/cmd/key-pair/create/create.go +++ b/internal/cmd/key-pair/create/create.go @@ -14,7 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -26,8 +26,8 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel Name *string - PublicKey *string - Labels *map[string]string + PublicKey string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -101,9 +101,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), Name: flags.FlagToStringPointer(p, cmd, nameFlag), - PublicKey: flags.FlagToStringPointer(p, cmd, publicKeyFlag), + PublicKey: flags.FlagToStringValue(p, cmd, publicKeyFlag), } p.DebugInputModel(model) @@ -111,11 +111,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateKeyPairRequest { - req := apiClient.CreateKeyPair(ctx) + req := apiClient.DefaultAPI.CreateKeyPair(ctx) payload := iaas.CreateKeyPairPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, PublicKey: model.PublicKey, } diff --git a/internal/cmd/key-pair/create/create_test.go b/internal/cmd/key-pair/create/create_test.go index f3e872c43..2e9673360 100644 --- a/internal/cmd/key-pair/create/create_test.go +++ b/internal/cmd/key-pair/create/create_test.go @@ -12,13 +12,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testPublicKey = "ssh-rsa " var testKeyPairName = "foobar_key" @@ -40,10 +40,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "foo": "bar", - }), - PublicKey: utils.Ptr(testPublicKey), + }, + PublicKey: testPublicKey, Name: utils.Ptr(testKeyPairName), } for _, mod := range mods { @@ -53,7 +53,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateKeyPairRequest)) iaas.ApiCreateKeyPairRequest { - request := testClient.CreateKeyPair(testCtx) + request := testClient.DefaultAPI.CreateKeyPair(testCtx) request = request.CreateKeyPairPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -63,10 +63,10 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateKeyPairRequest)) iaas.Ap func fixturePayload(mods ...func(payload *iaas.CreateKeyPairPayload)) iaas.CreateKeyPairPayload { payload := iaas.CreateKeyPairPayload{ - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "foo": "bar", - }), - PublicKey: utils.Ptr(testPublicKey), + }, + PublicKey: testPublicKey, Name: utils.Ptr(testKeyPairName), } for _, mod := range mods { @@ -112,7 +112,7 @@ func TestParseInput(t *testing.T) { if err != nil { t.Fatal("could not create expected Model", err) } - model.PublicKey = utils.Ptr(string(file)) + model.PublicKey = string(file) }), }, { @@ -148,7 +148,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/key-pair/delete/delete.go b/internal/cmd/key-pair/delete/delete.go index 17984e936..b9b452ec2 100644 --- a/internal/cmd/key-pair/delete/delete.go +++ b/internal/cmd/key-pair/delete/delete.go @@ -13,7 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -86,5 +86,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteKeyPairRequest { - return apiClient.DeleteKeyPair(ctx, model.KeyPairName) + return apiClient.DefaultAPI.DeleteKeyPair(ctx, model.KeyPairName) } diff --git a/internal/cmd/key-pair/delete/delete_test.go b/internal/cmd/key-pair/delete/delete_test.go index 568c272c0..569826fb2 100644 --- a/internal/cmd/key-pair/delete/delete_test.go +++ b/internal/cmd/key-pair/delete/delete_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -17,7 +17,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "test") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testKeyPairName = "key-pair-name" func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -52,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteKeyPairRequest)) iaas.ApiDeleteKeyPairRequest { - request := testClient.DeleteKeyPair(testCtx, testKeyPairName) + request := testClient.DefaultAPI.DeleteKeyPair(testCtx, testKeyPairName) for _, mod := range mods { mod(&request) } @@ -168,7 +168,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/key-pair/describe/describe.go b/internal/cmd/key-pair/describe/describe.go index 40f450949..4061d2421 100644 --- a/internal/cmd/key-pair/describe/describe.go +++ b/internal/cmd/key-pair/describe/describe.go @@ -20,7 +20,7 @@ import ( "github.com/goccy/go-yaml" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -104,7 +104,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetKeyPairRequest { - return apiClient.GetKeyPair(ctx, model.KeyPairName) + return apiClient.DefaultAPI.GetKeyPair(ctx, model.KeyPairName) } func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, keyPair iaas.Keypair) error { @@ -113,7 +113,7 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, details, err := json.MarshalIndent(keyPair, "", " ") if showOnlyPublicKey { onlyPublicKey := map[string]string{ - "publicKey": *keyPair.PublicKey, + "publicKey": keyPair.PublicKey, } details, err = json.MarshalIndent(onlyPublicKey, "", " ") } @@ -128,7 +128,7 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, details, err := yaml.MarshalWithOptions(keyPair, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) if showOnlyPublicKey { onlyPublicKey := map[string]string{ - "publicKey": *keyPair.PublicKey, + "publicKey": keyPair.PublicKey, } details, err = yaml.MarshalWithOptions(onlyPublicKey, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) } @@ -141,16 +141,16 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, return nil default: if showOnlyPublicKey { - p.Outputln(*keyPair.PublicKey) + p.Outputln(keyPair.PublicKey) return nil } table := tables.NewTable() table.AddRow("KEY PAIR NAME", utils.PtrString(keyPair.Name)) table.AddSeparator() - if keyPair.Labels != nil && len(*keyPair.Labels) > 0 { + if len(keyPair.Labels) > 0 { var labels []string - for key, value := range *keyPair.Labels { + for key, value := range keyPair.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) @@ -160,9 +160,9 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, table.AddRow("FINGERPRINT", utils.PtrString(keyPair.Fingerprint)) table.AddSeparator() - truncatedPublicKey := "" - if keyPair.PublicKey != nil { - truncatedPublicKey = (*keyPair.PublicKey)[:maxLengthPublicKey] + "..." + truncatedPublicKey := keyPair.PublicKey + if len(keyPair.PublicKey) > maxLengthPublicKey { + truncatedPublicKey = truncatedPublicKey[:maxLengthPublicKey] + "..." } table.AddRow("PUBLIC KEY", truncatedPublicKey) diff --git a/internal/cmd/key-pair/describe/describe_test.go b/internal/cmd/key-pair/describe/describe_test.go index 7769b3bae..69770f1fb 100644 --- a/internal/cmd/key-pair/describe/describe_test.go +++ b/internal/cmd/key-pair/describe/describe_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "test") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testKeyPairName = "foobar" var testPublicKeyFlag = "true" @@ -52,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetKeyPairRequest)) iaas.ApiGetKeyPairRequest { - request := testClient.GetKeyPair(testCtx, testKeyPairName) + request := testClient.DefaultAPI.GetKeyPair(testCtx, testKeyPairName) for _, mod := range mods { mod(&request) } @@ -132,7 +132,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedResult, cmp.AllowUnexported(tt.expectedResult), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("data does not match: %s", diff) diff --git a/internal/cmd/key-pair/list/list.go b/internal/cmd/key-pair/list/list.go index 5aaf4d508..a854e2e2b 100644 --- a/internal/cmd/key-pair/list/list.go +++ b/internal/cmd/key-pair/list/list.go @@ -19,7 +19,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -118,7 +118,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListKeyPairsRequest { - req := apiClient.ListKeyPairs(ctx) + req := apiClient.DefaultAPI.ListKeyPairs(ctx) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -140,7 +140,7 @@ func outputResult(p *print.Printer, outputFormat string, keyPairs []iaas.Keypair var labels []string if keyPair.Labels != nil { - for key, value := range *keyPair.Labels { + for key, value := range keyPair.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } } diff --git a/internal/cmd/key-pair/list/list_test.go b/internal/cmd/key-pair/list/list_test.go index 779b57d49..5ff89be22 100644 --- a/internal/cmd/key-pair/list/list_test.go +++ b/internal/cmd/key-pair/list/list_test.go @@ -12,13 +12,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "test") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testLabelSelector = "foo=bar" var testLimit = int64(64) @@ -48,7 +48,7 @@ func fixtureInputModel(mods ...func(inputModel *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListKeyPairsRequest)) iaas.ApiListKeyPairsRequest { - request := testClient.ListKeyPairs(testCtx) + request := testClient.DefaultAPI.ListKeyPairs(testCtx) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -141,7 +141,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("request does not match: %s", diff) diff --git a/internal/cmd/key-pair/update/update.go b/internal/cmd/key-pair/update/update.go index 14988bf28..f79169c0c 100644 --- a/internal/cmd/key-pair/update/update.go +++ b/internal/cmd/key-pair/update/update.go @@ -15,7 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -25,7 +25,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Labels *map[string]string + Labels map[string]any KeyPairName *string } @@ -82,10 +82,10 @@ func configureFlags(cmd *cobra.Command) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateKeyPairRequest { - req := apiClient.UpdateKeyPair(ctx, *model.KeyPairName) + req := apiClient.DefaultAPI.UpdateKeyPair(ctx, *model.KeyPairName) payload := iaas.UpdateKeyPairPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.UpdateKeyPairPayload(payload) } @@ -96,7 +96,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) inputM model := inputModel{ GlobalFlagModel: globalFlags, - Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelsFlag), KeyPairName: utils.Ptr(keyPairName), } diff --git a/internal/cmd/key-pair/update/update_test.go b/internal/cmd/key-pair/update/update_test.go index 02179c76f..033ed65db 100644 --- a/internal/cmd/key-pair/update/update_test.go +++ b/internal/cmd/key-pair/update/update_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testKeyPairName = "foobar_key" @@ -45,9 +45,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "foo": "bar", - }), + }, KeyPairName: utils.Ptr(testKeyPairName), } for _, mod := range mods { @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateKeyPairRequest)) iaas.ApiUpdateKeyPairRequest { - request := testClient.UpdateKeyPair(testCtx, testKeyPairName) + request := testClient.DefaultAPI.UpdateKeyPair(testCtx, testKeyPairName) request = request.UpdateKeyPairPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -67,9 +67,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdateKeyPairRequest)) iaas.Ap func fixturePayload(mods ...func(payload *iaas.UpdateKeyPairPayload)) iaas.UpdateKeyPairPayload { payload := iaas.UpdateKeyPairPayload{ - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]interface{}{ "foo": "bar", - }), + }, } for _, mod := range mods { mod(&payload) @@ -173,7 +173,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/network-area/create/create.go b/internal/cmd/network-area/create/create.go index af3568850..8b008448f 100644 --- a/internal/cmd/network-area/create/create.go +++ b/internal/cmd/network-area/create/create.go @@ -7,8 +7,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -47,7 +47,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Name *string + Name string OrganizationId string // Deprecated: DnsNameServers is deprecated, because with iaas v2 the create endpoint for network area was separated, remove this after April 2026. DnsNameServers *[]string @@ -61,7 +61,7 @@ type inputModel struct { MaxPrefixLength *int64 // Deprecated: MinPrefixLength is deprecated, because with iaas v2 the create endpoint for network area was separated, remove this after April 2026. MinPrefixLength *int64 - Labels *map[string]string + Labels map[string]any } // NetworkAreaResponses is a workaround, to keep the two responses of the iaas v2 api together for the json and yaml output @@ -147,7 +147,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } if !model.Async { err := spinner.Run(params.Printer, "Create network area region", func() error { - _, err = wait.CreateNetworkAreaRegionWaitHandler(ctx, apiClient, model.OrganizationId, *resp.Id, model.Region).WaitWithContext(ctx) + _, err = wait.CreateNetworkAreaRegionWaitHandler(ctx, apiClient.DefaultAPI, model.OrganizationId, *resp.Id, model.Region).WaitWithContext(ctx) return err }) if err != nil { @@ -221,7 +221,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, - Name: flags.FlagToStringPointer(p, cmd, nameFlag), + Name: flags.FlagToStringValue(p, cmd, nameFlag), OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag), DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, dnsNameServersFlag), NetworkRanges: flags.FlagToStringSlicePointer(p, cmd, networkRangesFlag), @@ -229,7 +229,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, DefaultPrefixLength: flags.FlagToInt64Pointer(p, cmd, defaultPrefixLengthFlag), MaxPrefixLength: flags.FlagToInt64Pointer(p, cmd, maxPrefixLengthFlag), MinPrefixLength: flags.FlagToInt64Pointer(p, cmd, minPrefixLengthFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } // Check if any of the deprecated **optional** fields are set and if no of the associated deprecated **required** fields is set. @@ -247,38 +247,50 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkAreaRequest { - req := apiClient.CreateNetworkArea(ctx, model.OrganizationId) + req := apiClient.DefaultAPI.CreateNetworkArea(ctx, model.OrganizationId) payload := iaas.CreateNetworkAreaPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.CreateNetworkAreaPayload(payload) } func buildRequestNetworkAreaRegion(ctx context.Context, model *inputModel, networkAreaId string, apiClient *iaas.APIClient) iaas.ApiCreateNetworkAreaRegionRequest { - req := apiClient.CreateNetworkAreaRegion(ctx, model.OrganizationId, networkAreaId, model.Region) + req := apiClient.DefaultAPI.CreateNetworkAreaRegion(ctx, model.OrganizationId, networkAreaId, model.Region) var networkRanges []iaas.NetworkRange if model.NetworkRanges != nil { networkRanges = make([]iaas.NetworkRange, len(*model.NetworkRanges)) for i, networkRange := range *model.NetworkRanges { networkRanges[i] = iaas.NetworkRange{ - Prefix: utils.Ptr(networkRange), + Prefix: networkRange, } } } + ipv4 := &iaas.RegionalAreaIPv4{ + NetworkRanges: networkRanges, + } + if model.DnsNameServers != nil { + ipv4.DefaultNameservers = *model.DnsNameServers + } + if model.TransferNetwork != nil { + ipv4.TransferNetwork = *model.TransferNetwork + } + if model.DefaultPrefixLength != nil { + ipv4.DefaultPrefixLen = *model.DefaultPrefixLength + } + if model.MaxPrefixLength != nil { + ipv4.MaxPrefixLen = *model.MaxPrefixLength + } + if model.MinPrefixLength != nil { + ipv4.MinPrefixLen = *model.MinPrefixLength + } + payload := iaas.CreateNetworkAreaRegionPayload{ - Ipv4: &iaas.RegionalAreaIPv4{ - DefaultNameservers: model.DnsNameServers, - NetworkRanges: utils.Ptr(networkRanges), - TransferNetwork: model.TransferNetwork, - DefaultPrefixLen: model.DefaultPrefixLength, - MaxPrefixLen: model.MaxPrefixLength, - MinPrefixLen: model.MinPrefixLength, - }, + Ipv4: ipv4, } return req.CreateNetworkAreaRegionPayload(payload) diff --git a/internal/cmd/network-area/create/create_test.go b/internal/cmd/network-area/create/create_test.go index 142920b88..1a7dd4c4e 100644 --- a/internal/cmd/network-area/create/create_test.go +++ b/internal/cmd/network-area/create/create_test.go @@ -14,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -29,7 +29,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testOrgId = uuid.NewString() @@ -58,11 +58,11 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: utils.Ptr("example-network-area-name"), + Name: "example-network-area-name", OrganizationId: testOrgId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -71,7 +71,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRequest)) iaas.ApiCreateNetworkAreaRequest { - request := testClient.CreateNetworkArea(testCtx, testOrgId) + request := testClient.DefaultAPI.CreateNetworkArea(testCtx, testOrgId) request = request.CreateNetworkAreaPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -81,10 +81,10 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRequest)) iaa func fixturePayload(mods ...func(payload *iaas.CreateNetworkAreaPayload)) iaas.CreateNetworkAreaPayload { payload := iaas.CreateNetworkAreaPayload{ - Name: utils.Ptr("example-network-area-name"), - Labels: utils.Ptr(map[string]interface{}{ + Name: "example-network-area-name", + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(&payload) @@ -93,7 +93,7 @@ func fixturePayload(mods ...func(payload *iaas.CreateNetworkAreaPayload)) iaas.C } func fixtureRequestRegionalArea(mods ...func(request *iaas.ApiCreateNetworkAreaRegionRequest)) iaas.ApiCreateNetworkAreaRegionRequest { - req := testClient.CreateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) + req := testClient.DefaultAPI.CreateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) req = req.CreateNetworkAreaRegionPayload(fixtureRegionalAreaPayload()) for _, mod := range mods { mod(&req) @@ -105,18 +105,18 @@ func fixtureRegionalAreaPayload(mods ...func(request *iaas.CreateNetworkAreaRegi var networkRanges []iaas.NetworkRange for _, networkRange := range testNetworkRanges { networkRanges = append(networkRanges, iaas.NetworkRange{ - Prefix: utils.Ptr(networkRange), + Prefix: networkRange, }) } payload := iaas.CreateNetworkAreaRegionPayload{ Ipv4: &iaas.RegionalAreaIPv4{ - DefaultNameservers: utils.Ptr(testDnsNameservers), - DefaultPrefixLen: utils.Ptr(testDefaultPrefixLength), - MaxPrefixLen: utils.Ptr(testMaxPrefixLength), - MinPrefixLen: utils.Ptr(testMinPrefixLength), - NetworkRanges: utils.Ptr(networkRanges), - TransferNetwork: utils.Ptr(testTransferNetwork), + DefaultNameservers: testDnsNameservers, + DefaultPrefixLen: testDefaultPrefixLength, + MaxPrefixLen: testMaxPrefixLength, + MinPrefixLen: testMinPrefixLength, + NetworkRanges: networkRanges, + TransferNetwork: testTransferNetwork, }, Status: nil, } @@ -160,7 +160,7 @@ func TestParseInput(t *testing.T) { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr(testName), + Name: testName, OrganizationId: testOrgId, // Deprecated fields @@ -279,7 +279,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -331,7 +331,7 @@ func TestBuildRequestNetworkAreaRegion(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -399,11 +399,11 @@ func TestGetConfiguredDeprecatedFlags(t *testing.T) { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr(testName), + Name: testName, OrganizationId: testOrgId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, DnsNameServers: nil, NetworkRanges: nil, TransferNetwork: nil, @@ -421,11 +421,11 @@ func TestGetConfiguredDeprecatedFlags(t *testing.T) { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr(testName), + Name: testName, OrganizationId: testOrgId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, DnsNameServers: utils.Ptr(testDnsNameservers), NetworkRanges: utils.Ptr(testNetworkRanges), TransferNetwork: utils.Ptr(testTransferNetwork), @@ -467,11 +467,11 @@ func TestHasDeprecatedFlagsSet(t *testing.T) { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr(testName), + Name: testName, OrganizationId: testOrgId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, DnsNameServers: nil, NetworkRanges: nil, TransferNetwork: nil, @@ -489,11 +489,11 @@ func TestHasDeprecatedFlagsSet(t *testing.T) { GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr(testName), + Name: testName, OrganizationId: testOrgId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, DnsNameServers: utils.Ptr(testDnsNameservers), NetworkRanges: utils.Ptr(testNetworkRanges), TransferNetwork: utils.Ptr(testTransferNetwork), diff --git a/internal/cmd/network-area/delete/delete.go b/internal/cmd/network-area/delete/delete.go index f9c20e3a9..b45746426 100644 --- a/internal/cmd/network-area/delete/delete.go +++ b/internal/cmd/network-area/delete/delete.go @@ -7,8 +7,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, model.AreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, *model.OrganizationId, model.AreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = model.AreaId @@ -77,17 +77,17 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Check if the network area has a regional configuration - regionalArea, err := apiClient.GetNetworkAreaRegion(ctx, *model.OrganizationId, model.AreaId, model.Region).Execute() + regionalArea, err := apiClient.DefaultAPI.GetNetworkAreaRegion(ctx, *model.OrganizationId, model.AreaId, model.Region).Execute() if err != nil { params.Printer.Debug(print.ErrorLevel, "get regional area: %v", err) } if regionalArea != nil { params.Printer.Warn(deprecationMessage, model.Region, networkAreaLabel) - err = apiClient.DeleteNetworkAreaRegion(ctx, *model.OrganizationId, model.AreaId, model.Region).Execute() + err = apiClient.DefaultAPI.DeleteNetworkAreaRegion(ctx, *model.OrganizationId, model.AreaId, model.Region).Execute() if err != nil { return fmt.Errorf("delete network area region: %w", err) } - _, err := wait.DeleteNetworkAreaRegionWaitHandler(ctx, apiClient, *model.OrganizationId, model.AreaId, model.Region).WaitWithContext(ctx) + _, err := wait.DeleteNetworkAreaRegionWaitHandler(ctx, apiClient.DefaultAPI, *model.OrganizationId, model.AreaId, model.Region).WaitWithContext(ctx) if err != nil { return fmt.Errorf("wait delete network area region: %w", err) } @@ -131,5 +131,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNetworkAreaRequest { - return apiClient.DeleteNetworkArea(ctx, *model.OrganizationId, model.AreaId) + return apiClient.DefaultAPI.DeleteNetworkArea(ctx, *model.OrganizationId, model.AreaId) } diff --git a/internal/cmd/network-area/delete/delete_test.go b/internal/cmd/network-area/delete/delete_test.go index 1ee322dc3..62db3491a 100644 --- a/internal/cmd/network-area/delete/delete_test.go +++ b/internal/cmd/network-area/delete/delete_test.go @@ -10,13 +10,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrganizationId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteNetworkAreaRequest)) iaas.ApiDeleteNetworkAreaRequest { - request := testClient.DeleteNetworkArea(testCtx, testOrganizationId, testNetworkAreaId) + request := testClient.DefaultAPI.DeleteNetworkArea(testCtx, testOrganizationId, testNetworkAreaId) for _, mod := range mods { mod(&request) } @@ -159,7 +159,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/describe/describe.go b/internal/cmd/network-area/describe/describe.go index 0c467f2c7..b70dd18a1 100644 --- a/internal/cmd/network-area/describe/describe.go +++ b/internal/cmd/network-area/describe/describe.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -79,7 +79,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { var projects []string if model.ShowAttachedProjects { - projects, err = iaasUtils.ListAttachedProjects(ctx, apiClient, *model.OrganizationId, model.AreaId) + projects, err = iaasUtils.ListAttachedProjects(ctx, apiClient.DefaultAPI, *model.OrganizationId, model.AreaId) if err != nil && errors.Is(err, iaasUtils.ErrItemsNil) { projects = []string{} } else if err != nil { @@ -119,7 +119,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNetworkAreaRequest { - return apiClient.GetNetworkArea(ctx, *model.OrganizationId, model.AreaId) + return apiClient.DefaultAPI.GetNetworkArea(ctx, *model.OrganizationId, model.AreaId) } func outputResult(p *print.Printer, outputFormat string, networkArea *iaas.NetworkArea, attachedProjects []string) error { @@ -131,11 +131,11 @@ func outputResult(p *print.Printer, outputFormat string, networkArea *iaas.Netwo table := tables.NewTable() table.AddRow("ID", utils.PtrString(networkArea.Id)) table.AddSeparator() - table.AddRow("NAME", utils.PtrString(networkArea.Name)) + table.AddRow("NAME", networkArea.Name) table.AddSeparator() - if networkArea.Labels != nil && len(*networkArea.Labels) > 0 { + if len(networkArea.Labels) > 0 { var labels []string - for key, value := range *networkArea.Labels { + for key, value := range networkArea.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/network-area/describe/describe_test.go b/internal/cmd/network-area/describe/describe_test.go index 353f0d0cd..b589cbcf3 100644 --- a/internal/cmd/network-area/describe/describe_test.go +++ b/internal/cmd/network-area/describe/describe_test.go @@ -11,13 +11,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrganizationId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkAreaRequest)) iaas.ApiGetNetworkAreaRequest { - request := testClient.GetNetworkArea(testCtx, testOrganizationId, testNetworkAreaId) + request := testClient.DefaultAPI.GetNetworkArea(testCtx, testOrganizationId, testNetworkAreaId) for _, mod := range mods { mod(&request) } @@ -173,7 +173,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/list/list.go b/internal/cmd/network-area/list/list.go index f473fc981..592a72b76 100644 --- a/internal/cmd/network-area/list/list.go +++ b/internal/cmd/network-area/list/list.go @@ -9,7 +9,7 @@ import ( rmClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -141,7 +141,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNetworkAreasRequest { - req := apiClient.ListNetworkAreas(ctx, model.OrganizationId) + req := apiClient.DefaultAPI.ListNetworkAreas(ctx, model.OrganizationId) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -161,7 +161,7 @@ func outputResult(p *print.Printer, outputFormat, orgLabel string, networkAreas for _, networkArea := range networkAreas { table.AddRow( utils.PtrString(networkArea.Id), - utils.PtrString(networkArea.Name), + networkArea.Name, utils.PtrString(networkArea.ProjectCount), ) table.AddSeparator() diff --git a/internal/cmd/network-area/list/list_test.go b/internal/cmd/network-area/list/list_test.go index 096ac43eb..af74284b4 100644 --- a/internal/cmd/network-area/list/list_test.go +++ b/internal/cmd/network-area/list/list_test.go @@ -12,13 +12,13 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrganizationId = uuid.NewString() var testLabelSelector = "foo=bar" @@ -50,7 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListNetworkAreasRequest)) iaas.ApiListNetworkAreasRequest { - request := testClient.ListNetworkAreas(testCtx, testOrganizationId) + request := testClient.DefaultAPI.ListNetworkAreas(testCtx, testOrganizationId) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -155,7 +155,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/network-range/create/create.go b/internal/cmd/network-area/network-range/create/create.go index 0767cc9ea..5d8ba7fd9 100644 --- a/internal/cmd/network-area/network-range/create/create.go +++ b/internal/cmd/network-area/network-range/create/create.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -30,7 +30,7 @@ type inputModel struct { *globalflags.GlobalFlagModel OrganizationId *string NetworkAreaId *string - NetworkRange *string + NetworkRange string } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -59,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, *model.OrganizationId, *model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = *model.NetworkAreaId @@ -78,11 +78,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("create network range: %w", err) } - if resp.Items == nil || len(*resp.Items) == 0 { + if len(resp.Items) == 0 { return fmt.Errorf("empty response from API") } - networkRange, err := iaasUtils.GetNetworkRangeFromAPIResponse(*model.NetworkRange, resp.Items) + networkRange, err := iaasUtils.GetNetworkRangeFromAPIResponse(model.NetworkRange, resp.Items) if err != nil { return err } @@ -110,7 +110,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, GlobalFlagModel: globalFlags, OrganizationId: flags.FlagToStringPointer(p, cmd, organizationIdFlag), NetworkAreaId: flags.FlagToStringPointer(p, cmd, networkAreaIdFlag), - NetworkRange: flags.FlagToStringPointer(p, cmd, networkRangeFlag), + NetworkRange: flags.FlagToStringValue(p, cmd, networkRangeFlag), } p.DebugInputModel(model) @@ -118,9 +118,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkAreaRangeRequest { - req := apiClient.CreateNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region) + req := apiClient.DefaultAPI.CreateNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region) payload := iaas.CreateNetworkAreaRangePayload{ - Ipv4: &[]iaas.NetworkRange{ + Ipv4: []iaas.NetworkRange{ { Prefix: model.NetworkRange, }, diff --git a/internal/cmd/network-area/network-range/create/create_test.go b/internal/cmd/network-area/network-range/create/create_test.go index 3c65c007e..24fee526b 100644 --- a/internal/cmd/network-area/network-range/create/create_test.go +++ b/internal/cmd/network-area/network-range/create/create_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -49,7 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, OrganizationId: utils.Ptr(testOrgId), NetworkAreaId: utils.Ptr(testNetworkAreaId), - NetworkRange: utils.Ptr("1.1.1.0/24"), + NetworkRange: "1.1.1.0/24", } for _, mod := range mods { mod(model) @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRangeRequest)) iaas.ApiCreateNetworkAreaRangeRequest { - request := testClient.CreateNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion) + request := testClient.DefaultAPI.CreateNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion) request = request.CreateNetworkAreaRangePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -68,9 +68,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRangeRequest) func fixturePayload(mods ...func(payload *iaas.CreateNetworkAreaRangePayload)) iaas.CreateNetworkAreaRangePayload { payload := iaas.CreateNetworkAreaRangePayload{ - Ipv4: &[]iaas.NetworkRange{ + Ipv4: []iaas.NetworkRange{ { - Prefix: utils.Ptr("1.1.1.0/24"), + Prefix: "1.1.1.0/24", }, }, } @@ -177,7 +177,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/network-range/delete/delete.go b/internal/cmd/network-area/network-range/delete/delete.go index eb0daa88d..b563fa0ae 100644 --- a/internal/cmd/network-area/network-range/delete/delete.go +++ b/internal/cmd/network-area/network-range/delete/delete.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -59,12 +59,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, *model.OrganizationId, *model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = *model.NetworkAreaId } - networkRangeLabel, err := iaasUtils.GetNetworkRangePrefix(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId) + networkRangeLabel, err := iaasUtils.GetNetworkRangePrefix(ctx, apiClient.DefaultAPI, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network range prefix: %v", err) networkRangeLabel = model.NetworkRangeId @@ -118,6 +118,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNetworkAreaRangeRequest { - req := apiClient.DeleteNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId) + req := apiClient.DefaultAPI.DeleteNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId) return req } diff --git a/internal/cmd/network-area/network-range/delete/delete_test.go b/internal/cmd/network-area/network-range/delete/delete_test.go index 328e77a45..46d83b37e 100644 --- a/internal/cmd/network-area/network-range/delete/delete_test.go +++ b/internal/cmd/network-area/network-range/delete/delete_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -67,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteNetworkAreaRangeRequest)) iaas.ApiDeleteNetworkAreaRangeRequest { - request := testClient.DeleteNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion, testNetworkRangeId) + request := testClient.DefaultAPI.DeleteNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion, testNetworkRangeId) for _, mod := range mods { mod(&request) } @@ -233,7 +233,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/network-range/describe/describe.go b/internal/cmd/network-area/network-range/describe/describe.go index 6ba53cb83..cf9d5e533 100644 --- a/internal/cmd/network-area/network-range/describe/describe.go +++ b/internal/cmd/network-area/network-range/describe/describe.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -97,7 +97,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNetworkAreaRangeRequest { - req := apiClient.GetNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId) + req := apiClient.DefaultAPI.GetNetworkAreaRange(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.NetworkRangeId) return req } @@ -110,7 +110,7 @@ func outputResult(p *print.Printer, outputFormat string, networkRange *iaas.Netw table := tables.NewTable() table.AddRow("ID", utils.PtrString(networkRange.Id)) table.AddSeparator() - table.AddRow("Network range", utils.PtrString(networkRange.Prefix)) + table.AddRow("Network range", networkRange.Prefix) err := table.Display(p) if err != nil { diff --git a/internal/cmd/network-area/network-range/describe/describe_test.go b/internal/cmd/network-area/network-range/describe/describe_test.go index 89e3d4d15..ef75d8fc8 100644 --- a/internal/cmd/network-area/network-range/describe/describe_test.go +++ b/internal/cmd/network-area/network-range/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -68,7 +68,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkAreaRangeRequest)) iaas.ApiGetNetworkAreaRangeRequest { - request := testClient.GetNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion, testNetworkRangeId) + request := testClient.DefaultAPI.GetNetworkAreaRange(testCtx, testOrgId, testNetworkAreaId, testRegion, testNetworkRangeId) for _, mod := range mods { mod(&request) } @@ -234,7 +234,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/network-range/list/list.go b/internal/cmd/network-area/network-range/list/list.go index ebc1e0faa..72dfdb0e0 100644 --- a/internal/cmd/network-area/network-range/list/list.go +++ b/internal/cmd/network-area/network-range/list/list.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -77,7 +77,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { items := resp.GetItems() - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err) networkAreaLabel = model.NetworkAreaId @@ -126,7 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNetworkAreaRangesRequest { - return apiClient.ListNetworkAreaRanges(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + return apiClient.DefaultAPI.ListNetworkAreaRanges(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) } func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, networkRanges []iaas.NetworkRange) error { @@ -139,7 +139,7 @@ func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, netwo table.SetHeader("ID", "Network Range") for _, networkRange := range networkRanges { - table.AddRow(utils.PtrString(networkRange.Id), utils.PtrString(networkRange.Prefix)) + table.AddRow(utils.PtrString(networkRange.Id), networkRange.Prefix) } p.Outputln(table.Render()) diff --git a/internal/cmd/network-area/network-range/list/list_test.go b/internal/cmd/network-area/network-range/list/list_test.go index e0848648b..26703fc6d 100644 --- a/internal/cmd/network-area/network-range/list/list_test.go +++ b/internal/cmd/network-area/network-range/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrganizationId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListNetworkAreaRangesRequest)) iaas.ApiListNetworkAreaRangesRequest { - request := testClient.ListNetworkAreaRanges(testCtx, testOrganizationId, testNetworkAreaId, testRegion) + request := testClient.DefaultAPI.ListNetworkAreaRanges(testCtx, testOrganizationId, testNetworkAreaId, testRegion) for _, mod := range mods { mod(&request) } @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/region/create/create.go b/internal/cmd/network-area/region/create/create.go index 791c8fabe..185ba10cb 100644 --- a/internal/cmd/network-area/region/create/create.go +++ b/internal/cmd/network-area/region/create/create.go @@ -7,8 +7,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -19,7 +19,6 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) const ( @@ -38,10 +37,10 @@ type inputModel struct { OrganizationId string NetworkAreaId string - IPv4DefaultNameservers *[]string - IPv4DefaultPrefixLength *int64 - IPv4MaxPrefixLength *int64 - IPv4MinPrefixLength *int64 + IPv4DefaultNameservers []string + IPv4DefaultPrefixLength int64 + IPv4MaxPrefixLength int64 + IPv4MinPrefixLength int64 IPv4NetworkRanges []string IPv4TransferNetwork string } @@ -85,7 +84,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = model.NetworkAreaId @@ -110,7 +109,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { err := spinner.Run(params.Printer, "Create network area region", func() error { - _, err = wait.CreateNetworkAreaRegionWaitHandler(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region).WaitWithContext(ctx) + _, err = wait.CreateNetworkAreaRegionWaitHandler(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region).WaitWithContext(ctx) return err }) if err != nil { @@ -149,10 +148,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, GlobalFlagModel: globalFlags, NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag), OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag), - IPv4DefaultNameservers: flags.FlagToStringSlicePointer(p, cmd, ipv4DefaultNameservers), - IPv4DefaultPrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4DefaultPrefixLengthFlag), - IPv4MaxPrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4MaxPrefixLengthFlag), - IPv4MinPrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4MinPrefixLengthFlag), + IPv4DefaultNameservers: flags.FlagToStringSliceValue(p, cmd, ipv4DefaultNameservers), + IPv4DefaultPrefixLength: flags.FlagWithDefaultToInt64Value(p, cmd, ipv4DefaultPrefixLengthFlag), + IPv4MaxPrefixLength: flags.FlagWithDefaultToInt64Value(p, cmd, ipv4MaxPrefixLengthFlag), + IPv4MinPrefixLength: flags.FlagWithDefaultToInt64Value(p, cmd, ipv4MinPrefixLengthFlag), IPv4NetworkRanges: flags.FlagToStringSliceValue(p, cmd, ipv4NetworkRangesFlag), IPv4TransferNetwork: flags.FlagToStringValue(p, cmd, ipv4TransferNetworkFlag), } @@ -162,14 +161,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkAreaRegionRequest { - req := apiClient.CreateNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + req := apiClient.DefaultAPI.CreateNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) var networkRange []iaas.NetworkRange if len(model.IPv4NetworkRanges) > 0 { networkRange = make([]iaas.NetworkRange, len(model.IPv4NetworkRanges)) for i := range model.IPv4NetworkRanges { networkRange[i] = iaas.NetworkRange{ - Prefix: utils.Ptr(model.IPv4NetworkRanges[i]), + Prefix: model.IPv4NetworkRanges[i], } } } @@ -180,8 +179,8 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli DefaultPrefixLen: model.IPv4DefaultPrefixLength, MaxPrefixLen: model.IPv4MaxPrefixLength, MinPrefixLen: model.IPv4MinPrefixLength, - NetworkRanges: utils.Ptr(networkRange), - TransferNetwork: utils.Ptr(model.IPv4TransferNetwork), + NetworkRanges: networkRange, + TransferNetwork: model.IPv4TransferNetwork, }, } return req.CreateNetworkAreaRegionPayload(payload) diff --git a/internal/cmd/network-area/region/create/create_test.go b/internal/cmd/network-area/region/create/create_test.go index b353a1a79..c9d9dcd22 100644 --- a/internal/cmd/network-area/region/create/create_test.go +++ b/internal/cmd/network-area/region/create/create_test.go @@ -9,13 +9,12 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) const ( @@ -29,7 +28,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testAreaId = uuid.NewString() @@ -65,10 +64,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, OrganizationId: testOrgId, NetworkAreaId: testAreaId, - IPv4DefaultNameservers: utils.Ptr(testDefaultNameservers), - IPv4DefaultPrefixLength: utils.Ptr(testDefaultPrefixLength), - IPv4MaxPrefixLength: utils.Ptr(testMaxPrefixLength), - IPv4MinPrefixLength: utils.Ptr(testMinPrefixLength), + IPv4DefaultNameservers: testDefaultNameservers, + IPv4DefaultPrefixLength: testDefaultPrefixLength, + IPv4MaxPrefixLength: testMaxPrefixLength, + IPv4MinPrefixLength: testMinPrefixLength, IPv4NetworkRanges: testNetworkRanges, IPv4TransferNetwork: testTransferNetwork, } @@ -79,7 +78,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRegionRequest)) iaas.ApiCreateNetworkAreaRegionRequest { - request := testClient.CreateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) + request := testClient.DefaultAPI.CreateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) request = request.CreateNetworkAreaRegionPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -93,19 +92,19 @@ func fixturePayload(mods ...func(payload *iaas.CreateNetworkAreaRegionPayload)) networkRange = make([]iaas.NetworkRange, len(testNetworkRanges)) for i := range testNetworkRanges { networkRange[i] = iaas.NetworkRange{ - Prefix: utils.Ptr(testNetworkRanges[i]), + Prefix: testNetworkRanges[i], } } } payload := iaas.CreateNetworkAreaRegionPayload{ Ipv4: &iaas.RegionalAreaIPv4{ - DefaultNameservers: utils.Ptr(testDefaultNameservers), - DefaultPrefixLen: utils.Ptr(testDefaultPrefixLength), - MaxPrefixLen: utils.Ptr(testMaxPrefixLength), - MinPrefixLen: utils.Ptr(testMinPrefixLength), - NetworkRanges: utils.Ptr(networkRange), - TransferNetwork: utils.Ptr(testTransferNetwork), + DefaultNameservers: testDefaultNameservers, + DefaultPrefixLen: testDefaultPrefixLength, + MaxPrefixLen: testMaxPrefixLength, + MinPrefixLen: testMinPrefixLength, + NetworkRanges: networkRange, + TransferNetwork: testTransferNetwork, }, } for _, mod := range mods { @@ -255,7 +254,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/region/delete/delete.go b/internal/cmd/network-area/region/delete/delete.go index d016aff73..0017e5ff3 100644 --- a/internal/cmd/network-area/region/delete/delete.go +++ b/internal/cmd/network-area/region/delete/delete.go @@ -7,8 +7,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaName, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaName, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaName = model.NetworkAreaId @@ -84,7 +84,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if !model.Async { err := spinner.Run(params.Printer, "Delete network area region", func() error { - _, err = wait.DeleteNetworkAreaRegionWaitHandler(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region).WaitWithContext(ctx) + _, err = wait.DeleteNetworkAreaRegionWaitHandler(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region).WaitWithContext(ctx) return err }) if err != nil { @@ -125,5 +125,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNetworkAreaRegionRequest { - return apiClient.DeleteNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + return apiClient.DefaultAPI.DeleteNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) } diff --git a/internal/cmd/network-area/region/delete/delete_test.go b/internal/cmd/network-area/region/delete/delete_test.go index 5a47b2b49..809156ce3 100644 --- a/internal/cmd/network-area/region/delete/delete_test.go +++ b/internal/cmd/network-area/region/delete/delete_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testAreaId = uuid.NewString() @@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteNetworkAreaRegionRequest)) iaas.ApiDeleteNetworkAreaRegionRequest { - request := testClient.DeleteNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) + request := testClient.DefaultAPI.DeleteNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) for _, mod := range mods { mod(&request) } @@ -159,7 +159,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/region/describe/describe.go b/internal/cmd/network-area/region/describe/describe.go index 4694d1db5..ec0e99b6b 100644 --- a/internal/cmd/network-area/region/describe/describe.go +++ b/internal/cmd/network-area/region/describe/describe.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaName, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaName, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) // Set explicit the networkAreaName to empty string and not to the ID, because this is used for the table output @@ -114,7 +114,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNetworkAreaRegionRequest { - return apiClient.GetNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + return apiClient.DefaultAPI.GetNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) } func outputResult(p *print.Printer, outputFormat, region, areaId, areaName string, regionalArea iaas.RegionalArea) error { @@ -133,34 +133,24 @@ func outputResult(p *print.Printer, outputFormat, region, areaId, areaName strin if ipv4 := regionalArea.Ipv4; ipv4 != nil { if ipv4.NetworkRanges != nil { var networkRanges []string - for _, networkRange := range *ipv4.NetworkRanges { - if networkRange.Prefix != nil { - networkRanges = append(networkRanges, *networkRange.Prefix) - } + for _, networkRange := range ipv4.NetworkRanges { + networkRanges = append(networkRanges, networkRange.Prefix) } table.AddRow("NETWORK RANGES", strings.Join(networkRanges, ",")) table.AddSeparator() } - if transferNetwork := ipv4.TransferNetwork; transferNetwork != nil { - table.AddRow("TRANSFER RANGE", utils.PtrString(transferNetwork)) - table.AddSeparator() - } - if defaultNameserver := ipv4.DefaultNameservers; defaultNameserver != nil && len(*defaultNameserver) > 0 { - table.AddRow("DNS NAME SERVERS", strings.Join(*defaultNameserver, ",")) - table.AddSeparator() - } - if defaultPrefixLength := ipv4.DefaultPrefixLen; defaultPrefixLength != nil { - table.AddRow("DEFAULT PREFIX LENGTH", utils.PtrString(defaultPrefixLength)) - table.AddSeparator() - } - if maxPrefixLength := ipv4.MaxPrefixLen; maxPrefixLength != nil { - table.AddRow("MAX PREFIX LENGTH", utils.PtrString(maxPrefixLength)) - table.AddSeparator() - } - if minPrefixLen := ipv4.MinPrefixLen; minPrefixLen != nil { - table.AddRow("MIN PREFIX LENGTH", utils.PtrString(minPrefixLen)) + table.AddRow("TRANSFER RANGE", ipv4.TransferNetwork) + table.AddSeparator() + if len(ipv4.DefaultNameservers) > 0 { + table.AddRow("DNS NAME SERVERS", strings.Join(ipv4.DefaultNameservers, ",")) table.AddSeparator() } + table.AddRow("DEFAULT PREFIX LENGTH", ipv4.DefaultPrefixLen) + table.AddSeparator() + table.AddRow("MAX PREFIX LENGTH", ipv4.MaxPrefixLen) + table.AddSeparator() + table.AddRow("MIN PREFIX LENGTH", ipv4.MinPrefixLen) + table.AddSeparator() } if err := table.Display(p); err != nil { diff --git a/internal/cmd/network-area/region/describe/describe_test.go b/internal/cmd/network-area/region/describe/describe_test.go index 738737f1a..34c2d9469 100644 --- a/internal/cmd/network-area/region/describe/describe_test.go +++ b/internal/cmd/network-area/region/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testAreaId = uuid.NewString() @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkAreaRegionRequest)) iaas.ApiGetNetworkAreaRegionRequest { - request := testClient.GetNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) + request := testClient.DefaultAPI.GetNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) for _, mod := range mods { mod(&request) } @@ -161,7 +161,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/region/list/list.go b/internal/cmd/network-area/region/list/list.go index 4988c87cc..0135e86ea 100644 --- a/internal/cmd/network-area/region/list/list.go +++ b/internal/cmd/network-area/region/list/list.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = model.NetworkAreaId @@ -104,38 +104,36 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNetworkAreaRegionsRequest { - return apiClient.ListNetworkAreaRegions(ctx, model.OrganizationId, model.NetworkAreaId) + return apiClient.DefaultAPI.ListNetworkAreaRegions(ctx, model.OrganizationId, model.NetworkAreaId) } func outputResult(p *print.Printer, outputFormat, areaLabel string, regionalArea iaas.RegionalAreaListResponse) error { return p.OutputResult(outputFormat, regionalArea, func() error { - if regionalArea.Regions == nil || len(*regionalArea.Regions) == 0 { + if len(regionalArea.Regions) == 0 { p.Outputf("No regions found for network area %q\n", areaLabel) return nil } table := tables.NewTable() table.SetHeader("REGION", "STATUS", "DNS NAME SERVERS", "NETWORK RANGES", "TRANSFER NETWORK") - for region, regionConfig := range *regionalArea.Regions { + for region, regionConfig := range regionalArea.Regions { var dnsNames string var networkRanges []string var transferNetwork string if ipv4 := regionConfig.Ipv4; ipv4 != nil { // Set dnsNames - dnsNames = utils.JoinStringPtr(ipv4.DefaultNameservers, ",") + dnsNames = strings.Join(ipv4.DefaultNameservers, ",") // Set networkRanges - if ipv4.NetworkRanges != nil && len(*ipv4.NetworkRanges) > 0 { - for _, networkRange := range *ipv4.NetworkRanges { - if networkRange.Prefix != nil { - networkRanges = append(networkRanges, *networkRange.Prefix) - } + if len(ipv4.NetworkRanges) > 0 { + for _, networkRange := range ipv4.NetworkRanges { + networkRanges = append(networkRanges, networkRange.Prefix) } } // Set transferNetwork - transferNetwork = utils.PtrString(ipv4.TransferNetwork) + transferNetwork = ipv4.TransferNetwork } table.AddRow( diff --git a/internal/cmd/network-area/region/list/list_test.go b/internal/cmd/network-area/region/list/list_test.go index cd93683b7..9a480fe56 100644 --- a/internal/cmd/network-area/region/list/list_test.go +++ b/internal/cmd/network-area/region/list/list_test.go @@ -7,18 +7,17 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testAreaId = uuid.NewString() @@ -51,7 +50,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListNetworkAreaRegionsRequest)) iaas.ApiListNetworkAreaRegionsRequest { - request := testClient.ListNetworkAreaRegions(testCtx, testOrgId, testAreaId) + request := testClient.DefaultAPI.ListNetworkAreaRegions(testCtx, testOrgId, testAreaId) for _, mod := range mods { mod(&request) } @@ -147,7 +146,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -192,7 +191,7 @@ func Test_outputResult(t *testing.T) { name: "set empty map for regions map in response", args: args{ regionalArea: iaas.RegionalAreaListResponse{ - Regions: utils.Ptr(map[string]iaas.RegionalArea{}), + Regions: map[string]iaas.RegionalArea{}, }, }, wantErr: false, @@ -201,9 +200,9 @@ func Test_outputResult(t *testing.T) { name: "set empty region in response", args: args{ regionalArea: iaas.RegionalAreaListResponse{ - Regions: utils.Ptr(map[string]iaas.RegionalArea{ + Regions: map[string]iaas.RegionalArea{ "eu01": {}, - }), + }, }, }, wantErr: false, diff --git a/internal/cmd/network-area/region/update/update.go b/internal/cmd/network-area/region/update/update.go index 151c83a50..7b1d35add 100644 --- a/internal/cmd/network-area/region/update/update.go +++ b/internal/cmd/network-area/region/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -33,7 +33,7 @@ type inputModel struct { OrganizationId string NetworkAreaId string - IPv4DefaultNameservers *[]string + IPv4DefaultNameservers []string IPv4DefaultPrefixLength *int64 IPv4MaxPrefixLength *int64 IPv4MinPrefixLength *int64 @@ -78,7 +78,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = model.NetworkAreaId @@ -133,7 +133,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, GlobalFlagModel: globalFlags, NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag), OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag), - IPv4DefaultNameservers: flags.FlagToStringSlicePointer(p, cmd, ipv4DefaultNameservers), + IPv4DefaultNameservers: flags.FlagToStringSliceValue(p, cmd, ipv4DefaultNameservers), IPv4DefaultPrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4DefaultPrefixLengthFlag), IPv4MaxPrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4MaxPrefixLengthFlag), IPv4MinPrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4MinPrefixLengthFlag), @@ -144,7 +144,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateNetworkAreaRegionRequest { - req := apiClient.UpdateNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + req := apiClient.DefaultAPI.UpdateNetworkAreaRegion(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) payload := iaas.UpdateNetworkAreaRegionPayload{ Ipv4: &iaas.UpdateRegionalAreaIPv4{ diff --git a/internal/cmd/network-area/region/update/update_test.go b/internal/cmd/network-area/region/update/update_test.go index 736f5b743..d76c943a3 100644 --- a/internal/cmd/network-area/region/update/update_test.go +++ b/internal/cmd/network-area/region/update/update_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -28,7 +28,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testAreaId = uuid.NewString() @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, OrganizationId: testOrgId, NetworkAreaId: testAreaId, - IPv4DefaultNameservers: utils.Ptr(testDefaultNameservers), + IPv4DefaultNameservers: testDefaultNameservers, IPv4DefaultPrefixLength: utils.Ptr(testDefaultPrefixLength), IPv4MaxPrefixLength: utils.Ptr(testMaxPrefixLength), IPv4MinPrefixLength: utils.Ptr(testMinPrefixLength), @@ -74,7 +74,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateNetworkAreaRegionRequest)) iaas.ApiUpdateNetworkAreaRegionRequest { - request := testClient.UpdateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) + request := testClient.DefaultAPI.UpdateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) request = request.UpdateNetworkAreaRegionPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -88,14 +88,14 @@ func fixturePayload(mods ...func(payload *iaas.UpdateNetworkAreaRegionPayload)) networkRange = make([]iaas.NetworkRange, len(testNetworkRanges)) for i := range testNetworkRanges { networkRange[i] = iaas.NetworkRange{ - Prefix: utils.Ptr(testNetworkRanges[i]), + Prefix: testNetworkRanges[i], } } } payload := iaas.UpdateNetworkAreaRegionPayload{ Ipv4: &iaas.UpdateRegionalAreaIPv4{ - DefaultNameservers: utils.Ptr(testDefaultNameservers), + DefaultNameservers: testDefaultNameservers, DefaultPrefixLen: utils.Ptr(testDefaultPrefixLength), MaxPrefixLen: utils.Ptr(testMaxPrefixLength), MinPrefixLen: utils.Ptr(testMinPrefixLength), @@ -213,7 +213,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/route/create/create.go b/internal/cmd/network-area/route/create/create.go index 385216013..68974737b 100644 --- a/internal/cmd/network-area/route/create/create.go +++ b/internal/cmd/network-area/route/create/create.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -56,7 +56,7 @@ type inputModel struct { NexthopV6 *string NexthopBlackhole *bool NexthopInternet *bool - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -92,7 +92,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, *model.OrganizationId, *model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = *model.NetworkAreaId @@ -111,7 +111,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("create static route: %w", err) } - if resp.Items == nil || len(*resp.Items) == 0 { + if len(resp.Items) == 0 { return fmt.Errorf("empty response from API") } @@ -140,7 +140,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, route) + return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, &route) }, } configureFlags(cmd) @@ -225,7 +225,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, NexthopV6: nexthopIPv6, NexthopBlackhole: nexthopBlackhole, NexthopInternet: nexthopInternet, - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } p.DebugInputModel(model) @@ -233,20 +233,20 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkAreaRouteRequest { - req := apiClient.CreateNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region) + req := apiClient.DefaultAPI.CreateNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region) var destinationV4 *iaas.DestinationCIDRv4 var destinationV6 *iaas.DestinationCIDRv6 if model.DestinationV4 != nil { destinationV4 = &iaas.DestinationCIDRv4{ - Type: utils.Ptr(destinationCIDRv4Type), - Value: model.DestinationV4, + Type: destinationCIDRv4Type, + Value: *model.DestinationV4, } } if model.DestinationV6 != nil { destinationV6 = &iaas.DestinationCIDRv6{ - Type: utils.Ptr(destinationCIDRv6Type), - Value: model.DestinationV6, + Type: destinationCIDRv6Type, + Value: *model.DestinationV6, } } @@ -257,45 +257,45 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli if model.NexthopV4 != nil { nexthopIPv4 = &iaas.NexthopIPv4{ - Type: utils.Ptr(nexthopIPv4Type), - Value: model.NexthopV4, + Type: nexthopIPv4Type, + Value: *model.NexthopV4, } } else if model.NexthopV6 != nil { nexthopIPv6 = &iaas.NexthopIPv6{ - Type: utils.Ptr(nexthopIPv6Type), - Value: model.NexthopV6, + Type: nexthopIPv6Type, + Value: *model.NexthopV6, } } else if model.NexthopBlackhole != nil { nexthopBlackhole = &iaas.NexthopBlackhole{ - Type: utils.Ptr(nexthopBlackholeType), + Type: nexthopBlackholeType, } } else if model.NexthopInternet != nil { nexthopInternet = &iaas.NexthopInternet{ - Type: utils.Ptr(nexthopInternetType), + Type: nexthopInternetType, } } payload := iaas.CreateNetworkAreaRoutePayload{ - Items: &[]iaas.Route{ + Items: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: destinationV4, DestinationCIDRv6: destinationV6, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: nexthopIPv4, NexthopIPv6: nexthopIPv6, NexthopBlackhole: nexthopBlackhole, NexthopInternet: nexthopInternet, }, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, }, }, } return req.CreateNetworkAreaRoutePayload(payload) } -func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route iaas.Route) error { +func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route *iaas.Route) error { return p.OutputResult(outputFormat, route, func() error { p.Outputf("Created static route for SNA %q.\nStatic route ID: %s\n", networkAreaLabel, utils.PtrString(route.Id)) return nil diff --git a/internal/cmd/network-area/route/create/create_test.go b/internal/cmd/network-area/route/create/create_test.go index a3841a7ce..c854c4a31 100644 --- a/internal/cmd/network-area/route/create/create_test.go +++ b/internal/cmd/network-area/route/create/create_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -24,7 +24,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRouteRequest)) iaas.ApiCreateNetworkAreaRouteRequest { - request := testClient.CreateNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion) + request := testClient.DefaultAPI.CreateNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion) request = request.CreateNetworkAreaRoutePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -72,18 +72,18 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkAreaRouteRequest) func fixturePayload(mods ...func(payload *iaas.CreateNetworkAreaRoutePayload)) iaas.CreateNetworkAreaRoutePayload { payload := iaas.CreateNetworkAreaRoutePayload{ - Items: &[]iaas.Route{ + Items: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(destinationCIDRv4Type), - Value: utils.Ptr(testDestinationCIDRv4), + Type: destinationCIDRv4Type, + Value: testDestinationCIDRv4, }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(nexthopIPv4Type), - Value: utils.Ptr(testNexthopIPv4), + Type: nexthopIPv4Type, + Value: testNexthopIPv4, }, }, }, @@ -192,7 +192,7 @@ func TestParseInput(t *testing.T) { flagValues[labelFlag] = "key=value" }), expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = utils.Ptr(map[string]string{"key": "value"}) + model.Labels = map[string]any{"key": "value"} }), isValid: true, }, @@ -236,11 +236,11 @@ func TestBuildRequest(t *testing.T) { { description: "optional labels provided", model: fixtureInputModel(func(model *inputModel) { - model.Labels = utils.Ptr(map[string]string{"key": "value"}) + model.Labels = map[string]any{"key": "value"} }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkAreaRouteRequest) { - *request = (*request).CreateNetworkAreaRoutePayload(fixturePayload(func(payload *iaas.CreateNetworkAreaRoutePayload) { - (*payload.Items)[0].Labels = utils.Ptr(map[string]interface{}{"key": "value"}) + *request = request.CreateNetworkAreaRoutePayload(fixturePayload(func(payload *iaas.CreateNetworkAreaRoutePayload) { + payload.Items[0].Labels = map[string]any{"key": "value"} })) }), }, @@ -252,7 +252,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -288,7 +288,7 @@ func TestOutputResult(t *testing.T) { params := testparams.NewTestParams() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreaLabel, tt.args.route); (err != nil) != tt.wantErr { + if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreaLabel, &tt.args.route); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/cmd/network-area/route/delete/delete.go b/internal/cmd/network-area/route/delete/delete.go index 55ec64472..862bccc62 100644 --- a/internal/cmd/network-area/route/delete/delete.go +++ b/internal/cmd/network-area/route/delete/delete.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -59,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, *model.OrganizationId, *model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = *model.NetworkAreaId @@ -110,6 +110,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNetworkAreaRouteRequest { - req := apiClient.DeleteNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.RouteId) + req := apiClient.DefaultAPI.DeleteNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.RouteId) return req } diff --git a/internal/cmd/network-area/route/delete/delete_test.go b/internal/cmd/network-area/route/delete/delete_test.go index 0e2b9e41c..caa136f10 100644 --- a/internal/cmd/network-area/route/delete/delete_test.go +++ b/internal/cmd/network-area/route/delete/delete_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -67,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteNetworkAreaRouteRequest)) iaas.ApiDeleteNetworkAreaRouteRequest { - request := testClient.DeleteNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId) + request := testClient.DefaultAPI.DeleteNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId) for _, mod := range mods { mod(&request) } @@ -233,7 +233,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-area/route/describe/describe.go b/internal/cmd/network-area/route/describe/describe.go index 070b47738..5e8a432ac 100644 --- a/internal/cmd/network-area/route/describe/describe.go +++ b/internal/cmd/network-area/route/describe/describe.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("describe static route: %w", err) } - return outputResult(params.Printer, model.OutputFormat, *resp) + return outputResult(params.Printer, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -102,50 +102,48 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNetworkAreaRouteRequest { - req := apiClient.GetNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.RouteId) + req := apiClient.DefaultAPI.GetNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.RouteId) return req } -func outputResult(p *print.Printer, outputFormat string, route iaas.Route) error { +func outputResult(p *print.Printer, outputFormat string, route *iaas.Route) error { return p.OutputResult(outputFormat, route, func() error { table := tables.NewTable() table.AddRow("ID", utils.PtrString(route.Id)) table.AddSeparator() - if destination := route.Destination; destination != nil { - if destination.DestinationCIDRv4 != nil { - table.AddRow("DESTINATION TYPE", utils.PtrString(destination.DestinationCIDRv4.Type)) - table.AddSeparator() - table.AddRow("DESTINATION", utils.PtrString(destination.DestinationCIDRv4.Value)) - table.AddSeparator() - } else if destination.DestinationCIDRv6 != nil { - table.AddRow("DESTINATION TYPE", utils.PtrString(destination.DestinationCIDRv6.Type)) - table.AddSeparator() - table.AddRow("DESTINATION", utils.PtrString(destination.DestinationCIDRv6.Value)) - table.AddSeparator() - } + destination := route.Destination + if destination.DestinationCIDRv4 != nil { + table.AddRow("DESTINATION TYPE", destination.DestinationCIDRv4.Type) + table.AddSeparator() + table.AddRow("DESTINATION", destination.DestinationCIDRv4.Value) + table.AddSeparator() + } else if destination.DestinationCIDRv6 != nil { + table.AddRow("DESTINATION TYPE", destination.DestinationCIDRv6.Type) + table.AddSeparator() + table.AddRow("DESTINATION", destination.DestinationCIDRv6.Value) + table.AddSeparator() } - if nexthop := route.Nexthop; nexthop != nil { - if nexthop.NexthopIPv4 != nil { - table.AddRow("NEXTHOP", utils.PtrString(nexthop.NexthopIPv4.Value)) - table.AddSeparator() - table.AddRow("NEXTHOP TYPE", utils.PtrString(nexthop.NexthopIPv4.Type)) - table.AddSeparator() - } else if nexthop.NexthopIPv6 != nil { - table.AddRow("NEXTHOP", utils.PtrString(nexthop.NexthopIPv6.Value)) - table.AddSeparator() - table.AddRow("NEXTHOP TYPE", utils.PtrString(nexthop.NexthopIPv6.Type)) - table.AddSeparator() - } else if nexthop.NexthopBlackhole != nil { - table.AddRow("NEXTHOP TYPE", utils.PtrString(nexthop.NexthopBlackhole.Type)) - table.AddSeparator() - } else if nexthop.NexthopInternet != nil { - table.AddRow("NEXTHOP TYPE", utils.PtrString(nexthop.NexthopInternet.Type)) - table.AddSeparator() - } + nexthop := route.Nexthop + if nexthop.NexthopIPv4 != nil { + table.AddRow("NEXTHOP", nexthop.NexthopIPv4.Value) + table.AddSeparator() + table.AddRow("NEXTHOP TYPE", nexthop.NexthopIPv4.Type) + table.AddSeparator() + } else if nexthop.NexthopIPv6 != nil { + table.AddRow("NEXTHOP", nexthop.NexthopIPv6.Value) + table.AddSeparator() + table.AddRow("NEXTHOP TYPE", nexthop.NexthopIPv6.Type) + table.AddSeparator() + } else if nexthop.NexthopBlackhole != nil { + table.AddRow("NEXTHOP TYPE", nexthop.NexthopBlackhole.Type) + table.AddSeparator() + } else if nexthop.NexthopInternet != nil { + table.AddRow("NEXTHOP TYPE", nexthop.NexthopInternet.Type) + table.AddSeparator() } - if route.Labels != nil && len(*route.Labels) > 0 { + if len(route.Labels) > 0 { labels := []string{} - for key, value := range *route.Labels { + for key, value := range route.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddSeparator() diff --git a/internal/cmd/network-area/route/describe/describe_test.go b/internal/cmd/network-area/route/describe/describe_test.go index 9dd0ec277..8e454ad06 100644 --- a/internal/cmd/network-area/route/describe/describe_test.go +++ b/internal/cmd/network-area/route/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -67,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkAreaRouteRequest)) iaas.ApiGetNetworkAreaRouteRequest { - request := testClient.GetNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId) + request := testClient.DefaultAPI.GetNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId) for _, mod := range mods { mod(&request) } @@ -233,7 +233,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -268,7 +268,7 @@ func TestOutputResult(t *testing.T) { params := testparams.NewTestParams() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.route); (err != nil) != tt.wantErr { + if err := outputResult(params.Printer, tt.args.outputFormat, &tt.args.route); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/cmd/network-area/route/list/list.go b/internal/cmd/network-area/route/list/list.go index 813f09c10..c9ef46f6a 100644 --- a/internal/cmd/network-area/route/list/list.go +++ b/internal/cmd/network-area/route/list/list.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -77,7 +77,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { items := resp.GetItems() var networkAreaLabel string - networkAreaLabel, err = iaasUtils.GetNetworkAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId) + networkAreaLabel, err = iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = model.NetworkAreaId @@ -126,7 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNetworkAreaRoutesRequest { - return apiClient.ListNetworkAreaRoutes(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + return apiClient.DefaultAPI.ListNetworkAreaRoutes(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) } func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, routes []iaas.Route) error { @@ -142,26 +142,24 @@ func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route var nextHop string var nextHopType string var destination string - if routeDest := route.Destination; routeDest != nil { - if routeDest.DestinationCIDRv4 != nil { - destination = *routeDest.DestinationCIDRv4.Value - } - if routeDest.DestinationCIDRv6 != nil { - destination = *routeDest.DestinationCIDRv6.Value - } + routeDest := route.Destination + if routeDest.DestinationCIDRv4 != nil { + destination = routeDest.DestinationCIDRv4.Value } - if routeNexthop := route.Nexthop; routeNexthop != nil { - if routeNexthop.NexthopIPv4 != nil { - nextHop = *routeNexthop.NexthopIPv4.Value - nextHopType = *routeNexthop.NexthopIPv4.Type - } else if routeNexthop.NexthopIPv6 != nil { - nextHop = *routeNexthop.NexthopIPv6.Value - nextHopType = *routeNexthop.NexthopIPv6.Type - } else if routeNexthop.NexthopBlackhole != nil { - nextHopType = *routeNexthop.NexthopBlackhole.Type - } else if routeNexthop.NexthopInternet != nil { - nextHopType = *routeNexthop.NexthopInternet.Type - } + if routeDest.DestinationCIDRv6 != nil { + destination = routeDest.DestinationCIDRv6.Value + } + routeNexthop := route.Nexthop + if routeNexthop.NexthopIPv4 != nil { + nextHop = routeNexthop.NexthopIPv4.Value + nextHopType = routeNexthop.NexthopIPv4.Type + } else if routeNexthop.NexthopIPv6 != nil { + nextHop = routeNexthop.NexthopIPv6.Value + nextHopType = routeNexthop.NexthopIPv6.Type + } else if routeNexthop.NexthopBlackhole != nil { + nextHopType = routeNexthop.NexthopBlackhole.Type + } else if routeNexthop.NexthopInternet != nil { + nextHopType = routeNexthop.NexthopInternet.Type } table.AddRow( diff --git a/internal/cmd/network-area/route/list/list_test.go b/internal/cmd/network-area/route/list/list_test.go index bcd79bf00..b83a47ce0 100644 --- a/internal/cmd/network-area/route/list/list_test.go +++ b/internal/cmd/network-area/route/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrganizationId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListNetworkAreaRoutesRequest)) iaas.ApiListNetworkAreaRoutesRequest { - request := testClient.ListNetworkAreaRoutes(testCtx, testOrganizationId, testNetworkAreaId, testRegion) + request := testClient.DefaultAPI.ListNetworkAreaRoutes(testCtx, testOrganizationId, testNetworkAreaId, testRegion) for _, mod := range mods { mod(&request) } @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -215,7 +215,7 @@ func TestOutputResult(t *testing.T) { name: "empty destination in route", args: args{ routes: []iaas.Route{{ - Destination: &iaas.RouteDestination{}, + Destination: iaas.RouteDestination{}, }}, }, wantErr: false, @@ -224,7 +224,7 @@ func TestOutputResult(t *testing.T) { name: "empty nexthop in route", args: args{ routes: []iaas.Route{{ - Nexthop: &iaas.RouteNexthop{}, + Nexthop: iaas.RouteNexthop{}, }}, }, wantErr: false, diff --git a/internal/cmd/network-area/route/update/update.go b/internal/cmd/network-area/route/update/update.go index 2a422a1d4..5cbad6a69 100644 --- a/internal/cmd/network-area/route/update/update.go +++ b/internal/cmd/network-area/route/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -34,7 +34,7 @@ type inputModel struct { OrganizationId *string NetworkAreaId *string RouteId string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -66,7 +66,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get network area label - networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient.DefaultAPI, *model.OrganizationId, *model.NetworkAreaId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = *model.NetworkAreaId @@ -79,7 +79,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("create static route: %w", err) } - return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, *resp) + return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, resp) }, } configureFlags(cmd) @@ -99,7 +99,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu routeId := inputArgs[0] globalFlags := globalflags.Parse(p, cmd) - labels := flags.FlagToStringToStringPointer(p, cmd, labelFlag) + labels := flags.FlagToStringToAny(p, cmd, labelFlag) if labels == nil { return nil, &cliErr.EmptyUpdateError{} @@ -118,17 +118,17 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateNetworkAreaRouteRequest { - req := apiClient.UpdateNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.RouteId) + req := apiClient.DefaultAPI.UpdateNetworkAreaRoute(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region, model.RouteId) payload := iaas.UpdateNetworkAreaRoutePayload{ - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } req = req.UpdateNetworkAreaRoutePayload(payload) return req } -func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route iaas.Route) error { +func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, route *iaas.Route) error { return p.OutputResult(outputFormat, route, func() error { p.Outputf("Updated static route for SNA %q.\nStatic route ID: %s\n", networkAreaLabel, utils.PtrString(route.Id)) return nil diff --git a/internal/cmd/network-area/route/update/update_test.go b/internal/cmd/network-area/route/update/update_test.go index 096c4e2be..edc9cd8cb 100644 --- a/internal/cmd/network-area/route/update/update_test.go +++ b/internal/cmd/network-area/route/update/update_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() @@ -54,7 +54,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixturePayload(mods ...func(payload *iaas.UpdateNetworkAreaRoutePayload)) iaas.UpdateNetworkAreaRoutePayload { payload := iaas.UpdateNetworkAreaRoutePayload{ - Labels: &map[string]interface{}{ + Labels: map[string]any{ "value": "key", }, } @@ -65,10 +65,10 @@ func fixturePayload(mods ...func(payload *iaas.UpdateNetworkAreaRoutePayload)) i return payload } -func fixturePayloadAsStringMap() map[string]string { +func fixturePayloadAsMap() map[string]any { payload := fixturePayload() - labelsMap := make(map[string]string) - for k, v := range *payload.Labels { + labelsMap := make(map[string]any) + for k, v := range payload.Labels { if value, ok := v.(string); ok { labelsMap[k] = value } @@ -77,7 +77,7 @@ func fixturePayloadAsStringMap() map[string]string { } func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { - payload := fixturePayloadAsStringMap() + payload := fixturePayloadAsMap() model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ Verbosity: globalflags.VerbosityDefault, @@ -86,7 +86,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { OrganizationId: utils.Ptr(testOrgId), NetworkAreaId: utils.Ptr(testNetworkAreaId), RouteId: testRouteId, - Labels: utils.Ptr(payload), + Labels: payload, } for _, mod := range mods { mod(model) @@ -95,7 +95,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateNetworkAreaRouteRequest)) iaas.ApiUpdateNetworkAreaRouteRequest { - request := testClient.UpdateNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId) + request := testClient.DefaultAPI.UpdateNetworkAreaRoute(testCtx, testOrgId, testNetworkAreaId, testRegion, testRouteId) request = request.UpdateNetworkAreaRoutePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -268,7 +268,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -304,7 +304,7 @@ func TestOutputResult(t *testing.T) { params := testparams.NewTestParams() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreaLabel, tt.args.route); (err != nil) != tt.wantErr { + if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreaLabel, &tt.args.route); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/cmd/network-area/routingtable/create/create.go b/internal/cmd/network-area/routingtable/create/create.go index aed268466..e1583e50d 100644 --- a/internal/cmd/network-area/routingtable/create/create.go +++ b/internal/cmd/network-area/routingtable/create/create.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -30,7 +30,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel Description *string - Labels *map[string]string + Labels map[string]any Name string NetworkAreaId string SystemRoutes bool @@ -117,7 +117,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, GlobalFlagModel: globalFlags, Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), DynamicRoutes: flags.FlagToBoolValue(p, cmd, dynamicRoutesFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), Name: flags.FlagToStringValue(p, cmd, nameFlag), NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag), OrganizationId: flags.FlagToStringValue(p, cmd, organizationIdFlag), @@ -131,13 +131,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) (iaas.ApiAddRoutingTableToAreaRequest, error) { payload := iaas.AddRoutingTableToAreaPayload{ Description: model.Description, - Name: utils.Ptr(model.Name), - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Name: model.Name, + Labels: model.Labels, SystemRoutes: utils.Ptr(model.SystemRoutes), DynamicRoutes: utils.Ptr(model.DynamicRoutes), } - return apiClient.AddRoutingTableToArea( + return apiClient.DefaultAPI.AddRoutingTableToArea( ctx, model.OrganizationId, model.NetworkAreaId, diff --git a/internal/cmd/network-area/routingtable/create/create_test.go b/internal/cmd/network-area/routingtable/create/create_test.go index 81250cba0..6aface406 100644 --- a/internal/cmd/network-area/routingtable/create/create_test.go +++ b/internal/cmd/network-area/routingtable/create/create_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -21,7 +21,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} const testRegion = "eu01" @@ -36,7 +36,7 @@ const testDynamicRoutesFlag = true const testLabelSelectorFlag = "key1=value1,key2=value2" -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -79,7 +79,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiAddRoutingTableToAreaRequest)) iaas.ApiAddRoutingTableToAreaRequest { - request := testClient.AddRoutingTableToArea(testCtx, testOrgId, testNetworkAreaId, testRegion) + request := testClient.DefaultAPI.AddRoutingTableToArea(testCtx, testOrgId, testNetworkAreaId, testRegion) request = request.AddRoutingTableToAreaPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -90,8 +90,8 @@ func fixtureRequest(mods ...func(request *iaas.ApiAddRoutingTableToAreaRequest)) func fixturePayload(mods ...func(payload *iaas.AddRoutingTableToAreaPayload)) iaas.AddRoutingTableToAreaPayload { payload := iaas.AddRoutingTableToAreaPayload{ Description: utils.Ptr(testRoutingTableDescription), - Name: utils.Ptr(testRoutingTableName), - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Name: testRoutingTableName, + Labels: testLabels, SystemRoutes: utils.Ptr(true), DynamicRoutes: utils.Ptr(true), } @@ -236,7 +236,7 @@ func TestBuildRequest(t *testing.T) { model.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) { - *request = (*request).AddRoutingTableToAreaPayload( + *request = request.AddRoutingTableToAreaPayload( fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) { payload.Labels = nil }), @@ -249,7 +249,7 @@ func TestBuildRequest(t *testing.T) { model.SystemRoutes = false }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) { - *request = (*request).AddRoutingTableToAreaPayload( + *request = request.AddRoutingTableToAreaPayload( fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) { payload.SystemRoutes = utils.Ptr(false) }), @@ -262,7 +262,7 @@ func TestBuildRequest(t *testing.T) { model.DynamicRoutes = false }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) { - *request = (*request).AddRoutingTableToAreaPayload( + *request = request.AddRoutingTableToAreaPayload( fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) { payload.DynamicRoutes = utils.Ptr(false) }), @@ -280,7 +280,7 @@ func TestBuildRequest(t *testing.T) { if diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx)); diff != "" { + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{})); diff != "" { t.Errorf("buildRequest() mismatch (-got +want):\n%s", diff) } }) @@ -290,11 +290,11 @@ func TestBuildRequest(t *testing.T) { func TestOutputResult(t *testing.T) { dummyRoutingTable := iaas.RoutingTable{ Id: utils.Ptr("id-foo"), - Name: utils.Ptr("route-table-foo"), + Name: "route-table-foo", Description: utils.Ptr("description-foo"), SystemRoutes: utils.Ptr(true), DynamicRoutes: utils.Ptr(true), - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, CreatedAt: utils.Ptr(time.Now()), UpdatedAt: utils.Ptr(time.Now()), } diff --git a/internal/cmd/network-area/routingtable/delete/delete.go b/internal/cmd/network-area/routingtable/delete/delete.go index 1ae94658c..07b7aedc9 100644 --- a/internal/cmd/network-area/routingtable/delete/delete.go +++ b/internal/cmd/network-area/routingtable/delete/delete.go @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) + routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err) routingTableLabel = model.RoutingTableId @@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - req := apiClient.DeleteRoutingTableFromArea( + req := apiClient.DefaultAPI.DeleteRoutingTableFromArea( ctx, model.OrganizationId, model.NetworkAreaId, diff --git a/internal/cmd/network-area/routingtable/describe/describe.go b/internal/cmd/network-area/routingtable/describe/describe.go index 8292e3f9b..d1323a110 100644 --- a/internal/cmd/network-area/routingtable/describe/describe.go +++ b/internal/cmd/network-area/routingtable/describe/describe.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - request := apiClient.GetRoutingTableOfArea( + request := apiClient.DefaultAPI.GetRoutingTableOfArea( ctx, model.OrganizationId, model.NetworkAreaId, @@ -113,7 +113,7 @@ func outputResult(p *print.Printer, outputFormat string, routingTable *iaas.Rout table.AddRow("ID", utils.PtrString(routingTable.Id)) table.AddSeparator() - table.AddRow("NAME", utils.PtrString(routingTable.Name)) + table.AddRow("NAME", routingTable.Name) table.AddSeparator() table.AddRow("DESCRIPTION", utils.PtrString(routingTable.Description)) @@ -122,9 +122,9 @@ func outputResult(p *print.Printer, outputFormat string, routingTable *iaas.Rout table.AddRow("DEFAULT", utils.PtrString(routingTable.Default)) table.AddSeparator() - if routingTable.Labels != nil && len(*routingTable.Labels) > 0 { + if routingTable.Labels != nil && len(routingTable.Labels) > 0 { var labels []string - for key, value := range *routingTable.Labels { + for key, value := range routingTable.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/network-area/routingtable/describe/describe_test.go b/internal/cmd/network-area/routingtable/describe/describe_test.go index 832043f62..44ee066b3 100644 --- a/internal/cmd/network-area/routingtable/describe/describe_test.go +++ b/internal/cmd/network-area/routingtable/describe/describe_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -20,7 +20,7 @@ var testOrgId = uuid.NewString() var testNetworkAreaId = uuid.NewString() var testRoutingTableId = uuid.NewString() -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -159,8 +159,8 @@ func TestOutputResult(t *testing.T) { Default: nil, Description: utils.Ptr("description"), Id: utils.Ptr("route-foo"), - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), - Name: utils.Ptr("route-foo"), + Labels: testLabels, + Name: "route-foo", SystemRoutes: utils.Ptr(true), DynamicRoutes: utils.Ptr(true), UpdatedAt: utils.Ptr(time.Now()), diff --git a/internal/cmd/network-area/routingtable/list/list.go b/internal/cmd/network-area/routingtable/list/list.go index 82553f83c..01c8c8e25 100644 --- a/internal/cmd/network-area/routingtable/list/list.go +++ b/internal/cmd/network-area/routingtable/list/list.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -76,7 +76,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("list routing-tables: %w", err) } - routingTables := utils.GetSliceFromPointer(response.Items) + routingTables := response.Items // Truncate output if model.Limit != nil && len(routingTables) > int(*model.Limit) { @@ -125,7 +125,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListRoutingTablesOfAreaRequest { - request := apiClient.ListRoutingTablesOfArea(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) + request := apiClient.DefaultAPI.ListRoutingTablesOfArea(ctx, model.OrganizationId, model.NetworkAreaId, model.Region) if model.LabelSelector != nil { request = request.LabelSelector(*model.LabelSelector) } @@ -148,15 +148,15 @@ func outputResult(p *print.Printer, outputFormat string, routingTables []iaas.Ro table.SetHeader("ID", "NAME", "DESCRIPTION", "DEFAULT", "LABELS", "SYSTEM ROUTES", "DYNAMIC ROUTES", "CREATED AT", "UPDATED AT") for _, routingTable := range routingTables { var labels []string - if routingTable.Labels != nil && len(*routingTable.Labels) > 0 { - for key, value := range *routingTable.Labels { + if len(routingTable.Labels) > 0 { + for key, value := range routingTable.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } } table.AddRow( utils.PtrString(routingTable.Id), - utils.PtrString(routingTable.Name), + routingTable.Name, utils.PtrString(routingTable.Description), utils.PtrString(routingTable.Default), strings.Join(labels, "\n"), diff --git a/internal/cmd/network-area/routingtable/list/list_test.go b/internal/cmd/network-area/routingtable/list/list_test.go index cd03c67d6..2cd1fc5ed 100644 --- a/internal/cmd/network-area/routingtable/list/list_test.go +++ b/internal/cmd/network-area/routingtable/list/list_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -25,7 +25,7 @@ var testNetworkAreaId = uuid.NewString() const testLabelSelectorFlag = "key1=value1,key2=value2" -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -33,7 +33,7 @@ var testLabels = &map[string]string{ type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testLimitFlag = int64(10) func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -51,7 +51,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st } func fixtureRequest(mods ...func(request *iaas.ApiListRoutingTablesOfAreaRequest)) iaas.ApiListRoutingTablesOfAreaRequest { - request := testClient.ListRoutingTablesOfArea(testCtx, testOrgId, testNetworkAreaId, testRegion) + request := testClient.DefaultAPI.ListRoutingTablesOfArea(testCtx, testOrgId, testNetworkAreaId, testRegion) request = request.LabelSelector(testLabelSelectorFlag) for _, mod := range mods { @@ -159,8 +159,8 @@ func TestOutputResult(t *testing.T) { Default: nil, Description: utils.Ptr("description"), Id: utils.Ptr("route-foo"), - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), - Name: utils.Ptr("route-foo"), + Labels: testLabels, + Name: "route-foo", SystemRoutes: utils.Ptr(true), DynamicRoutes: utils.Ptr(true), UpdatedAt: utils.Ptr(time.Now()), @@ -261,7 +261,7 @@ func TestBuildRequest(t *testing.T) { model.LabelSelector = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiListRoutingTablesOfAreaRequest) { - *request = testClient.ListRoutingTablesOfArea(testCtx, testOrgId, testNetworkAreaId, testRegion) + *request = testClient.DefaultAPI.ListRoutingTablesOfArea(testCtx, testOrgId, testNetworkAreaId, testRegion) }), }, } @@ -272,7 +272,7 @@ func TestBuildRequest(t *testing.T) { if diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx)); diff != "" { + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{})); diff != "" { t.Errorf("buildRequest() mismatch (-got +want):\n%s", diff) } }) diff --git a/internal/cmd/network-area/routingtable/route/create/create.go b/internal/cmd/network-area/routingtable/route/create/create.go index d3455087d..5f479299f 100644 --- a/internal/cmd/network-area/routingtable/route/create/create.go +++ b/internal/cmd/network-area/routingtable/route/create/create.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -45,7 +45,7 @@ type inputModel struct { *globalflags.GlobalFlagModel DestinationType string DestinationValue *string - Labels *map[string]string + Labels map[string]any NetworkAreaId string NextHopType string NextHopValue *string @@ -81,7 +81,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) + routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err) routingTableLabel = model.RoutingTableId @@ -142,7 +142,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, GlobalFlagModel: globalFlags, DestinationType: flags.FlagToStringValue(p, cmd, destinationTypeFlag), DestinationValue: flags.FlagToStringPointer(p, cmd, destinationValueFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag), NextHopType: flags.FlagToStringValue(p, cmd, nextHopTypeFlag), NextHopValue: flags.FlagToStringPointer(p, cmd, nextHopValueFlag), @@ -174,16 +174,16 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli if destination != nil && nextHop != nil { payload := iaas.AddRoutesToRoutingTablePayload{ - Items: &[]iaas.Route{ + Items: []iaas.Route{ { - Destination: destination, - Nexthop: nextHop, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Destination: *destination, + Nexthop: *nextHop, + Labels: model.Labels, }, }, } - return apiClient.AddRoutesToRoutingTable( + return apiClient.DefaultAPI.AddRoutesToRoutingTable( ctx, model.OrganizationId, model.NetworkAreaId, @@ -192,7 +192,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli ).AddRoutesToRoutingTablePayload(payload), nil } - return nil, fmt.Errorf("invalid input") + return iaas.ApiAddRoutesToRoutingTableRequest{}, fmt.Errorf("invalid input") } func buildDestination(model *inputModel) *iaas.RouteDestination { @@ -205,15 +205,15 @@ func buildDestination(model *inputModel) *iaas.RouteDestination { case destTypeCIDRv4: return &iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: &model.DestinationType, - Value: model.DestinationValue, + Type: model.DestinationType, + Value: *model.DestinationValue, }, } case destTypeCIDRv6: return &iaas.RouteDestination{ DestinationCIDRv6: &iaas.DestinationCIDRv6{ - Type: &model.DestinationType, - Value: model.DestinationValue, + Type: model.DestinationType, + Value: *model.DestinationValue, }, } default: @@ -227,27 +227,27 @@ func buildNextHop(model *inputModel) *iaas.RouteNexthop { case nextHopTypeIPv4: return &iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: &model.NextHopType, - Value: model.NextHopValue, + Type: model.NextHopType, + Value: *model.NextHopValue, }, } case nextHopTypeIPv6: return &iaas.RouteNexthop{ NexthopIPv6: &iaas.NexthopIPv6{ - Type: &model.NextHopType, - Value: model.NextHopValue, + Type: model.NextHopType, + Value: *model.NextHopValue, }, } case nextHopTypeInternet: return &iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: &model.NextHopType, + Type: model.NextHopType, }, } case nextHopTypeBlackhole: return &iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: &model.NextHopType, + Type: model.NextHopType, }, } default: diff --git a/internal/cmd/network-area/routingtable/route/create/create_test.go b/internal/cmd/network-area/routingtable/route/create/create_test.go index 52be1dcd6..2f0de6965 100644 --- a/internal/cmd/network-area/routingtable/route/create/create_test.go +++ b/internal/cmd/network-area/routingtable/route/create/create_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -20,7 +20,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} const testRegion = "eu01" @@ -34,7 +34,7 @@ const testNextHopTypeFlag = nextHopTypeIPv4 const testNextHopValueFlag = "1.1.1.1" const testLabelSelectorFlag = "key1=value1,key2=value2" -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -79,7 +79,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiAddRoutesToRoutingTableRequest)) iaas.ApiAddRoutesToRoutingTableRequest { - request := testClient.AddRoutesToRoutingTable(testCtx, testOrgId, testNetworkAreaId, testRegion, testRoutingTableId) + request := testClient.DefaultAPI.AddRoutesToRoutingTable(testCtx, testOrgId, testNetworkAreaId, testRegion, testRoutingTableId) request = request.AddRoutesToRoutingTablePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -89,21 +89,21 @@ func fixtureRequest(mods ...func(request *iaas.ApiAddRoutesToRoutingTableRequest func fixturePayload(mods ...func(payload *iaas.AddRoutesToRoutingTablePayload)) iaas.AddRoutesToRoutingTablePayload { payload := iaas.AddRoutesToRoutingTablePayload{ - Items: &[]iaas.Route{ + Items: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(testDestinationTypeFlag), - Value: utils.Ptr(testDestinationValueFlag), + Type: testDestinationTypeFlag, + Value: testDestinationValueFlag, }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(testNextHopTypeFlag), - Value: utils.Ptr(testNextHopValueFlag), + Type: testNextHopTypeFlag, + Value: testNextHopValueFlag, }, }, - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, }, }, } @@ -319,7 +319,7 @@ func TestParseInput(t *testing.T) { flagValues[labelFlag] = "key=value" }), expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = utils.Ptr(map[string]string{"key": "value"}) + model.Labels = map[string]any{"key": "value"} }), isValid: true, }, @@ -360,8 +360,8 @@ func TestBuildNextHop(t *testing.T) { }), expected: &iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(nextHopTypeIPv4), - Value: utils.Ptr("1.1.1.1"), + Type: nextHopTypeIPv4, + Value: "1.1.1.1", }, }, }, @@ -373,8 +373,8 @@ func TestBuildNextHop(t *testing.T) { }), expected: &iaas.RouteNexthop{ NexthopIPv6: &iaas.NexthopIPv6{ - Type: utils.Ptr(nextHopTypeIPv6), - Value: utils.Ptr("::1"), + Type: nextHopTypeIPv6, + Value: "::1", }, }, }, @@ -386,7 +386,7 @@ func TestBuildNextHop(t *testing.T) { }), expected: &iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr(nextHopTypeInternet), + Type: nextHopTypeInternet, }, }, }, @@ -398,7 +398,7 @@ func TestBuildNextHop(t *testing.T) { }), expected: &iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr(nextHopTypeBlackhole), + Type: nextHopTypeBlackhole, }, }, }, @@ -435,8 +435,8 @@ func TestBuildDestination(t *testing.T) { }), expected: &iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(destTypeCIDRv4), - Value: utils.Ptr("192.168.1.0/24"), + Type: destTypeCIDRv4, + Value: "192.168.1.0/24", }, }, }, @@ -448,8 +448,8 @@ func TestBuildDestination(t *testing.T) { }), expected: &iaas.RouteDestination{ DestinationCIDRv6: &iaas.DestinationCIDRv6{ - Type: utils.Ptr(destTypeCIDRv6), - Value: utils.Ptr("2001:db8::/32"), + Type: destTypeCIDRv6, + Value: "2001:db8::/32", }, }, }, @@ -494,11 +494,11 @@ func TestBuildRequest(t *testing.T) { { description: "optional labels provided", model: fixtureInputModel(func(model *inputModel) { - model.Labels = utils.Ptr(map[string]string{"key": "value"}) + model.Labels = map[string]any{"key": "value"} }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutesToRoutingTableRequest) { - *request = (*request).AddRoutesToRoutingTablePayload(fixturePayload(func(payload *iaas.AddRoutesToRoutingTablePayload) { - (*payload.Items)[0].Labels = utils.ConvertStringMapToInterfaceMap(utils.Ptr(map[string]string{"key": "value"})) + *request = request.AddRoutesToRoutingTablePayload(fixturePayload(func(payload *iaas.AddRoutesToRoutingTablePayload) { + payload.Items[0].Labels = map[string]any{"key": "value"} })) }), }, @@ -511,22 +511,22 @@ func TestBuildRequest(t *testing.T) { model.NextHopValue = utils.Ptr("2001:db8::1") }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutesToRoutingTableRequest) { - *request = (*request).AddRoutesToRoutingTablePayload(iaas.AddRoutesToRoutingTablePayload{ - Items: &[]iaas.Route{ + *request = request.AddRoutesToRoutingTablePayload(iaas.AddRoutesToRoutingTablePayload{ + Items: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv6: &iaas.DestinationCIDRv6{ - Type: utils.Ptr(destTypeCIDRv6), - Value: utils.Ptr("2001:db8::/32"), + Type: destTypeCIDRv6, + Value: "2001:db8::/32", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv6: &iaas.NexthopIPv6{ - Type: utils.Ptr(nextHopTypeIPv6), - Value: utils.Ptr("2001:db8::1"), + Type: nextHopTypeIPv6, + Value: "2001:db8::1", }, }, - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, }, }, }) @@ -540,13 +540,13 @@ func TestBuildRequest(t *testing.T) { }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutesToRoutingTableRequest) { payload := fixturePayload(func(payload *iaas.AddRoutesToRoutingTablePayload) { - (*payload.Items)[0].Nexthop = &iaas.RouteNexthop{ + payload.Items[0].Nexthop = iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr(nextHopTypeInternet), + Type: nextHopTypeInternet, }, } }) - *request = (*request).AddRoutesToRoutingTablePayload(payload) + *request = request.AddRoutesToRoutingTablePayload(payload) }), }, { @@ -557,13 +557,13 @@ func TestBuildRequest(t *testing.T) { }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutesToRoutingTableRequest) { payload := fixturePayload(func(payload *iaas.AddRoutesToRoutingTablePayload) { - (*payload.Items)[0].Nexthop = &iaas.RouteNexthop{ + payload.Items[0].Nexthop = iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr(nextHopTypeBlackhole), + Type: nextHopTypeBlackhole, }, } }) - *request = (*request).AddRoutesToRoutingTablePayload(payload) + *request = request.AddRoutesToRoutingTablePayload(payload) }), }, { @@ -574,14 +574,14 @@ func TestBuildRequest(t *testing.T) { }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutesToRoutingTableRequest) { payload := fixturePayload(func(payload *iaas.AddRoutesToRoutingTablePayload) { - (*payload.Items)[0].Nexthop = &iaas.RouteNexthop{ + payload.Items[0].Nexthop = iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(nextHopTypeIPv4), - Value: utils.Ptr("1.2.3.4"), + Type: nextHopTypeIPv4, + Value: "1.2.3.4", }, } }) - *request = (*request).AddRoutesToRoutingTablePayload(payload) + *request = request.AddRoutesToRoutingTablePayload(payload) }), }, { @@ -592,14 +592,14 @@ func TestBuildRequest(t *testing.T) { }), expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutesToRoutingTableRequest) { payload := fixturePayload(func(payload *iaas.AddRoutesToRoutingTablePayload) { - (*payload.Items)[0].Nexthop = &iaas.RouteNexthop{ + payload.Items[0].Nexthop = iaas.RouteNexthop{ NexthopIPv6: &iaas.NexthopIPv6{ - Type: utils.Ptr(nextHopTypeIPv6), - Value: utils.Ptr("2001:db8::1"), + Type: nextHopTypeIPv6, + Value: "2001:db8::1", }, } }) - *request = (*request).AddRoutesToRoutingTablePayload(payload) + *request = request.AddRoutesToRoutingTablePayload(payload) }), }, } @@ -613,7 +613,7 @@ func TestBuildRequest(t *testing.T) { if diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx)); diff != "" { + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{})); diff != "" { t.Errorf("buildRequest() mismatch (-got +want):\n%s", diff) } }) @@ -623,19 +623,19 @@ func TestBuildRequest(t *testing.T) { func TestOutputResult(t *testing.T) { dummyRoute := iaas.Route{ Id: utils.Ptr("route-foo"), - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(destTypeCIDRv4), - Value: utils.Ptr("10.0.0.0/24"), + Type: destTypeCIDRv4, + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(nextHopTypeIPv4), - Value: utils.Ptr("10.0.0.1"), + Type: nextHopTypeIPv4, + Value: "10.0.0.1", }, }, - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, CreatedAt: utils.Ptr(time.Now()), UpdatedAt: utils.Ptr(time.Now()), } diff --git a/internal/cmd/network-area/routingtable/route/delete/delete.go b/internal/cmd/network-area/routingtable/route/delete/delete.go index ba4ea28cb..b36069e4b 100644 --- a/internal/cmd/network-area/routingtable/route/delete/delete.go +++ b/internal/cmd/network-area/routingtable/route/delete/delete.go @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) + routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err) routingTableLabel = model.RoutingTableId @@ -72,7 +72,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - req := apiClient.DeleteRouteFromRoutingTable( + req := apiClient.DefaultAPI.DeleteRouteFromRoutingTable( ctx, model.OrganizationId, model.NetworkAreaId, diff --git a/internal/cmd/network-area/routingtable/route/describe/describe.go b/internal/cmd/network-area/routingtable/route/describe/describe.go index 128394538..779ff8664 100644 --- a/internal/cmd/network-area/routingtable/route/describe/describe.go +++ b/internal/cmd/network-area/routingtable/route/describe/describe.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -61,7 +61,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - request := apiClient.GetRouteOfRoutingTable( + request := apiClient.DefaultAPI.GetRouteOfRoutingTable( ctx, model.OrganizationId, model.NetworkAreaId, @@ -114,7 +114,7 @@ func outputResult(p *print.Printer, outputFormat string, route *iaas.Route) erro } return p.OutputResult(outputFormat, route, func() error { - routeDetails := routeUtils.ExtractRouteDetails(*route) + routeDetails := routeUtils.ExtractRouteDetails(route) table := tables.NewTable() @@ -133,9 +133,9 @@ func outputResult(p *print.Printer, outputFormat string, route *iaas.Route) erro table.AddRow("NEXTHOP VALUE", routeDetails.HopValue) table.AddSeparator() - if route.Labels != nil && len(*route.Labels) > 0 { + if route.Labels != nil && len(route.Labels) > 0 { var labels []string - for key, value := range *route.Labels { + for key, value := range route.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/network-area/routingtable/route/describe/describe_test.go b/internal/cmd/network-area/routingtable/route/describe/describe_test.go index a6dbdfe5b..d710a27ca 100644 --- a/internal/cmd/network-area/routingtable/route/describe/describe_test.go +++ b/internal/cmd/network-area/routingtable/route/describe/describe_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -21,7 +21,7 @@ var testNetworkAreaId = uuid.NewString() var testRoutingTableId = uuid.NewString() var testRouteId = uuid.NewString() -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -161,19 +161,19 @@ func TestParseInput(t *testing.T) { func TestOutputResult(t *testing.T) { dummyRoute := iaas.Route{ Id: utils.Ptr("route-foo"), - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr("cidrv4"), - Value: utils.Ptr("10.0.0.0/24"), + Type: "cidrv4", + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr("ipv4"), - Value: utils.Ptr("10.0.0.1"), + Type: "ipv4", + Value: "10.0.0.1", }, }, - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, CreatedAt: utils.Ptr(time.Now()), UpdatedAt: utils.Ptr(time.Now()), } @@ -196,12 +196,6 @@ func TestOutputResult(t *testing.T) { route: &iaas.Route{}, wantErr: false, }, - { - name: "json empty route", - outputFormat: print.JSONOutputFormat, - route: &iaas.Route{}, - wantErr: false, - }, { name: "pretty output with one route", outputFormat: print.PrettyOutputFormat, diff --git a/internal/cmd/network-area/routingtable/route/list/list.go b/internal/cmd/network-area/routingtable/route/list/list.go index 4fe9f1122..bf396ff8a 100644 --- a/internal/cmd/network-area/routingtable/route/list/list.go +++ b/internal/cmd/network-area/routingtable/route/list/list.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - request := apiClient.ListRoutesOfRoutingTable( + request := apiClient.DefaultAPI.ListRoutesOfRoutingTable( ctx, model.OrganizationId, model.NetworkAreaId, @@ -88,7 +88,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("list routes: %w", err) } - routes := utils.GetSliceFromPointer(response.Items) + routes := response.Items // Truncate output if model.Limit != nil && len(routes) > int(*model.Limit) { @@ -152,7 +152,7 @@ func outputResult(p *print.Printer, outputFormat string, routes []iaas.Route, or table := tables.NewTable() table.SetHeader("ID", "DESTINATION TYPE", "DESTINATION VALUE", "NEXTHOP TYPE", "NEXTHOP VALUE", "LABELS", "CREATED AT", "UPDATED AT") for _, route := range routes { - routeDetails := routeUtils.ExtractRouteDetails(route) + routeDetails := routeUtils.ExtractRouteDetails(&route) table.AddRow( utils.PtrString(route.Id), routeDetails.DestType, diff --git a/internal/cmd/network-area/routingtable/route/list/list_test.go b/internal/cmd/network-area/routingtable/route/list/list_test.go index f6ab6450e..f645267d8 100644 --- a/internal/cmd/network-area/routingtable/route/list/list_test.go +++ b/internal/cmd/network-area/routingtable/route/list/list_test.go @@ -6,7 +6,7 @@ import ( "time" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -23,7 +23,7 @@ var testRoutingTableId = uuid.NewString() const testLabelSelectorFlag = "key1=value1,key2=value2" -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -156,19 +156,19 @@ func TestParseInput(t *testing.T) { func TestOutputResult(t *testing.T) { dummyRoute := iaas.Route{ Id: utils.Ptr("route-foo"), - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr("cidrv4"), - Value: utils.Ptr("10.0.0.0/24"), + Type: "cidrv4", + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr("ipv4"), - Value: utils.Ptr("10.0.0.1"), + Type: "ipv4", + Value: "10.0.0.1", }, }, - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, CreatedAt: utils.Ptr(time.Now()), UpdatedAt: utils.Ptr(time.Now()), } diff --git a/internal/cmd/network-area/routingtable/route/update/update.go b/internal/cmd/network-area/routingtable/route/update/update.go index 719043be2..11ae98d72 100644 --- a/internal/cmd/network-area/routingtable/route/update/update.go +++ b/internal/cmd/network-area/routingtable/route/update/update.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -29,7 +29,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Labels *map[string]string + Labels map[string]any NetworkAreaId string OrganizationId string RouteId string @@ -61,7 +61,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) + routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err) routingTableLabel = model.RoutingTableId @@ -103,7 +103,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu routeId := inputArgs[0] - labels := flags.FlagToStringToStringPointer(p, cmd, labelFlag) + labels := flags.FlagToStringToAny(p, cmd, labelFlag) if labels == nil { return nil, &cliErr.EmptyUpdateError{} @@ -138,7 +138,7 @@ func outputResult(p *print.Printer, outputFormat, routingTableId, networkAreaId } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateRouteOfRoutingTableRequest { - req := apiClient.UpdateRouteOfRoutingTable( + req := apiClient.DefaultAPI.UpdateRouteOfRoutingTable( ctx, model.OrganizationId, model.NetworkAreaId, @@ -148,7 +148,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli ) payload := iaas.UpdateRouteOfRoutingTablePayload{ - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.UpdateRouteOfRoutingTablePayload(payload) diff --git a/internal/cmd/network-area/routingtable/route/update/update_test.go b/internal/cmd/network-area/routingtable/route/update/update_test.go index 0866de030..15c8f4144 100644 --- a/internal/cmd/network-area/routingtable/route/update/update_test.go +++ b/internal/cmd/network-area/routingtable/route/update/update_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -20,7 +20,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} const testRegion = "eu01" @@ -31,7 +31,7 @@ var testRouteId = uuid.NewString() const testLabelSelectorFlag = "key1=value1,key2=value2" -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -79,7 +79,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string { } func fixtureRequest(mods ...func(req *iaas.ApiUpdateRouteOfRoutingTableRequest)) iaas.ApiUpdateRouteOfRoutingTableRequest { - req := testClient.UpdateRouteOfRoutingTable( + req := testClient.DefaultAPI.UpdateRouteOfRoutingTable( testCtx, testOrgId, testNetworkAreaId, @@ -89,7 +89,7 @@ func fixtureRequest(mods ...func(req *iaas.ApiUpdateRouteOfRoutingTableRequest)) ) payload := iaas.UpdateRouteOfRoutingTablePayload{ - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, } req = req.UpdateRouteOfRoutingTablePayload(payload) @@ -208,7 +208,7 @@ func TestBuildRequest(t *testing.T) { m.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRouteOfRoutingTableRequest) { - *request = (*request).UpdateRouteOfRoutingTablePayload(iaas.UpdateRouteOfRoutingTablePayload{ + *request = request.UpdateRouteOfRoutingTablePayload(iaas.UpdateRouteOfRoutingTablePayload{ Labels: nil, }) }), @@ -223,7 +223,7 @@ func TestBuildRequest(t *testing.T) { tt.expectedRequest, gotReq, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ); diff != "" { t.Errorf("buildRequest() mismatch (-want +got):\n%s", diff) } @@ -234,19 +234,19 @@ func TestBuildRequest(t *testing.T) { func TestOutputResult(t *testing.T) { dummyRoute := iaas.Route{ Id: utils.Ptr("route-foo"), - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr("cidrv4"), - Value: utils.Ptr("10.0.0.0/24"), + Type: "cidrv4", + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr("ipv4"), - Value: utils.Ptr("10.0.0.1"), + Type: "ipv4", + Value: "10.0.0.1", }, }, - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, CreatedAt: utils.Ptr(time.Now()), UpdatedAt: utils.Ptr(time.Now()), } diff --git a/internal/cmd/network-area/routingtable/update/update.go b/internal/cmd/network-area/routingtable/update/update.go index 0d01f5e81..bdee91c1d 100644 --- a/internal/cmd/network-area/routingtable/update/update.go +++ b/internal/cmd/network-area/routingtable/update/update.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -37,7 +37,7 @@ type inputModel struct { SystemRoutes *bool RoutingTableId string Description *string - Labels *map[string]string + Labels map[string]any Name *string } @@ -82,7 +82,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) + routingTableLabel, err := iaasUtils.GetRoutingTableOfAreaName(ctx, apiClient.DefaultAPI, model.OrganizationId, model.NetworkAreaId, model.Region, model.RoutingTableId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get routing-table name: %v", err) routingTableLabel = model.RoutingTableId @@ -131,7 +131,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu model := inputModel{ GlobalFlagModel: globalFlags, Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), Name: flags.FlagToStringPointer(p, cmd, nameFlag), NetworkAreaId: flags.FlagToStringValue(p, cmd, networkAreaIdFlag), SystemRoutes: flags.FlagToBoolPointer(p, cmd, systemRoutesFlag), @@ -160,7 +160,7 @@ func outputResult(p *print.Printer, outputFormat, networkAreaId string, routingT } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateRoutingTableOfAreaRequest { - req := apiClient.UpdateRoutingTableOfArea( + req := apiClient.DefaultAPI.UpdateRoutingTableOfArea( ctx, model.OrganizationId, model.NetworkAreaId, @@ -169,7 +169,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli ) payload := iaas.UpdateRoutingTableOfAreaPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, Name: model.Name, Description: model.Description, DynamicRoutes: model.DynamicRoutes, diff --git a/internal/cmd/network-area/routingtable/update/update_test.go b/internal/cmd/network-area/routingtable/update/update_test.go index 04d1c4f0d..f3289a256 100644 --- a/internal/cmd/network-area/routingtable/update/update_test.go +++ b/internal/cmd/network-area/routingtable/update/update_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" @@ -21,7 +21,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} const testRegion = "eu01" @@ -36,7 +36,7 @@ const testLabelSelectorFlag = "key1=value1,key2=value2" const testSystemRoutesFlag = true const testDynamicRoutesFlag = true -var testLabels = &map[string]string{ +var testLabels = map[string]any{ "key1": "value1", "key2": "value2", } @@ -89,7 +89,7 @@ func fixtureArgValues(mods ...func(argValues []string)) []string { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateRoutingTableOfAreaRequest)) iaas.ApiUpdateRoutingTableOfAreaRequest { - req := testClient.UpdateRoutingTableOfArea( + req := testClient.DefaultAPI.UpdateRoutingTableOfArea( testCtx, testOrgId, testNetworkAreaId, @@ -98,7 +98,7 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdateRoutingTableOfAreaReques ) payload := iaas.UpdateRoutingTableOfAreaPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, Name: utils.Ptr(testRoutingTableName), Description: utils.Ptr(testRoutingTableDescription), DynamicRoutes: utils.Ptr(true), @@ -264,7 +264,7 @@ func TestBuildRequest(t *testing.T) { model.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) { - *request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ + *request = request.UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ Labels: nil, Name: utils.Ptr(testRoutingTableName), Description: utils.Ptr(testRoutingTableDescription), @@ -280,8 +280,8 @@ func TestBuildRequest(t *testing.T) { model.Name = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) { - *request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + *request = request.UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ + Labels: testLabels, Name: nil, Description: utils.Ptr(testRoutingTableDescription), DynamicRoutes: utils.Ptr(true), @@ -296,8 +296,8 @@ func TestBuildRequest(t *testing.T) { model.Description = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) { - *request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + *request = request.UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ + Labels: testLabels, Name: utils.Ptr(testRoutingTableName), Description: nil, DynamicRoutes: utils.Ptr(true), @@ -312,8 +312,8 @@ func TestBuildRequest(t *testing.T) { model.DynamicRoutes = utils.Ptr(false) }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) { - *request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + *request = request.UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ + Labels: testLabels, Name: utils.Ptr(testRoutingTableName), Description: utils.Ptr(testRoutingTableDescription), DynamicRoutes: utils.Ptr(false), @@ -328,8 +328,8 @@ func TestBuildRequest(t *testing.T) { model.DynamicRoutes = utils.Ptr(false) }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateRoutingTableOfAreaRequest) { - *request = (*request).UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + *request = request.UpdateRoutingTableOfAreaPayload(iaas.UpdateRoutingTableOfAreaPayload{ + Labels: testLabels, Name: utils.Ptr(testRoutingTableName), Description: utils.Ptr(testRoutingTableDescription), SystemRoutes: utils.Ptr(true), @@ -345,7 +345,7 @@ func TestBuildRequest(t *testing.T) { if diff := cmp.Diff(req, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ); diff != "" { t.Errorf("buildRequest() mismatch (-got +want):\n%s", diff) } @@ -356,11 +356,11 @@ func TestBuildRequest(t *testing.T) { func TestOutputResult(t *testing.T) { dummyRoutingTable := iaas.RoutingTable{ Id: utils.Ptr("id-foo"), - Name: utils.Ptr("route-table-foo"), + Name: "route-table-foo", Description: utils.Ptr("description-foo"), SystemRoutes: utils.Ptr(true), DynamicRoutes: utils.Ptr(true), - Labels: utils.ConvertStringMapToInterfaceMap(testLabels), + Labels: testLabels, CreatedAt: utils.Ptr(time.Now()), UpdatedAt: utils.Ptr(time.Now()), } diff --git a/internal/cmd/network-area/update/update.go b/internal/cmd/network-area/update/update.go index 4ba577cf0..a4f9195c3 100644 --- a/internal/cmd/network-area/update/update.go +++ b/internal/cmd/network-area/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -54,14 +54,14 @@ type inputModel struct { Name *string OrganizationId *string // Deprecated: DnsNameServers is deprecated, because with iaas v2 the create endpoint for network area was separated, remove this after April 2026. - DnsNameServers *[]string + DnsNameServers []string // Deprecated: DefaultPrefixLength is deprecated, because with iaas v2 the create endpoint for network area was separated, remove this after April 2026. DefaultPrefixLength *int64 // Deprecated: MaxPrefixLength is deprecated, because with iaas v2 the create endpoint for network area was separated, remove this after April 2026. MaxPrefixLength *int64 // Deprecated: MinPrefixLength is deprecated, because with iaas v2 the create endpoint for network area was separated, remove this after April 2026. MinPrefixLength *int64 - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -170,11 +170,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu Name: flags.FlagToStringPointer(p, cmd, nameFlag), OrganizationId: flags.FlagToStringPointer(p, cmd, organizationIdFlag), AreaId: areaId, - DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, dnsNameServersFlag), + DnsNameServers: flags.FlagToStringSliceValue(p, cmd, dnsNameServersFlag), DefaultPrefixLength: flags.FlagToInt64Pointer(p, cmd, defaultPrefixLengthFlag), MaxPrefixLength: flags.FlagToInt64Pointer(p, cmd, maxPrefixLengthFlag), MinPrefixLength: flags.FlagToInt64Pointer(p, cmd, minPrefixLengthFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } p.DebugInputModel(model) @@ -204,18 +204,18 @@ func getConfiguredDeprecatedFlags(model *inputModel) []string { } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiPartialUpdateNetworkAreaRequest { - req := apiClient.PartialUpdateNetworkArea(ctx, *model.OrganizationId, model.AreaId) + req := apiClient.DefaultAPI.PartialUpdateNetworkArea(ctx, *model.OrganizationId, model.AreaId) payload := iaas.PartialUpdateNetworkAreaPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.PartialUpdateNetworkAreaPayload(payload) } func buildRequestNetworkAreaRegion(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateNetworkAreaRegionRequest { - req := apiClient.UpdateNetworkAreaRegion(ctx, *model.OrganizationId, model.AreaId, model.Region) + req := apiClient.DefaultAPI.UpdateNetworkAreaRegion(ctx, *model.OrganizationId, model.AreaId, model.Region) payload := iaas.UpdateNetworkAreaRegionPayload{ Ipv4: &iaas.UpdateRegionalAreaIPv4{ diff --git a/internal/cmd/network-area/update/update_test.go b/internal/cmd/network-area/update/update_test.go index 91fd5756f..b58777a7a 100644 --- a/internal/cmd/network-area/update/update_test.go +++ b/internal/cmd/network-area/update/update_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -27,7 +27,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var ( testOrgId = uuid.NewString() @@ -69,9 +69,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Name: utils.Ptr(testName), OrganizationId: utils.Ptr(testOrgId), AreaId: testAreaId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -80,7 +80,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiPartialUpdateNetworkAreaRequest)) iaas.ApiPartialUpdateNetworkAreaRequest { - request := testClient.PartialUpdateNetworkArea(testCtx, testOrgId, testAreaId) + request := testClient.DefaultAPI.PartialUpdateNetworkArea(testCtx, testOrgId, testAreaId) request = request.PartialUpdateNetworkAreaPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -91,9 +91,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiPartialUpdateNetworkAreaReques func fixturePayload(mods ...func(payload *iaas.PartialUpdateNetworkAreaPayload)) iaas.PartialUpdateNetworkAreaPayload { payload := iaas.PartialUpdateNetworkAreaPayload{ Name: utils.Ptr(testName), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(&payload) @@ -102,7 +102,7 @@ func fixturePayload(mods ...func(payload *iaas.PartialUpdateNetworkAreaPayload)) } func fixtureRequestRegionalArea(mods ...func(request *iaas.ApiUpdateNetworkAreaRegionRequest)) iaas.ApiUpdateNetworkAreaRegionRequest { - request := testClient.UpdateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) + request := testClient.DefaultAPI.UpdateNetworkAreaRegion(testCtx, testOrgId, testAreaId, testRegion) request = request.UpdateNetworkAreaRegionPayload(fixturePayloadRegionalArea()) for _, mod := range mods { mod(&request) @@ -113,7 +113,7 @@ func fixtureRequestRegionalArea(mods ...func(request *iaas.ApiUpdateNetworkAreaR func fixturePayloadRegionalArea(mods ...func(payload *iaas.UpdateNetworkAreaRegionPayload)) iaas.UpdateNetworkAreaRegionPayload { payload := iaas.UpdateNetworkAreaRegionPayload{ Ipv4: &iaas.UpdateRegionalAreaIPv4{ - DefaultNameservers: utils.Ptr(testDnsNameservers), + DefaultNameservers: testDnsNameservers, DefaultPrefixLen: utils.Ptr(testDefaultPrefixLength), MaxPrefixLen: utils.Ptr(testMaxPrefixLength), MinPrefixLen: utils.Ptr(testMinPrefixLength), @@ -152,7 +152,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.DnsNameServers = utils.Ptr(testDnsNameservers) + model.DnsNameServers = testDnsNameservers model.DefaultPrefixLength = utils.Ptr(testDefaultPrefixLength) model.MaxPrefixLength = utils.Ptr(testMaxPrefixLength) model.MinPrefixLength = utils.Ptr(testMinPrefixLength) @@ -301,7 +301,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -319,7 +319,7 @@ func TestBuildRequestNetworkAreaRegion(t *testing.T) { { description: "base", model: fixtureInputModel(func(model *inputModel) { - model.DnsNameServers = utils.Ptr(testDnsNameservers) + model.DnsNameServers = testDnsNameservers model.DefaultPrefixLength = utils.Ptr(testDefaultPrefixLength) model.MaxPrefixLength = utils.Ptr(testMaxPrefixLength) model.MinPrefixLength = utils.Ptr(testMinPrefixLength) @@ -334,7 +334,7 @@ func TestBuildRequestNetworkAreaRegion(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -398,9 +398,9 @@ func TestGetConfiguredDeprecatedFlags(t *testing.T) { }, Name: utils.Ptr(testName), OrganizationId: utils.Ptr(testOrgId), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, DnsNameServers: nil, DefaultPrefixLength: nil, MaxPrefixLength: nil, @@ -418,10 +418,10 @@ func TestGetConfiguredDeprecatedFlags(t *testing.T) { }, Name: utils.Ptr(testName), OrganizationId: utils.Ptr(testOrgId), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), - DnsNameServers: utils.Ptr(testDnsNameservers), + }, + DnsNameServers: testDnsNameservers, DefaultPrefixLength: utils.Ptr(testDefaultPrefixLength), MaxPrefixLength: utils.Ptr(testMaxPrefixLength), MinPrefixLength: utils.Ptr(testMinPrefixLength), @@ -462,9 +462,9 @@ func TestHasDeprecatedFlagsSet(t *testing.T) { }, Name: utils.Ptr(testName), OrganizationId: utils.Ptr(testOrgId), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, DnsNameServers: nil, DefaultPrefixLength: nil, MaxPrefixLength: nil, @@ -482,10 +482,10 @@ func TestHasDeprecatedFlagsSet(t *testing.T) { }, Name: utils.Ptr(testName), OrganizationId: utils.Ptr(testOrgId), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), - DnsNameServers: utils.Ptr(testDnsNameservers), + }, + DnsNameServers: testDnsNameservers, DefaultPrefixLength: utils.Ptr(testDefaultPrefixLength), MaxPrefixLength: utils.Ptr(testMaxPrefixLength), MinPrefixLength: utils.Ptr(testMinPrefixLength), diff --git a/internal/cmd/network-interface/create/create.go b/internal/cmd/network-interface/create/create.go index 5a1f5b8c3..2ca9ce7b7 100644 --- a/internal/cmd/network-interface/create/create.go +++ b/internal/cmd/network-interface/create/create.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -41,13 +41,13 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel NetworkId string - AllowedAddresses *[]iaas.AllowedAddressesInner + AllowedAddresses []iaas.AllowedAddressesInner Ipv4 *string Ipv6 *string - Labels *map[string]string + Labels map[string]any Name *string // <= 63 characters + regex ^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$ NicSecurity *bool - SecurityGroups *[]string // = 36 characters + regex ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ + SecurityGroups []string // = 36 characters + regex ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -155,11 +155,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } // check security groups size and regex - securityGroups := flags.FlagToStringSlicePointer(p, cmd, securityGroupsFlag) - if securityGroups != nil && len(*securityGroups) > 0 { + securityGroups := flags.FlagToStringSliceValue(p, cmd, securityGroupsFlag) + if len(securityGroups) > 0 { securityGroupsRegex := regexp.MustCompile(securityGroupsRegex) // iterate over them - for _, value := range *securityGroups { + for _, value := range securityGroups { if len(value) != securityGroupLength { return nil, &errors.FlagValidationError{ Flag: securityGroupsFlag, @@ -180,14 +180,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag), Ipv4: flags.FlagToStringPointer(p, cmd, ipv4Flag), Ipv6: flags.FlagToStringPointer(p, cmd, ipv6Flag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), Name: name, NicSecurity: flags.FlagToBoolPointer(p, cmd, nicSecurityFlag), SecurityGroups: securityGroups, } if allowedAddresses != nil { - model.AllowedAddresses = utils.Ptr(allowedAddressesInner) + model.AllowedAddresses = allowedAddressesInner } p.DebugInputModel(model) @@ -195,13 +195,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNicRequest { - req := apiClient.CreateNic(ctx, model.ProjectId, model.Region, model.NetworkId) + req := apiClient.DefaultAPI.CreateNic(ctx, model.ProjectId, model.Region, model.NetworkId) payload := iaas.CreateNicPayload{ AllowedAddresses: model.AllowedAddresses, Ipv4: model.Ipv4, Ipv6: model.Ipv6, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, Name: model.Name, NicSecurity: model.NicSecurity, SecurityGroups: model.SecurityGroups, diff --git a/internal/cmd/network-interface/create/create_test.go b/internal/cmd/network-interface/create/create_test.go index 8209c8f21..780317033 100644 --- a/internal/cmd/network-interface/create/create_test.go +++ b/internal/cmd/network-interface/create/create_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -23,7 +23,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() @@ -62,15 +62,15 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Verbosity: globalflags.VerbosityDefault, }, NetworkId: testNetworkId, - AllowedAddresses: utils.Ptr(allowedAddresses), + AllowedAddresses: allowedAddresses, Ipv4: utils.Ptr("1.2.3.4"), Ipv6: utils.Ptr("2001:0db8:85a3:08d3::0370:7344"), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, Name: utils.Ptr("testNic"), NicSecurity: utils.Ptr(true), - SecurityGroups: utils.Ptr([]string{testSecurityGroup}), + SecurityGroups: []string{testSecurityGroup}, } for _, mod := range mods { mod(model) @@ -79,7 +79,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateNicRequest)) iaas.ApiCreateNicRequest { - request := testClient.CreateNic(testCtx, testProjectId, testRegion, testNetworkId) + request := testClient.DefaultAPI.CreateNic(testCtx, testProjectId, testRegion, testNetworkId) request = request.CreateNicPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -94,15 +94,15 @@ func fixturePayload(mods ...func(payload *iaas.CreateNicPayload)) iaas.CreateNic iaas.StringAsAllowedAddressesInner(utils.Ptr("9.9.9.9")), } payload := iaas.CreateNicPayload{ - AllowedAddresses: utils.Ptr(allowedAddresses), + AllowedAddresses: allowedAddresses, Ipv4: utils.Ptr("1.2.3.4"), Ipv6: utils.Ptr("2001:0db8:85a3:08d3::0370:7344"), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, Name: utils.Ptr("testNic"), NicSecurity: utils.Ptr(true), - SecurityGroups: utils.Ptr([]string{testSecurityGroup}), + SecurityGroups: []string{testSecurityGroup}, } for _, mod := range mods { mod(&payload) @@ -223,7 +223,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-interface/delete/delete.go b/internal/cmd/network-interface/delete/delete.go index af8a49eee..4cdca444c 100644 --- a/internal/cmd/network-interface/delete/delete.go +++ b/internal/cmd/network-interface/delete/delete.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -99,6 +99,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNicRequest { - req := apiClient.DeleteNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId) + req := apiClient.DefaultAPI.DeleteNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId) return req } diff --git a/internal/cmd/network-interface/delete/delete_test.go b/internal/cmd/network-interface/delete/delete_test.go index 0ffbc63c3..277de1c13 100644 --- a/internal/cmd/network-interface/delete/delete_test.go +++ b/internal/cmd/network-interface/delete/delete_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteNicRequest)) iaas.ApiDeleteNicRequest { - request := testClient.DeleteNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId) + request := testClient.DefaultAPI.DeleteNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId) for _, mod := range mods { mod(&request) } @@ -198,7 +198,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-interface/describe/describe.go b/internal/cmd/network-interface/describe/describe.go index 49e93d690..27c1f1ff9 100644 --- a/internal/cmd/network-interface/describe/describe.go +++ b/internal/cmd/network-interface/describe/describe.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -105,7 +105,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNicRequest { - req := apiClient.GetNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId) + req := apiClient.DefaultAPI.GetNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId) return req } @@ -134,17 +134,17 @@ func outputResult(p *print.Printer, outputFormat string, nic *iaas.NIC) error { table.AddRow("MAC", utils.PtrString(nic.Mac)) table.AddSeparator() table.AddRow("NIC SECURITY", utils.PtrString(nic.NicSecurity)) - if nic.AllowedAddresses != nil && len(*nic.AllowedAddresses) > 0 { + if len(nic.AllowedAddresses) > 0 { var allowedAddresses []string - for _, value := range *nic.AllowedAddresses { + for _, value := range nic.AllowedAddresses { allowedAddresses = append(allowedAddresses, *value.String) } table.AddSeparator() table.AddRow("ALLOWED ADDRESSES", strings.Join(allowedAddresses, "\n")) } - if nic.Labels != nil && len(*nic.Labels) > 0 { + if len(nic.Labels) > 0 { var labels []string - for key, value := range *nic.Labels { + for key, value := range nic.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddSeparator() @@ -154,9 +154,9 @@ func outputResult(p *print.Printer, outputFormat string, nic *iaas.NIC) error { table.AddRow("STATUS", utils.PtrString(nic.Status)) table.AddSeparator() table.AddRow("TYPE", utils.PtrString(nic.Type)) - if nic.SecurityGroups != nil && len(*nic.SecurityGroups) > 0 { + if len(nic.SecurityGroups) > 0 { table.AddSeparator() - table.AddRow("SECURITY GROUPS", strings.Join(*nic.SecurityGroups, "\n")) + table.AddRow("SECURITY GROUPS", strings.Join(nic.SecurityGroups, "\n")) } err := table.Display(p) diff --git a/internal/cmd/network-interface/describe/describe_test.go b/internal/cmd/network-interface/describe/describe_test.go index 2e587fe17..86570f780 100644 --- a/internal/cmd/network-interface/describe/describe_test.go +++ b/internal/cmd/network-interface/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetNicRequest)) iaas.ApiGetNicRequest { - request := testClient.GetNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId) + request := testClient.DefaultAPI.GetNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId) for _, mod := range mods { mod(&request) } @@ -198,7 +198,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-interface/list/list.go b/internal/cmd/network-interface/list/list.go index 33941d1de..fc5a20ae3 100644 --- a/internal/cmd/network-interface/list/list.go +++ b/internal/cmd/network-interface/list/list.go @@ -10,7 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -94,7 +94,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Truncate output - items := utils.GetSliceFromPointer(resp.Items) + items := resp.Items if model.Limit != nil && len(items) > int(*model.Limit) { items = items[:*model.Limit] } @@ -110,7 +110,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("list network interfaces: %w", err) } - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, *model.NetworkId) + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.NetworkId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) networkLabel = *model.NetworkId @@ -119,7 +119,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Truncate output - items := utils.GetSliceFromPointer(resp.Items) + items := resp.Items if model.Limit != nil && len(items) > int(*model.Limit) { items = items[:*model.Limit] } @@ -163,7 +163,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListProjectNICsRequest { - req := apiClient.ListProjectNICs(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListProjectNICs(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -172,7 +172,7 @@ func buildProjectRequest(ctx context.Context, model *inputModel, apiClient *iaas } func buildNetworkRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNicsRequest { - req := apiClient.ListNics(ctx, model.ProjectId, model.Region, *model.NetworkId) + req := apiClient.DefaultAPI.ListNics(ctx, model.ProjectId, model.Region, *model.NetworkId) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } diff --git a/internal/cmd/network-interface/list/list_test.go b/internal/cmd/network-interface/list/list_test.go index 30c9395d4..3ef5c3397 100644 --- a/internal/cmd/network-interface/list/list_test.go +++ b/internal/cmd/network-interface/list/list_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,7 +23,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() var testLabelSelector = "label" @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureProjectRequest(mods ...func(request *iaas.ApiListProjectNICsRequest)) iaas.ApiListProjectNICsRequest { - request := testClient.ListProjectNICs(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListProjectNICs(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -70,7 +70,7 @@ func fixtureProjectRequest(mods ...func(request *iaas.ApiListProjectNICsRequest) } func fixtureNetworkRequest(mods ...func(request *iaas.ApiListNicsRequest)) iaas.ApiListNicsRequest { - request := testClient.ListNics(testCtx, testProjectId, testRegion, testNetworkId) + request := testClient.DefaultAPI.ListNics(testCtx, testProjectId, testRegion, testNetworkId) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -175,7 +175,7 @@ func TestBuildProjectRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -203,7 +203,7 @@ func TestBuildNetworkRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network-interface/update/update.go b/internal/cmd/network-interface/update/update.go index e1b9b6e1e..6673cada5 100644 --- a/internal/cmd/network-interface/update/update.go +++ b/internal/cmd/network-interface/update/update.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -41,11 +41,11 @@ type inputModel struct { *globalflags.GlobalFlagModel NicId string NetworkId string - AllowedAddresses *[]iaas.AllowedAddressesInner - Labels *map[string]string + AllowedAddresses []iaas.AllowedAddressesInner + Labels map[string]any Name *string // <= 63 characters + regex ^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$ NicSecurity *bool - SecurityGroups *[]string // = 36 characters + regex ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ + SecurityGroups []string // = 36 characters + regex ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -148,11 +148,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } // check security groups size and regex - securityGroups := flags.FlagToStringSlicePointer(p, cmd, securityGroupsFlag) - if securityGroups != nil && len(*securityGroups) > 0 { + securityGroups := flags.FlagToStringSliceValue(p, cmd, securityGroupsFlag) + if len(securityGroups) > 0 { securityGroupsRegex := regexp.MustCompile(securityGroupsRegex) // iterate over them - for _, value := range *securityGroups { + for _, value := range securityGroups { if len(value) != securityGroupLength { return nil, &errors.FlagValidationError{ Flag: securityGroupsFlag, @@ -172,14 +172,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu GlobalFlagModel: globalFlags, NicId: nicId, NetworkId: flags.FlagToStringValue(p, cmd, networkIdFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), Name: name, NicSecurity: flags.FlagToBoolPointer(p, cmd, nicSecurityFlag), SecurityGroups: securityGroups, } if allowedAddresses != nil { - model.AllowedAddresses = utils.Ptr(allowedAddressesInner) + model.AllowedAddresses = allowedAddressesInner } p.DebugInputModel(model) @@ -187,11 +187,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateNicRequest { - req := apiClient.UpdateNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId) + req := apiClient.DefaultAPI.UpdateNic(ctx, model.ProjectId, model.Region, model.NetworkId, model.NicId) payload := iaas.UpdateNicPayload{ AllowedAddresses: model.AllowedAddresses, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, Name: model.Name, NicSecurity: model.NicSecurity, SecurityGroups: model.SecurityGroups, diff --git a/internal/cmd/network-interface/update/update_test.go b/internal/cmd/network-interface/update/update_test.go index 86be147b0..474d52f8a 100644 --- a/internal/cmd/network-interface/update/update_test.go +++ b/internal/cmd/network-interface/update/update_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() var testNicId = uuid.NewString() @@ -68,13 +68,13 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, }, NetworkId: testNetworkId, - AllowedAddresses: utils.Ptr(allowedAddresses), - Labels: utils.Ptr(map[string]string{ + AllowedAddresses: allowedAddresses, + Labels: map[string]any{ "key": "value", - }), + }, Name: utils.Ptr("testNic"), NicSecurity: utils.Ptr(true), - SecurityGroups: utils.Ptr([]string{testSecurityGroup}), + SecurityGroups: []string{testSecurityGroup}, NicId: testNicId, } for _, mod := range mods { @@ -84,7 +84,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateNicRequest)) iaas.ApiUpdateNicRequest { - request := testClient.UpdateNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId) + request := testClient.DefaultAPI.UpdateNic(testCtx, testProjectId, testRegion, testNetworkId, testNicId) request = request.UpdateNicPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -99,13 +99,13 @@ func fixturePayload(mods ...func(payload *iaas.UpdateNicPayload)) iaas.UpdateNic iaas.StringAsAllowedAddressesInner(utils.Ptr("9.9.9.9")), } payload := iaas.UpdateNicPayload{ - AllowedAddresses: utils.Ptr(allowedAddresses), - Labels: utils.Ptr(map[string]interface{}{ + AllowedAddresses: allowedAddresses, + Labels: map[string]any{ "key": "value", - }), + }, Name: utils.Ptr("testNic"), NicSecurity: utils.Ptr(true), - SecurityGroups: utils.Ptr([]string{testSecurityGroup}), + SecurityGroups: []string{testSecurityGroup}, } for _, mod := range mods { mod(&payload) @@ -288,7 +288,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network/create/create.go b/internal/cmd/network/create/create.go index 46e9e0e57..31f669d08 100644 --- a/internal/cmd/network/create/create.go +++ b/internal/cmd/network/create/create.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -42,12 +42,12 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Name *string - IPv4DnsNameServers *[]string + Name string + IPv4DnsNameServers []string IPv4PrefixLength *int64 IPv4Prefix *string IPv4Gateway *string - IPv6DnsNameServers *[]string + IPv6DnsNameServers []string IPv6PrefixLength *int64 IPv6Prefix *string IPv6Gateway *string @@ -55,7 +55,7 @@ type inputModel struct { NoIPv4Gateway bool NoIPv6Gateway bool RoutingTableID *string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -128,15 +128,15 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("create network : %w", err) } - if resp == nil || resp.Id == nil { + if resp == nil { return fmt.Errorf("create network : empty response") } - networkId := *resp.Id + networkId := resp.Id // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Creating network", func() error { - _, err = wait.CreateNetworkWaitHandler(ctx, apiClient, model.ProjectId, model.Region, networkId).WaitWithContext(ctx) + _, err = wait.CreateNetworkWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, networkId).WaitWithContext(ctx) return err }) if err != nil { @@ -189,13 +189,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, - Name: flags.FlagToStringPointer(p, cmd, nameFlag), - IPv4DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, ipv4DnsNameServersFlag), + Name: flags.FlagToStringValue(p, cmd, nameFlag), + IPv4DnsNameServers: flags.FlagToStringSliceValue(p, cmd, ipv4DnsNameServersFlag), IPv4PrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv4PrefixLengthFlag), IPv4Prefix: flags.FlagToStringPointer(p, cmd, ipv4PrefixFlag), IPv4Gateway: flags.FlagToStringPointer(p, cmd, ipv4GatewayFlag), - IPv6DnsNameServers: flags.FlagToStringSlicePointer(p, cmd, ipv6DnsNameServersFlag), + IPv6DnsNameServers: flags.FlagToStringSliceValue(p, cmd, ipv6DnsNameServersFlag), IPv6PrefixLength: flags.FlagToInt64Pointer(p, cmd, ipv6PrefixLengthFlag), IPv6Prefix: flags.FlagToStringPointer(p, cmd, ipv6PrefixFlag), IPv6Gateway: flags.FlagToStringPointer(p, cmd, ipv6GatewayFlag), @@ -203,11 +203,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, NoIPv4Gateway: flags.FlagToBoolValue(p, cmd, noIpv4GatewayFlag), NoIPv6Gateway: flags.FlagToBoolValue(p, cmd, noIpv6GatewayFlag), RoutingTableID: flags.FlagToStringPointer(p, cmd, routingTableIdFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } // IPv4 nameserver can not be set alone. IPv4 Prefix || IPv4 Prefix length must be set as well - isIPv4NameserverSet := model.IPv4DnsNameServers != nil && len(*model.IPv4DnsNameServers) > 0 + isIPv4NameserverSet := model.IPv4DnsNameServers != nil && len(model.IPv4DnsNameServers) > 0 isIPv4PrefixOrPrefixLengthSet := model.IPv4Prefix != nil || model.IPv4PrefixLength != nil if isIPv4NameserverSet && !isIPv4PrefixOrPrefixLengthSet { return nil, &cliErr.OneOfFlagsIsMissing{ @@ -225,7 +225,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } // IPv6 nameserver can not be set alone. IPv6 Prefix || IPv6 Prefix length must be set as well - isIPv6NameserverSet := model.IPv6DnsNameServers != nil && len(*model.IPv6DnsNameServers) > 0 + isIPv6NameserverSet := model.IPv6DnsNameServers != nil && len(model.IPv6DnsNameServers) > 0 isIPv6PrefixOrPrefixLengthSet := model.IPv6Prefix != nil || model.IPv6PrefixLength != nil if isIPv6NameserverSet && !isIPv6PrefixOrPrefixLengthSet { return nil, &cliErr.OneOfFlagsIsMissing{ @@ -247,27 +247,27 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateNetworkRequest { - req := apiClient.CreateNetwork(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreateNetwork(ctx, model.ProjectId, model.Region) var ipv4Network *iaas.CreateNetworkIPv4 var ipv6Network *iaas.CreateNetworkIPv6 if model.IPv6Prefix != nil { ipv6Network = &iaas.CreateNetworkIPv6{ CreateNetworkIPv6WithPrefix: &iaas.CreateNetworkIPv6WithPrefix{ - Prefix: model.IPv6Prefix, + Prefix: *model.IPv6Prefix, Nameservers: model.IPv6DnsNameServers, }, } if model.NoIPv6Gateway { - ipv6Network.CreateNetworkIPv6WithPrefix.Gateway = iaas.NewNullableString(nil) + ipv6Network.CreateNetworkIPv6WithPrefix.Gateway = *iaas.NewNullableString(nil) } else if model.IPv6Gateway != nil { - ipv6Network.CreateNetworkIPv6WithPrefix.Gateway = iaas.NewNullableString(model.IPv6Gateway) + ipv6Network.CreateNetworkIPv6WithPrefix.Gateway = *iaas.NewNullableString(model.IPv6Gateway) } } else if model.IPv6PrefixLength != nil { ipv6Network = &iaas.CreateNetworkIPv6{ CreateNetworkIPv6WithPrefixLength: &iaas.CreateNetworkIPv6WithPrefixLength{ - PrefixLength: model.IPv6PrefixLength, + PrefixLength: *model.IPv6PrefixLength, Nameservers: model.IPv6DnsNameServers, }, } @@ -276,20 +276,20 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli if model.IPv4Prefix != nil { ipv4Network = &iaas.CreateNetworkIPv4{ CreateNetworkIPv4WithPrefix: &iaas.CreateNetworkIPv4WithPrefix{ - Prefix: model.IPv4Prefix, + Prefix: *model.IPv4Prefix, Nameservers: model.IPv4DnsNameServers, }, } if model.NoIPv4Gateway { - ipv4Network.CreateNetworkIPv4WithPrefix.Gateway = iaas.NewNullableString(nil) + ipv4Network.CreateNetworkIPv4WithPrefix.Gateway = *iaas.NewNullableString(nil) } else if model.IPv4Gateway != nil { - ipv4Network.CreateNetworkIPv4WithPrefix.Gateway = iaas.NewNullableString(model.IPv4Gateway) + ipv4Network.CreateNetworkIPv4WithPrefix.Gateway = *iaas.NewNullableString(model.IPv4Gateway) } } else if model.IPv4PrefixLength != nil { ipv4Network = &iaas.CreateNetworkIPv4{ CreateNetworkIPv4WithPrefixLength: &iaas.CreateNetworkIPv4WithPrefixLength{ - PrefixLength: model.IPv4PrefixLength, + PrefixLength: *model.IPv4PrefixLength, Nameservers: model.IPv4DnsNameServers, }, } @@ -297,7 +297,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli payload := iaas.CreateNetworkPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, Routed: utils.Ptr(!model.NonRouted), Ipv4: ipv4Network, Ipv6: ipv6Network, @@ -316,7 +316,7 @@ func outputResult(p *print.Printer, outputFormat string, async bool, projectLabe if async { operationState = "Triggered creation of" } - p.Outputf("%s network for project %q.\nNetwork ID: %s\n", operationState, projectLabel, utils.PtrString(network.Id)) + p.Outputf("%s network for project %q.\nNetwork ID: %s\n", operationState, projectLabel, network.Id) return nil }) } diff --git a/internal/cmd/network/create/create_test.go b/internal/cmd/network/create/create_test.go index c7609ea57..37aec4fb0 100644 --- a/internal/cmd/network/create/create_test.go +++ b/internal/cmd/network/create/create_test.go @@ -14,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -39,7 +39,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testRoutingTableId = uuid.NewString() ) @@ -97,11 +97,11 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: utils.Ptr(testNetworkName), + Name: testNetworkName, NonRouted: testNonRouted, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, RoutingTableID: utils.Ptr(testRoutingTableId), } for _, mod := range mods { @@ -113,11 +113,11 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { func fixtureInputModelWithPrefix(mods ...func(model *inputModel)) *inputModel { model := fixtureInputModel() - model.IPv4DnsNameServers = utils.Ptr(testIPv4NameServers) + model.IPv4DnsNameServers = testIPv4NameServers model.IPv4Prefix = utils.Ptr(testIPv4Prefix) model.IPv4Gateway = utils.Ptr(testIPv4Gateway) - model.IPv6DnsNameServers = utils.Ptr(testIPv6NameServers) + model.IPv6DnsNameServers = testIPv6NameServers model.IPv6Prefix = utils.Ptr(testIPv6Prefix) model.IPv6Gateway = utils.Ptr(testIPv6Gateway) @@ -130,10 +130,10 @@ func fixtureInputModelWithPrefix(mods ...func(model *inputModel)) *inputModel { func fixtureInputModelWithPrefixLength(mods ...func(model *inputModel)) *inputModel { model := fixtureInputModel() - model.IPv4DnsNameServers = utils.Ptr(testIPv4NameServers) + model.IPv4DnsNameServers = testIPv4NameServers model.IPv4PrefixLength = utils.Ptr(testIPv4PrefixLength) - model.IPv6DnsNameServers = utils.Ptr(testIPv6NameServers) + model.IPv6DnsNameServers = testIPv6NameServers model.IPv6PrefixLength = utils.Ptr(testIPv6PrefixLength) for _, mod := range mods { @@ -143,7 +143,7 @@ func fixtureInputModelWithPrefixLength(mods ...func(model *inputModel)) *inputMo } func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkRequest)) iaas.ApiCreateNetworkRequest { - request := testClient.CreateNetwork(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateNetwork(testCtx, testProjectId, testRegion) request = request.CreateNetworkPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -152,9 +152,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateNetworkRequest)) iaas.Ap } func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateNetworkRequest)) iaas.ApiCreateNetworkRequest { - request := testClient.CreateNetwork(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateNetwork(testCtx, testProjectId, testRegion) request = request.CreateNetworkPayload(iaas.CreateNetworkPayload{ - Name: utils.Ptr(testNetworkName), + Name: testNetworkName, Routed: utils.Ptr(true), }) for _, mod := range mods { @@ -165,11 +165,11 @@ func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateNetworkRequest)) func fixturePayload(mods ...func(payload *iaas.CreateNetworkPayload)) iaas.CreateNetworkPayload { payload := iaas.CreateNetworkPayload{ - Name: utils.Ptr("example-network-name"), + Name: "example-network-name", Routed: utils.Ptr(true), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, RoutingTableId: utils.Ptr(testRoutingTableId), } for _, mod := range mods { @@ -182,16 +182,16 @@ func fixturePayloadWithPrefix(mods ...func(payload *iaas.CreateNetworkPayload)) payload := fixturePayload() payload.Ipv4 = &iaas.CreateNetworkIPv4{ CreateNetworkIPv4WithPrefix: &iaas.CreateNetworkIPv4WithPrefix{ - Gateway: iaas.NewNullableString(utils.Ptr(testIPv4Gateway)), - Nameservers: utils.Ptr(testIPv4NameServers), - Prefix: utils.Ptr(testIPv4Prefix), + Gateway: *iaas.NewNullableString(utils.Ptr(testIPv4Gateway)), + Nameservers: testIPv4NameServers, + Prefix: testIPv4Prefix, }, } payload.Ipv6 = &iaas.CreateNetworkIPv6{ CreateNetworkIPv6WithPrefix: &iaas.CreateNetworkIPv6WithPrefix{ - Nameservers: utils.Ptr(testIPv6NameServers), - Prefix: utils.Ptr(testIPv6Prefix), - Gateway: iaas.NewNullableString(utils.Ptr(testIPv6Gateway)), + Nameservers: testIPv6NameServers, + Prefix: testIPv6Prefix, + Gateway: *iaas.NewNullableString(utils.Ptr(testIPv6Gateway)), }, } for _, mod := range mods { @@ -204,14 +204,14 @@ func fixturePayloadWithPrefixLength(mods ...func(payload *iaas.CreateNetworkPayl payload := fixturePayload() payload.Ipv4 = &iaas.CreateNetworkIPv4{ CreateNetworkIPv4WithPrefixLength: &iaas.CreateNetworkIPv4WithPrefixLength{ - PrefixLength: utils.Ptr(testIPv4PrefixLength), - Nameservers: utils.Ptr(testIPv4NameServers), + PrefixLength: testIPv4PrefixLength, + Nameservers: testIPv4NameServers, }, } payload.Ipv6 = &iaas.CreateNetworkIPv6{ CreateNetworkIPv6WithPrefixLength: &iaas.CreateNetworkIPv6WithPrefixLength{ - PrefixLength: utils.Ptr(testIPv6PrefixLength), - Nameservers: utils.Ptr(testIPv6NameServers), + PrefixLength: testIPv6PrefixLength, + Nameservers: testIPv6NameServers, }, } for _, mod := range mods { @@ -249,7 +249,7 @@ func TestParseInput(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: utils.Ptr(testNetworkName), + Name: testNetworkName, }, }, { @@ -517,7 +517,7 @@ func TestBuildRequest(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: utils.Ptr(testNetworkName), + Name: testNetworkName, }, expectedRequest: fixtureRequiredRequest(), }, @@ -525,14 +525,14 @@ func TestBuildRequest(t *testing.T) { description: "use prefix length", model: fixtureInputModelWithPrefixLength(), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) { - *request = (*request).CreateNetworkPayload(fixturePayloadWithPrefixLength()) + *request = request.CreateNetworkPayload(fixturePayloadWithPrefixLength()) }), }, { description: "use prefix", model: fixtureInputModelWithPrefix(), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) { - *request = (*request).CreateNetworkPayload(fixturePayloadWithPrefix()) + *request = request.CreateNetworkPayload(fixturePayloadWithPrefix()) }), }, { @@ -543,11 +543,11 @@ func TestBuildRequest(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: utils.Ptr(testNetworkName), + Name: testNetworkName, NonRouted: true, }, - expectedRequest: testClient.CreateNetwork(testCtx, testProjectId, testRegion).CreateNetworkPayload(iaas.CreateNetworkPayload{ - Name: utils.Ptr(testNetworkName), + expectedRequest: testClient.DefaultAPI.CreateNetwork(testCtx, testProjectId, testRegion).CreateNetworkPayload(iaas.CreateNetworkPayload{ + Name: testNetworkName, Routed: utils.Ptr(false), }), }, @@ -559,11 +559,11 @@ func TestBuildRequest(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - Name: utils.Ptr(testNetworkName), + Name: testNetworkName, RoutingTableID: utils.Ptr(testRoutingTableId), }, - expectedRequest: testClient.CreateNetwork(testCtx, testProjectId, testRegion).CreateNetworkPayload(iaas.CreateNetworkPayload{ - Name: utils.Ptr(testNetworkName), + expectedRequest: testClient.DefaultAPI.CreateNetwork(testCtx, testProjectId, testRegion).CreateNetworkPayload(iaas.CreateNetworkPayload{ + Name: testNetworkName, RoutingTableId: utils.Ptr(testRoutingTableId), Routed: utils.Ptr(true), }), @@ -576,15 +576,15 @@ func TestBuildRequest(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - IPv4DnsNameServers: utils.Ptr([]string{"1.1.1.1"}), + IPv4DnsNameServers: []string{"1.1.1.1"}, IPv4PrefixLength: utils.Ptr(int64(25)), }, expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) { - *request = (*request).CreateNetworkPayload(iaas.CreateNetworkPayload{ + *request = request.CreateNetworkPayload(iaas.CreateNetworkPayload{ Ipv4: &iaas.CreateNetworkIPv4{ CreateNetworkIPv4WithPrefixLength: &iaas.CreateNetworkIPv4WithPrefixLength{ - Nameservers: utils.Ptr([]string{"1.1.1.1"}), - PrefixLength: utils.Ptr(int64(25)), + Nameservers: []string{"1.1.1.1"}, + PrefixLength: int64(25), }, }, Routed: utils.Ptr(true), @@ -598,10 +598,10 @@ func TestBuildRequest(t *testing.T) { model.NoIPv6Gateway = true }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateNetworkRequest) { - *request = (*request).CreateNetworkPayload( + *request = request.CreateNetworkPayload( fixturePayloadWithPrefix(func(payload *iaas.CreateNetworkPayload) { - payload.Ipv4.CreateNetworkIPv4WithPrefix.Gateway = iaas.NewNullableString(nil) - payload.Ipv6.CreateNetworkIPv6WithPrefix.Gateway = iaas.NewNullableString(nil) + payload.Ipv4.CreateNetworkIPv4WithPrefix.Gateway = *iaas.NewNullableString(nil) + payload.Ipv6.CreateNetworkIPv6WithPrefix.Gateway = *iaas.NewNullableString(nil) }), ) }), @@ -614,16 +614,16 @@ func TestBuildRequest(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - IPv6DnsNameServers: utils.Ptr([]string{"2001:4860:4860::8888"}), + IPv6DnsNameServers: []string{"2001:4860:4860::8888"}, IPv6Prefix: utils.Ptr("2001:4860:4860::8888"), IPv6Gateway: utils.Ptr("2001:4860:4860::8888"), }, - expectedRequest: testClient.CreateNetwork(testCtx, testProjectId, testRegion).CreateNetworkPayload(iaas.CreateNetworkPayload{ + expectedRequest: testClient.DefaultAPI.CreateNetwork(testCtx, testProjectId, testRegion).CreateNetworkPayload(iaas.CreateNetworkPayload{ Ipv6: &iaas.CreateNetworkIPv6{ CreateNetworkIPv6WithPrefix: &iaas.CreateNetworkIPv6WithPrefix{ - Nameservers: utils.Ptr([]string{"2001:4860:4860::8888"}), - Prefix: utils.Ptr("2001:4860:4860::8888"), - Gateway: iaas.NewNullableString(utils.Ptr("2001:4860:4860::8888")), + Nameservers: []string{"2001:4860:4860::8888"}, + Prefix: "2001:4860:4860::8888", + Gateway: *iaas.NewNullableString(utils.Ptr("2001:4860:4860::8888")), }, }, Routed: utils.Ptr(true), @@ -636,7 +636,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(tt.expectedRequest, request, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/network/delete/delete.go b/internal/cmd/network/delete/delete.go index 3b3cc2177..25d05275d 100644 --- a/internal/cmd/network/delete/delete.go +++ b/internal/cmd/network/delete/delete.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -59,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.NetworkId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) networkLabel = model.NetworkId @@ -83,7 +83,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Deleting network", func() error { - _, err = wait.DeleteNetworkWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId).WaitWithContext(ctx) + _, err = wait.DeleteNetworkWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.NetworkId).WaitWithContext(ctx) return err }) if err != nil { @@ -120,5 +120,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteNetworkRequest { - return apiClient.DeleteNetwork(ctx, model.ProjectId, model.Region, model.NetworkId) + return apiClient.DefaultAPI.DeleteNetwork(ctx, model.ProjectId, model.Region, model.NetworkId) } diff --git a/internal/cmd/network/delete/delete_test.go b/internal/cmd/network/delete/delete_test.go index 76627b697..666fab6a2 100644 --- a/internal/cmd/network/delete/delete_test.go +++ b/internal/cmd/network/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testNetworkId = uuid.NewString() var testProjectId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteNetworkRequest)) iaas.ApiDeleteNetworkRequest { - request := testClient.DeleteNetwork(testCtx, testProjectId, testRegion, testNetworkId) + request := testClient.DefaultAPI.DeleteNetwork(testCtx, testProjectId, testRegion, testNetworkId) for _, mod := range mods { mod(&request) } @@ -165,7 +165,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network/describe/describe.go b/internal/cmd/network/describe/describe.go index 4f2a20319..f76d18017 100644 --- a/internal/cmd/network/describe/describe.go +++ b/internal/cmd/network/describe/describe.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -90,7 +90,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetNetworkRequest { - return apiClient.GetNetwork(ctx, model.ProjectId, model.Region, model.NetworkId) + return apiClient.DefaultAPI.GetNetwork(ctx, model.ProjectId, model.Region, model.NetworkId) } func outputResult(p *print.Printer, outputFormat string, network *iaas.Network) error { @@ -103,15 +103,15 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network) var publicIp, ipv4Gateway *string if ipv4 := network.Ipv4; ipv4 != nil { if ipv4.Nameservers != nil { - ipv4Nameservers = append(ipv4Nameservers, *ipv4.Nameservers...) + ipv4Nameservers = append(ipv4Nameservers, ipv4.Nameservers...) } if ipv4.Prefixes != nil { - ipv4Prefixes = append(ipv4Prefixes, *ipv4.Prefixes...) + ipv4Prefixes = append(ipv4Prefixes, ipv4.Prefixes...) } if ipv4.PublicIp != nil { publicIp = ipv4.PublicIp } - if ipv4.Gateway != nil && ipv4.Gateway.IsSet() { + if ipv4.Gateway.IsSet() { ipv4Gateway = ipv4.Gateway.Get() } } @@ -121,22 +121,22 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network) var ipv6Gateway *string if ipv6 := network.Ipv6; ipv6 != nil { if ipv6.Nameservers != nil { - ipv6Nameservers = append(ipv6Nameservers, *ipv6.Nameservers...) + ipv6Nameservers = append(ipv6Nameservers, ipv6.Nameservers...) } if ipv6.Prefixes != nil { - ipv6Prefixes = append(ipv6Prefixes, *ipv6.Prefixes...) + ipv6Prefixes = append(ipv6Prefixes, ipv6.Prefixes...) } - if ipv6.Gateway != nil && ipv6.Gateway.IsSet() { + if ipv6.Gateway.IsSet() { ipv6Gateway = ipv6.Gateway.Get() } } table := tables.NewTable() - table.AddRow("ID", utils.PtrString(network.Id)) + table.AddRow("ID", network.Id) table.AddSeparator() - table.AddRow("NAME", utils.PtrString(network.Name)) + table.AddRow("NAME", network.Name) table.AddSeparator() - table.AddRow("STATE", utils.PtrString(network.Status)) + table.AddRow("STATE", network.Status) table.AddSeparator() if publicIp != nil { @@ -184,9 +184,9 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network) table.AddRow("IPv6 PREFIXES", strings.Join(ipv6Prefixes, ", ")) table.AddSeparator() } - if network.Labels != nil && len(*network.Labels) > 0 { + if len(network.Labels) > 0 { var labels []string - for key, value := range *network.Labels { + for key, value := range network.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/network/describe/describe_test.go b/internal/cmd/network/describe/describe_test.go index cd305d7bb..7494b22f5 100644 --- a/internal/cmd/network/describe/describe_test.go +++ b/internal/cmd/network/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetNetworkRequest)) iaas.ApiGetNetworkRequest { - request := testClient.GetNetwork(testCtx, testProjectId, testRegion, testNetworkId) + request := testClient.DefaultAPI.GetNetwork(testCtx, testProjectId, testRegion, testNetworkId) for _, mod := range mods { mod(&request) } @@ -166,7 +166,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network/list/list.go b/internal/cmd/network/list/list.go index 4731e717a..ad412f36a 100644 --- a/internal/cmd/network/list/list.go +++ b/internal/cmd/network/list/list.go @@ -3,10 +3,11 @@ package list import ( "context" "fmt" + "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -127,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListNetworksRequest { - req := apiClient.ListNetworks(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListNetworks(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -148,7 +149,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, networks var publicIp, prefixes string if ipv4 := network.Ipv4; ipv4 != nil { publicIp = utils.PtrString(ipv4.PublicIp) - prefixes = utils.JoinStringPtr(ipv4.Prefixes, ", ") + prefixes = strings.Join(ipv4.Prefixes, ", ") } routed := false @@ -157,9 +158,9 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, networks } table.AddRow( - utils.PtrString(network.Id), - utils.PtrString(network.Name), - utils.PtrString(network.Status), + network.Id, + network.Name, + network.Status, publicIp, prefixes, routed, diff --git a/internal/cmd/network/list/list_test.go b/internal/cmd/network/list/list_test.go index 1aa09530c..ca08245ac 100644 --- a/internal/cmd/network/list/list_test.go +++ b/internal/cmd/network/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,7 +23,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListNetworksRequest)) iaas.ApiListNetworksRequest { - request := testClient.ListNetworks(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListNetworks(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/network/update/update.go b/internal/cmd/network/update/update.go index add37c6fa..eda3bb95d 100644 --- a/internal/cmd/network/update/update.go +++ b/internal/cmd/network/update/update.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -48,7 +48,7 @@ type inputModel struct { NoIPv4Gateway bool NoIPv6Gateway bool RoutingTableId *string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -92,7 +92,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, model.NetworkId) + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.NetworkId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) networkLabel = model.NetworkId @@ -117,7 +117,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Updating network", func() error { - _, err = wait.UpdateNetworkWaitHandler(ctx, apiClient, model.ProjectId, model.Region, networkId).WaitWithContext(ctx) + _, err = wait.UpdateNetworkWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, networkId).WaitWithContext(ctx) return err }) if err != nil { @@ -167,7 +167,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu NoIPv4Gateway: flags.FlagToBoolValue(p, cmd, noIpv4GatewayFlag), NoIPv6Gateway: flags.FlagToBoolValue(p, cmd, noIpv6GatewayFlag), RoutingTableId: flags.FlagToStringPointer(p, cmd, routingTableIdFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } p.DebugInputModel(model) @@ -175,31 +175,31 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiPartialUpdateNetworkRequest { - req := apiClient.PartialUpdateNetwork(ctx, model.ProjectId, model.Region, model.NetworkId) + req := apiClient.DefaultAPI.PartialUpdateNetwork(ctx, model.ProjectId, model.Region, model.NetworkId) var payloadIPv4 *iaas.UpdateNetworkIPv4Body var payloadIPv6 *iaas.UpdateNetworkIPv6Body if model.IPv6DnsNameServers != nil || model.NoIPv6Gateway || model.IPv6Gateway != nil { payloadIPv6 = &iaas.UpdateNetworkIPv6Body{ - Nameservers: model.IPv6DnsNameServers, + Nameservers: *model.IPv6DnsNameServers, } if model.NoIPv6Gateway { - payloadIPv6.Gateway = iaas.NewNullableString(nil) + payloadIPv6.Gateway = *iaas.NewNullableString(nil) } else if model.IPv6Gateway != nil { - payloadIPv6.Gateway = iaas.NewNullableString(model.IPv6Gateway) + payloadIPv6.Gateway = *iaas.NewNullableString(model.IPv6Gateway) } } if model.IPv4DnsNameServers != nil || model.NoIPv4Gateway || model.IPv4Gateway != nil { payloadIPv4 = &iaas.UpdateNetworkIPv4Body{ - Nameservers: model.IPv4DnsNameServers, + Nameservers: *model.IPv4DnsNameServers, } if model.NoIPv4Gateway { - payloadIPv4.Gateway = iaas.NewNullableString(nil) + payloadIPv4.Gateway = *iaas.NewNullableString(nil) } else if model.IPv4Gateway != nil { - payloadIPv4.Gateway = iaas.NewNullableString(model.IPv4Gateway) + payloadIPv4.Gateway = *iaas.NewNullableString(model.IPv4Gateway) } } @@ -207,7 +207,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli Name: model.Name, Ipv4: payloadIPv4, Ipv6: payloadIPv6, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, RoutingTableId: model.RoutingTableId, } diff --git a/internal/cmd/network/update/update_test.go b/internal/cmd/network/update/update_test.go index a78c27ce7..44dad9933 100644 --- a/internal/cmd/network/update/update_test.go +++ b/internal/cmd/network/update/update_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testNetworkId = uuid.NewString() @@ -69,9 +69,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { IPv4Gateway: utils.Ptr("10.1.2.3"), IPv6DnsNameServers: utils.Ptr([]string{"2001:4860:4860::8888", "2001:4860:4860::8844"}), IPv6Gateway: utils.Ptr("2001:4860:4860::8888"), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, RoutingTableId: utils.Ptr(testRoutingTableId), } for _, mod := range mods { @@ -81,7 +81,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiPartialUpdateNetworkRequest)) iaas.ApiPartialUpdateNetworkRequest { - request := testClient.PartialUpdateNetwork(testCtx, testProjectId, testRegion, testNetworkId) + request := testClient.DefaultAPI.PartialUpdateNetwork(testCtx, testProjectId, testRegion, testNetworkId) request = request.PartialUpdateNetworkPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -92,16 +92,16 @@ func fixtureRequest(mods ...func(request *iaas.ApiPartialUpdateNetworkRequest)) func fixturePayload(mods ...func(payload *iaas.PartialUpdateNetworkPayload)) iaas.PartialUpdateNetworkPayload { payload := iaas.PartialUpdateNetworkPayload{ Name: utils.Ptr("example-network-name"), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, Ipv4: &iaas.UpdateNetworkIPv4Body{ - Nameservers: utils.Ptr([]string{"1.1.1.0", "1.1.2.0"}), - Gateway: iaas.NewNullableString(utils.Ptr("10.1.2.3")), + Nameservers: []string{"1.1.1.0", "1.1.2.0"}, + Gateway: *iaas.NewNullableString(utils.Ptr("10.1.2.3")), }, Ipv6: &iaas.UpdateNetworkIPv6Body{ - Nameservers: utils.Ptr([]string{"2001:4860:4860::8888", "2001:4860:4860::8844"}), - Gateway: iaas.NewNullableString(utils.Ptr("2001:4860:4860::8888")), + Nameservers: []string{"2001:4860:4860::8888", "2001:4860:4860::8844"}, + Gateway: *iaas.NewNullableString(utils.Ptr("2001:4860:4860::8888")), }, RoutingTableId: utils.Ptr(testRoutingTableId), } @@ -328,7 +328,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), cmpopts.EquateComparable(testCtx), - cmp.AllowUnexported(iaas.NullableString{}), + cmp.AllowUnexported(iaas.NullableString{}, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/public-ip/associate/associate.go b/internal/cmd/public-ip/associate/associate.go index 9b86d2f61..399228d1c 100644 --- a/internal/cmd/public-ip/associate/associate.go +++ b/internal/cmd/public-ip/associate/associate.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId) + publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.PublicIpId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err) publicIpLabel = model.PublicIpId @@ -79,7 +79,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("associate public IP: %w", err) } - params.Printer.Outputf("Associated public IP %q with resource %v.\n", publicIpLabel, utils.PtrString(resp.GetNetworkInterface())) + params.Printer.Outputf("Associated public IP %q with resource %v.\n", publicIpLabel, resp.GetNetworkInterface()) return nil }, } @@ -113,10 +113,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdatePublicIPRequest { - req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) + req := apiClient.DefaultAPI.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) payload := iaas.UpdatePublicIPPayload{ - NetworkInterface: iaas.NewNullableString(model.AssociatedResourceId), + NetworkInterface: *iaas.NewNullableString(model.AssociatedResourceId), } return req.UpdatePublicIPPayload(payload) diff --git a/internal/cmd/public-ip/associate/associate_test.go b/internal/cmd/public-ip/associate/associate_test.go index 0960b21b0..3fe71e27d 100644 --- a/internal/cmd/public-ip/associate/associate_test.go +++ b/internal/cmd/public-ip/associate/associate_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testPublicIpId = uuid.NewString() @@ -68,7 +68,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.ApiUpdatePublicIPRequest { - request := testClient.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) + request := testClient.DefaultAPI.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) request = request.UpdatePublicIPPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -78,7 +78,7 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.A func fixturePayload(mods ...func(payload *iaas.UpdatePublicIPPayload)) iaas.UpdatePublicIPPayload { payload := iaas.UpdatePublicIPPayload{ - NetworkInterface: iaas.NewNullableString(utils.Ptr(testAssociatedResourceId)), + NetworkInterface: *iaas.NewNullableString(utils.Ptr(testAssociatedResourceId)), } for _, mod := range mods { mod(&payload) @@ -242,7 +242,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/public-ip/create/create.go b/internal/cmd/public-ip/create/create.go index 9da469d1e..17b746e9a 100644 --- a/internal/cmd/public-ip/create/create.go +++ b/internal/cmd/public-ip/create/create.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -28,7 +28,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel AssociatedResourceId *string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -106,7 +106,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, AssociatedResourceId: flags.FlagToStringPointer(p, cmd, associatedResourceIdFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } p.DebugInputModel(model) @@ -114,11 +114,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreatePublicIPRequest { - req := apiClient.CreatePublicIP(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreatePublicIP(ctx, model.ProjectId, model.Region) payload := iaas.CreatePublicIPPayload{ - NetworkInterface: iaas.NewNullableString(model.AssociatedResourceId), - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + NetworkInterface: *iaas.NewNullableString(model.AssociatedResourceId), + Labels: model.Labels, } return req.CreatePublicIPPayload(payload) diff --git a/internal/cmd/public-ip/create/create_test.go b/internal/cmd/public-ip/create/create_test.go index b85b9adfb..3fda027bc 100644 --- a/internal/cmd/public-ip/create/create_test.go +++ b/internal/cmd/public-ip/create/create_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testAssociatedResourceId = uuid.NewString() @@ -49,9 +49,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, }, AssociatedResourceId: utils.Ptr(testAssociatedResourceId), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -60,7 +60,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreatePublicIPRequest)) iaas.ApiCreatePublicIPRequest { - request := testClient.CreatePublicIP(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreatePublicIP(testCtx, testProjectId, testRegion) request = request.CreatePublicIPPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -70,10 +70,10 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreatePublicIPRequest)) iaas.A func fixturePayload(mods ...func(payload *iaas.CreatePublicIPPayload)) iaas.CreatePublicIPPayload { payload := iaas.CreatePublicIPPayload{ - NetworkInterface: iaas.NewNullableString(utils.Ptr(testAssociatedResourceId)), - Labels: utils.Ptr(map[string]interface{}{ + NetworkInterface: *iaas.NewNullableString(utils.Ptr(testAssociatedResourceId)), + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(&payload) @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/public-ip/delete/delete.go b/internal/cmd/public-ip/delete/delete.go index 8663ab334..7e0fb8ee1 100644 --- a/internal/cmd/public-ip/delete/delete.go +++ b/internal/cmd/public-ip/delete/delete.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId) + publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.PublicIpId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err) publicIpLabel = model.PublicIpId @@ -102,5 +102,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeletePublicIPRequest { - return apiClient.DeletePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) + return apiClient.DefaultAPI.DeletePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) } diff --git a/internal/cmd/public-ip/delete/delete_test.go b/internal/cmd/public-ip/delete/delete_test.go index 25290233e..5e54efb60 100644 --- a/internal/cmd/public-ip/delete/delete_test.go +++ b/internal/cmd/public-ip/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testPublicIpId = uuid.NewString() var testProjectId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeletePublicIPRequest)) iaas.ApiDeletePublicIPRequest { - request := testClient.DeletePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) + request := testClient.DefaultAPI.DeletePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) for _, mod := range mods { mod(&request) } @@ -165,7 +165,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/public-ip/describe/describe.go b/internal/cmd/public-ip/describe/describe.go index a4334b421..125a54ff8 100644 --- a/internal/cmd/public-ip/describe/describe.go +++ b/internal/cmd/public-ip/describe/describe.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -90,7 +90,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetPublicIPRequest { - return apiClient.GetPublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) + return apiClient.DefaultAPI.GetPublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) } func outputResult(p *print.Printer, outputFormat string, publicIp iaas.PublicIp) error { @@ -101,15 +101,13 @@ func outputResult(p *print.Printer, outputFormat string, publicIp iaas.PublicIp) table.AddRow("IP ADDRESS", utils.PtrString(publicIp.Ip)) table.AddSeparator() - if publicIp.NetworkInterface != nil { - networkInterfaceId := *publicIp.GetNetworkInterface() - table.AddRow("ASSOCIATED TO", networkInterfaceId) - table.AddSeparator() - } + networkInterfaceId := publicIp.GetNetworkInterface() + table.AddRow("ASSOCIATED TO", networkInterfaceId) + table.AddSeparator() - if publicIp.Labels != nil && len(*publicIp.Labels) > 0 { + if len(publicIp.Labels) > 0 { labels := []string{} - for key, value := range *publicIp.Labels { + for key, value := range publicIp.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/public-ip/describe/describe_test.go b/internal/cmd/public-ip/describe/describe_test.go index 070a6c842..a66125e0e 100644 --- a/internal/cmd/public-ip/describe/describe_test.go +++ b/internal/cmd/public-ip/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testPublicIpId = uuid.NewString() @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetPublicIPRequest)) iaas.ApiGetPublicIPRequest { - request := testClient.GetPublicIP(testCtx, testProjectId, testRegion, testPublicIpId) + request := testClient.DefaultAPI.GetPublicIP(testCtx, testProjectId, testRegion, testPublicIpId) for _, mod := range mods { mod(&request) } @@ -166,7 +166,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/public-ip/disassociate/disassociate.go b/internal/cmd/public-ip/disassociate/disassociate.go index fae9afa0e..08d432e68 100644 --- a/internal/cmd/public-ip/disassociate/disassociate.go +++ b/internal/cmd/public-ip/disassociate/disassociate.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -54,7 +54,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - publicIpLabel, associatedResourceId, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId) + publicIpLabel, associatedResourceId, err := iaasUtils.GetPublicIP(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.PublicIpId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err) publicIpLabel = model.PublicIpId @@ -100,10 +100,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdatePublicIPRequest { - req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) + req := apiClient.DefaultAPI.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) payload := iaas.UpdatePublicIPPayload{ - NetworkInterface: iaas.NewNullableString(nil), + NetworkInterface: *iaas.NewNullableString(nil), } return req.UpdatePublicIPPayload(payload) diff --git a/internal/cmd/public-ip/disassociate/disassociate_test.go b/internal/cmd/public-ip/disassociate/disassociate_test.go index 4b069d183..73cb88d5c 100644 --- a/internal/cmd/public-ip/disassociate/disassociate_test.go +++ b/internal/cmd/public-ip/disassociate/disassociate_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testPublicIpId = uuid.NewString() @@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.ApiUpdatePublicIPRequest { - request := testClient.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) + request := testClient.DefaultAPI.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) request = request.UpdatePublicIPPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -73,7 +73,7 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.A func fixturePayload(mods ...func(payload *iaas.UpdatePublicIPPayload)) iaas.UpdatePublicIPPayload { payload := iaas.UpdatePublicIPPayload{ - NetworkInterface: iaas.NewNullableString(nil), + NetworkInterface: *iaas.NewNullableString(nil), } for _, mod := range mods { mod(&payload) @@ -213,7 +213,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/public-ip/list/list.go b/internal/cmd/public-ip/list/list.go index a75d94f40..884613390 100644 --- a/internal/cmd/public-ip/list/list.go +++ b/internal/cmd/public-ip/list/list.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -129,7 +129,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListPublicIPsRequest { - req := apiClient.ListPublicIPs(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListPublicIPs(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -147,11 +147,10 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, publicIps table.SetHeader("ID", "IP ADDRESS", "USED BY") for _, publicIp := range publicIps { - networkInterfaceId := utils.PtrStringDefault(publicIp.GetNetworkInterface(), "") table.AddRow( utils.PtrString(publicIp.Id), utils.PtrString(publicIp.Ip), - networkInterfaceId, + publicIp.GetNetworkInterface(), ) table.AddSeparator() } diff --git a/internal/cmd/public-ip/list/list_test.go b/internal/cmd/public-ip/list/list_test.go index e2c840c24..e44b2fcc2 100644 --- a/internal/cmd/public-ip/list/list_test.go +++ b/internal/cmd/public-ip/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testLabelSelector = "label" @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListPublicIPsRequest)) iaas.ApiListPublicIPsRequest { - request := testClient.ListPublicIPs(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListPublicIPs(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/public-ip/ranges/list/list.go b/internal/cmd/public-ip/ranges/list/list.go index cf01450cf..05d09a907 100644 --- a/internal/cmd/public-ip/ranges/list/list.go +++ b/internal/cmd/public-ip/ranges/list/list.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -16,7 +16,6 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) const ( @@ -62,12 +61,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Call API - req := apiClient.ListPublicIPRanges(ctx) + req := apiClient.DefaultAPI.ListPublicIPRanges(ctx) resp, err := req.Execute() if err != nil { return fmt.Errorf("list public IP ranges: %w", err) } - publicIpRanges := utils.GetSliceFromPointer(resp.Items) + publicIpRanges := resp.Items // Truncate output if model.Limit != nil && len(publicIpRanges) > int(*model.Limit) { @@ -114,8 +113,8 @@ func outputResult(p *print.Printer, outputFormat string, publicIpRanges []iaas.P } for _, item := range publicIpRanges { - if item.Cidr != nil && *item.Cidr != "" { - p.Outputln(*item.Cidr) + if item.Cidr != "" { + p.Outputln(item.Cidr) } } diff --git a/internal/cmd/public-ip/ranges/list/list_test.go b/internal/cmd/public-ip/ranges/list/list_test.go index 8af609105..8dfe478a1 100644 --- a/internal/cmd/public-ip/ranges/list/list_test.go +++ b/internal/cmd/public-ip/ranges/list/list_test.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -105,7 +105,7 @@ func TestOutputResult(t *testing.T) { name: "JSON output single", outputFormat: "json", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, + {Cidr: "192.168.0.0/24"}, }, wantErr: false, }, @@ -113,8 +113,8 @@ func TestOutputResult(t *testing.T) { name: "JSON output multiple", outputFormat: "json", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, - {Cidr: utils.Ptr("192.167.0.0/24")}, + {Cidr: "192.168.0.0/24"}, + {Cidr: "192.167.0.0/24"}, }, wantErr: false, }, @@ -122,7 +122,7 @@ func TestOutputResult(t *testing.T) { name: "YAML output single", outputFormat: "yaml", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, + {Cidr: "192.168.0.0/24"}, }, wantErr: false, }, @@ -130,8 +130,8 @@ func TestOutputResult(t *testing.T) { name: "YAML output multiple", outputFormat: "yaml", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, - {Cidr: utils.Ptr("192.167.0.0/24")}, + {Cidr: "192.168.0.0/24"}, + {Cidr: "192.167.0.0/24"}, }, wantErr: false, }, @@ -139,7 +139,7 @@ func TestOutputResult(t *testing.T) { name: "pretty output single", outputFormat: "pretty", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, + {Cidr: "192.168.0.0/24"}, }, wantErr: false, }, @@ -147,8 +147,8 @@ func TestOutputResult(t *testing.T) { name: "pretty output multiple", outputFormat: "pretty", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, - {Cidr: utils.Ptr("192.167.0.0/24")}, + {Cidr: "192.168.0.0/24"}, + {Cidr: "192.167.0.0/24"}, }, wantErr: false, }, @@ -156,7 +156,7 @@ func TestOutputResult(t *testing.T) { name: "default output", outputFormat: "", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: utils.Ptr("192.168.0.0/24")}, + {Cidr: "192.168.0.0/24"}, }, wantErr: false, }, @@ -170,8 +170,8 @@ func TestOutputResult(t *testing.T) { name: "nil CIDR", outputFormat: "pretty", publicIpRanges: []iaas.PublicNetwork{ - {Cidr: nil}, - {Cidr: utils.Ptr("192.168.0.0/24")}, + {Cidr: ""}, + {Cidr: "192.168.0.0/24"}, }, wantErr: false, }, diff --git a/internal/cmd/public-ip/update/update.go b/internal/cmd/public-ip/update/update.go index bdecb7dfc..5e99f8f25 100644 --- a/internal/cmd/public-ip/update/update.go +++ b/internal/cmd/public-ip/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -29,7 +29,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel PublicIpId string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -61,7 +61,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId) + publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.PublicIpId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get public IP: %v", err) publicIpLabel = model.PublicIpId @@ -99,7 +99,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu return nil, &cliErr.ProjectIdError{} } - labels := flags.FlagToStringToStringPointer(p, cmd, labelFlag) + labels := flags.FlagToStringToAny(p, cmd, labelFlag) if labels == nil { return nil, &cliErr.EmptyUpdateError{} @@ -116,10 +116,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdatePublicIPRequest { - req := apiClient.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) + req := apiClient.DefaultAPI.UpdatePublicIP(ctx, model.ProjectId, model.Region, model.PublicIpId) payload := iaas.UpdatePublicIPPayload{ - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.UpdatePublicIPPayload(payload) diff --git a/internal/cmd/public-ip/update/update_test.go b/internal/cmd/public-ip/update/update_test.go index 7292910cd..50187f733 100644 --- a/internal/cmd/public-ip/update/update_test.go +++ b/internal/cmd/public-ip/update/update_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" ) const ( @@ -21,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testPublicIpId = uuid.NewString() @@ -57,9 +56,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, }, PublicIpId: testPublicIpId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -68,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.ApiUpdatePublicIPRequest { - request := testClient.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) + request := testClient.DefaultAPI.UpdatePublicIP(testCtx, testProjectId, testRegion, testPublicIpId) request = request.UpdatePublicIPPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -78,9 +77,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdatePublicIPRequest)) iaas.A func fixturePayload(mods ...func(payload *iaas.UpdatePublicIPPayload)) iaas.UpdatePublicIPPayload { payload := iaas.UpdatePublicIPPayload{ - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(&payload) @@ -220,7 +219,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/quota/list/list.go b/internal/cmd/quota/list/list.go index f8b77390c..e26c9038c 100644 --- a/internal/cmd/quota/list/list.go +++ b/internal/cmd/quota/list/list.go @@ -8,14 +8,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" ) @@ -49,14 +48,6 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd) - if err != nil { - params.Printer.Debug(print.ErrorLevel, "get project name: %v", err) - projectLabel = model.ProjectId - } else if projectLabel == "" { - projectLabel = model.ProjectId - } - // Call API request := buildRequest(ctx, model, apiClient) @@ -65,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("list quotas: %w", err) } - return outputResult(params.Printer, model.OutputFormat, projectLabel, response.Quotas) + return outputResult(params.Printer, model.OutputFormat, &response.Quotas) }, } @@ -87,55 +78,27 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListQuotasRequest { - request := apiClient.ListQuotas(ctx, model.ProjectId, model.Region) + request := apiClient.DefaultAPI.ListQuotas(ctx, model.ProjectId, model.Region) return request } -func outputResult(p *print.Printer, outputFormat, projectLabel string, quotas *iaas.QuotaList) error { +func outputResult(p *print.Printer, outputFormat string, quotas *iaas.QuotaList) error { return p.OutputResult(outputFormat, quotas, func() error { - if quotas == nil { - p.Outputf("No quotas found for project %q", projectLabel) - return nil - } table := tables.NewTable() table.SetHeader("NAME", "LIMIT", "CURRENT USAGE", "PERCENT") - if val := quotas.BackupGigabytes; val != nil { - table.AddRow("Total size in GiB of backups [GiB]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Backups; val != nil { - table.AddRow("Number of backups [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Gigabytes; val != nil { - table.AddRow("Total size in GiB of volumes and snapshots [GiB]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Networks; val != nil { - table.AddRow("Number of networks [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Nics; val != nil { - table.AddRow("Number of network interfaces (nics) [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.PublicIps; val != nil { - table.AddRow("Number of public IP addresses [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Ram; val != nil { - table.AddRow("Amount of server RAM in MiB [MiB]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.SecurityGroupRules; val != nil { - table.AddRow("Number of security group rules [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.SecurityGroups; val != nil { - table.AddRow("Number of security groups [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Snapshots; val != nil { - table.AddRow("Number of snapshots [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Vcpu; val != nil { - table.AddRow("Number of server cores (vcpu) [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } - if val := quotas.Volumes; val != nil { - table.AddRow("Number of volumes [Count]", conv(val.Limit), conv(val.Usage), percentage(val)) - } + table.AddRow(quotaRow("Total size in GiB of backups [GiB]", quotas.BackupGigabytes)...) + table.AddRow(quotaRow("Number of backups [Count]", quotas.Backups)...) + table.AddRow(quotaRow("Total size in GiB of volumes and snapshots [GiB]", quotas.Gigabytes)...) + table.AddRow(quotaRow("Number of networks [Count]", quotas.Networks)...) + table.AddRow(quotaRow("Number of network interfaces (nics) [Count]", quotas.Nics)...) + table.AddRow(quotaRow("Number of public IP addresses [Count]", quotas.PublicIps)...) + table.AddRow(quotaRow("Amount of server RAM in MiB [MiB]", quotas.Ram)...) + table.AddRow(quotaRow("Number of security group rules [Count]", quotas.SecurityGroupRules)...) + table.AddRow(quotaRow("Number of security groups [Count]", quotas.SecurityGroups)...) + table.AddRow(quotaRow("Number of snapshots [Count]", quotas.Snapshots)...) + table.AddRow(quotaRow("Number of server cores (vcpu) [Count]", quotas.Vcpu)...) + table.AddRow(quotaRow("Number of volumes [Count]", quotas.Volumes)...) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) @@ -145,21 +108,12 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, quotas *i }) } -func conv(n *int64) string { - if n != nil { - return strconv.FormatInt(*n, 10) - } - return "n/a" +func quotaRow(description string, quota iaas.Quota) []interface{} { + result := make([]interface{}, 0, 4) + result = append(result, description, conv(quota.Limit), conv(quota.Usage), fmt.Sprintf("%3.1f%%", 100.0/float64(quota.Limit)*float64(quota.Usage))) + return result } -func percentage(val interface { - GetLimitOk() (int64, bool) - GetUsageOk() (int64, bool) -}) string { - a, aOk := val.GetLimitOk() - b, bOk := val.GetUsageOk() - if aOk && bOk { - return fmt.Sprintf("%3.1f%%", 100.0/float64(a)*float64(b)) - } - return "n/a" +func conv(n int64) string { + return strconv.FormatInt(n, 10) } diff --git a/internal/cmd/quota/list/list_test.go b/internal/cmd/quota/list/list_test.go index 693d938ae..cad93beb6 100644 --- a/internal/cmd/quota/list/list_test.go +++ b/internal/cmd/quota/list/list_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() ) @@ -52,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListQuotasRequest)) iaas.ApiListQuotasRequest { - request := testClient.ListQuotas(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListQuotas(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -126,7 +126,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -138,8 +138,7 @@ func TestBuildRequest(t *testing.T) { func Test_outputResult(t *testing.T) { type args struct { outputFormat string - projectLabel string - quotas *iaas.QuotaList + quotas iaas.QuotaList } tests := []struct { name string @@ -154,7 +153,7 @@ func Test_outputResult(t *testing.T) { { name: "set quota empty", args: args{ - quotas: &iaas.QuotaList{}, + quotas: iaas.QuotaList{}, }, wantErr: false, }, @@ -162,7 +161,7 @@ func Test_outputResult(t *testing.T) { params := testparams.NewTestParams() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.quotas); (err != nil) != tt.wantErr { + if err := outputResult(params.Printer, tt.args.outputFormat, &tt.args.quotas); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/cmd/security-group/create/create.go b/internal/cmd/security-group/create/create.go index dfbbc258c..b835d10b4 100644 --- a/internal/cmd/security-group/create/create.go +++ b/internal/cmd/security-group/create/create.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -28,9 +28,9 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Labels *map[string]string + Labels map[string]any Description *string - Name *string + Name string Stateful *bool } @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - prompt := fmt.Sprintf("Are you sure you want to create the security group %q?", *model.Name) + prompt := fmt.Sprintf("Are you sure you want to create the security group %q?", model.Name) err = params.Printer.PromptForConfirmation(prompt) if err != nil { return err @@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("create security group: %w", err) } - if err := outputResult(params.Printer, model.OutputFormat, *model.Name, *group); err != nil { + if err := outputResult(params.Printer, model.OutputFormat, model.Name, group); err != nil { return err } @@ -103,9 +103,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, - Name: &name, + Name: name, - Labels: flags.FlagToStringToStringPointer(p, cmd, labelsFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelsFlag), Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), Stateful: flags.FlagToBoolPointer(p, cmd, statefulFlag), } @@ -115,11 +115,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateSecurityGroupRequest { - request := apiClient.CreateSecurityGroup(ctx, model.ProjectId, model.Region) + request := apiClient.DefaultAPI.CreateSecurityGroup(ctx, model.ProjectId, model.Region) payload := iaas.CreateSecurityGroupPayload{ Description: model.Description, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, Name: model.Name, Stateful: model.Stateful, } @@ -127,7 +127,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli return request.CreateSecurityGroupPayload(payload) } -func outputResult(p *print.Printer, outputFormat, name string, resp iaas.SecurityGroup) error { +func outputResult(p *print.Printer, outputFormat, name string, resp *iaas.SecurityGroup) error { return p.OutputResult(outputFormat, resp, func() error { p.Outputf("Created security group %q.\nSecurity Group ID %s\n", name, utils.PtrString(resp.Id)) return nil diff --git a/internal/cmd/security-group/create/create_test.go b/internal/cmd/security-group/create/create_test.go index 92889c2ca..986a6b0c0 100644 --- a/internal/cmd/security-group/create/create_test.go +++ b/internal/cmd/security-group/create/create_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -23,11 +23,11 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testName = "new-security-group" testDescription = "a test description" - testLabels = map[string]string{ + testLabels = map[string]any{ "fooKey": "fooValue", "barKey": "barValue", "bazKey": "bazValue", @@ -58,9 +58,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, - Labels: &testLabels, + Labels: testLabels, Description: &testDescription, - Name: &testName, + Name: testName, Stateful: &testStateful, } for _, mod := range mods { @@ -69,23 +69,13 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { return model } -func toStringAnyMapPtr(m map[string]string) map[string]any { - if m == nil { - return nil - } - result := map[string]any{} - for k, v := range m { - result[k] = v - } - return result -} func fixtureRequest(mods ...func(request *iaas.ApiCreateSecurityGroupRequest)) iaas.ApiCreateSecurityGroupRequest { - request := testClient.CreateSecurityGroup(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateSecurityGroup(testCtx, testProjectId, testRegion) request = request.CreateSecurityGroupPayload(iaas.CreateSecurityGroupPayload{ Description: &testDescription, - Labels: utils.Ptr(toStringAnyMapPtr(testLabels)), - Name: &testName, + Labels: testLabels, + Name: testName, Rules: nil, Stateful: &testStateful, }) @@ -159,7 +149,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = &map[string]string{ + model.Labels = map[string]any{ "foo": "bar", } }), @@ -200,10 +190,10 @@ func TestBuildRequest(t *testing.T) { model.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateSecurityGroupRequest) { - *request = (*request).CreateSecurityGroupPayload(iaas.CreateSecurityGroupPayload{ + *request = request.CreateSecurityGroupPayload(iaas.CreateSecurityGroupPayload{ Description: &testDescription, Labels: nil, - Name: &testName, + Name: testName, Stateful: &testStateful, }) }), @@ -214,10 +204,10 @@ func TestBuildRequest(t *testing.T) { model.Stateful = utils.Ptr(false) }), expectedRequest: fixtureRequest(func(request *iaas.ApiCreateSecurityGroupRequest) { - *request = (*request).CreateSecurityGroupPayload(iaas.CreateSecurityGroupPayload{ + *request = request.CreateSecurityGroupPayload(iaas.CreateSecurityGroupPayload{ Description: &testDescription, - Labels: utils.Ptr(toStringAnyMapPtr(testLabels)), - Name: &testName, + Labels: testLabels, + Name: testName, Stateful: utils.Ptr(false), }) }), @@ -229,7 +219,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -258,7 +248,7 @@ func TestOutputResult(t *testing.T) { params := testparams.NewTestParams() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := outputResult(params.Printer, tt.args.outputFormat, tt.name, tt.args.resp); (err != nil) != tt.wantErr { + if err := outputResult(params.Printer, tt.args.outputFormat, tt.name, &tt.args.resp); (err != nil) != tt.wantErr { t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/cmd/security-group/delete/delete.go b/internal/cmd/security-group/delete/delete.go index da840337c..6937998e9 100644 --- a/internal/cmd/security-group/delete/delete.go +++ b/internal/cmd/security-group/delete/delete.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { projectLabel = model.ProjectId } - groupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + groupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Warn("get security group name: %v", err) groupLabel = model.SecurityGroupId @@ -98,6 +98,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteSecurityGroupRequest { - request := apiClient.DeleteSecurityGroup(ctx, model.ProjectId, model.Region, model.SecurityGroupId) + request := apiClient.DefaultAPI.DeleteSecurityGroup(ctx, model.ProjectId, model.Region, model.SecurityGroupId) return request } diff --git a/internal/cmd/security-group/delete/delete_test.go b/internal/cmd/security-group/delete/delete_test.go index aeba061cb..9383a7dbc 100644 --- a/internal/cmd/security-group/delete/delete_test.go +++ b/internal/cmd/security-group/delete/delete_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testGroupId = uuid.NewString() ) @@ -54,7 +54,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteSecurityGroupRequest)) iaas.ApiDeleteSecurityGroupRequest { - request := testClient.DeleteSecurityGroup(testCtx, testProjectId, testRegion, testGroupId) + request := testClient.DefaultAPI.DeleteSecurityGroup(testCtx, testProjectId, testRegion, testGroupId) for _, mod := range mods { mod(&request) } @@ -182,7 +182,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/security-group/describe/describe.go b/internal/cmd/security-group/describe/describe.go index 485c2f10d..9f9a9591c 100644 --- a/internal/cmd/security-group/describe/describe.go +++ b/internal/cmd/security-group/describe/describe.go @@ -17,7 +17,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type inputModel struct { @@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetSecurityGroupRequest { - request := apiClient.GetSecurityGroup(ctx, model.ProjectId, model.Region, model.SecurityGroupId) + request := apiClient.DefaultAPI.GetSecurityGroup(ctx, model.ProjectId, model.Region, model.SecurityGroupId) return request } @@ -103,10 +103,8 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.SecurityGrou } table.AddSeparator() - if name := resp.Name; name != nil { - table.AddRow("NAME", *name) - table.AddSeparator() - } + table.AddRow("NAME", resp.Name) + table.AddSeparator() if description := resp.Description; description != nil { table.AddRow("DESCRIPTION", *description) @@ -118,9 +116,9 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.SecurityGrou table.AddSeparator() } - if resp.Labels != nil && len(*resp.Labels) > 0 { + if len(resp.Labels) > 0 { var labels []string - for key, value := range *resp.Labels { + for key, value := range resp.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) @@ -139,7 +137,7 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.SecurityGrou content = append(content, table) - if resp.Rules != nil && len(*resp.Rules) > 0 { + if len(resp.Rules) > 0 { rulesTable := tables.NewTable() rulesTable.SetTitle("RULES") rulesTable.SetHeader( @@ -154,10 +152,10 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.SecurityGrou "REMOTE SECURITY GROUP ID", ) - for _, rule := range *resp.Rules { + for _, rule := range resp.Rules { var portRange string if rule.PortRange != nil { - portRange = fmt.Sprintf("%s-%s", utils.PtrString(rule.PortRange.Min), utils.PtrString(rule.PortRange.Max)) + portRange = fmt.Sprintf("%d-%d", rule.PortRange.Min, rule.PortRange.Max) } var protocol string @@ -167,14 +165,14 @@ func outputResult(p *print.Printer, outputFormat string, resp *iaas.SecurityGrou var icmpParameter string if rule.IcmpParameters != nil { - icmpParameter = fmt.Sprintf("type: %s, code: %s", utils.PtrString(rule.IcmpParameters.Type), utils.PtrString(rule.IcmpParameters.Code)) + icmpParameter = fmt.Sprintf("type: %d, code: %d", rule.IcmpParameters.Type, rule.IcmpParameters.Code) } rulesTable.AddRow( utils.PtrString(rule.Id), utils.PtrString(rule.Description), protocol, - utils.PtrString(rule.Direction), + rule.Direction, utils.PtrString(rule.Ethertype), portRange, utils.PtrString(rule.IpRange), diff --git a/internal/cmd/security-group/describe/describe_test.go b/internal/cmd/security-group/describe/describe_test.go index 5ab281ffd..d0328fd67 100644 --- a/internal/cmd/security-group/describe/describe_test.go +++ b/internal/cmd/security-group/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testSecurityGroupId = []string{uuid.NewString()} ) @@ -54,7 +54,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetSecurityGroupRequest)) iaas.ApiGetSecurityGroupRequest { - request := testClient.GetSecurityGroup(testCtx, testProjectId, testRegion, testSecurityGroupId[0]) + request := testClient.DefaultAPI.GetSecurityGroup(testCtx, testProjectId, testRegion, testSecurityGroupId[0]) for _, mod := range mods { mod(&request) } @@ -193,7 +193,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/security-group/list/list.go b/internal/cmd/security-group/list/list.go index 32e71ec48..95c83a7d5 100644 --- a/internal/cmd/security-group/list/list.go +++ b/internal/cmd/security-group/list/list.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -123,7 +123,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListSecurityGroupsRequest { - request := apiClient.ListSecurityGroups(ctx, model.ProjectId, model.Region) + request := apiClient.DefaultAPI.ListSecurityGroups(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { request = request.LabelSelector(*model.LabelSelector) } @@ -142,7 +142,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, items []i var labelsString string if item.Labels != nil { var labels []string - for key, value := range *item.Labels { + for key, value := range item.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } labelsString = strings.Join(labels, ", ") @@ -150,7 +150,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, items []i table.AddRow( utils.PtrString(item.Id), - utils.PtrString(item.Name), + item.Name, utils.PtrString(item.Stateful), utils.PtrString(item.Description), labelsString, diff --git a/internal/cmd/security-group/list/list_test.go b/internal/cmd/security-group/list/list_test.go index 9677ec466..6e77eec9b 100644 --- a/internal/cmd/security-group/list/list_test.go +++ b/internal/cmd/security-group/list/list_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -23,7 +23,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testLabels = "fooKey=fooValue,barKey=barValue,bazKey=bazValue" ) @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListSecurityGroupsRequest)) iaas.ApiListSecurityGroupsRequest { - request := testClient.ListSecurityGroups(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListSecurityGroups(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabels) for _, mod := range mods { mod(&request) @@ -167,7 +167,7 @@ func TestBuildRequest(t *testing.T) { model.LabelSelector = utils.Ptr("") }), expectedRequest: fixtureRequest(func(request *iaas.ApiListSecurityGroupsRequest) { - *request = (*request).LabelSelector("") + *request = request.LabelSelector("") }), }, { @@ -176,7 +176,7 @@ func TestBuildRequest(t *testing.T) { model.LabelSelector = utils.Ptr("foo=bar") }), expectedRequest: fixtureRequest(func(request *iaas.ApiListSecurityGroupsRequest) { - *request = (*request).LabelSelector("foo=bar") + *request = request.LabelSelector("foo=bar") }), }, } @@ -186,7 +186,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/security-group/rule/create/create.go b/internal/cmd/security-group/rule/create/create.go index 9b836dd81..a5248580c 100644 --- a/internal/cmd/security-group/rule/create/create.go +++ b/internal/cmd/security-group/rule/create/create.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -40,7 +40,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel SecurityGroupId string - Direction *string + Direction string Description *string EtherType *string IcmpParameterCode *int64 @@ -96,7 +96,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { projectLabel = model.ProjectId } - securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get security group name: %v", err) securityGroupLabel = model.SecurityGroupId @@ -150,7 +150,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, SecurityGroupId: flags.FlagToStringValue(p, cmd, securityGroupIdFlag), - Direction: flags.FlagToStringPointer(p, cmd, directionFlag), + Direction: flags.FlagToStringValue(p, cmd, directionFlag), Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), EtherType: flags.FlagToStringPointer(p, cmd, etherTypeFlag), IcmpParameterCode: flags.FlagToInt64Pointer(p, cmd, icmpParameterCodeFlag), @@ -168,7 +168,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateSecurityGroupRuleRequest { - req := apiClient.CreateSecurityGroupRule(ctx, model.ProjectId, model.Region, model.SecurityGroupId) + req := apiClient.DefaultAPI.CreateSecurityGroupRule(ctx, model.ProjectId, model.Region, model.SecurityGroupId) icmpParameters := &iaas.ICMPParameters{} portRange := &iaas.PortRange{} protocol := &iaas.CreateProtocol{} @@ -182,15 +182,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli } if model.IcmpParameterCode != nil || model.IcmpParameterType != nil { - icmpParameters.Code = model.IcmpParameterCode - icmpParameters.Type = model.IcmpParameterType + icmpParameters.Code = *model.IcmpParameterCode + icmpParameters.Type = *model.IcmpParameterType payload.IcmpParameters = icmpParameters } if model.PortRangeMax != nil || model.PortRangeMin != nil { - portRange.Max = model.PortRangeMax - portRange.Min = model.PortRangeMin + portRange.Max = *model.PortRangeMax + portRange.Min = *model.PortRangeMin payload.PortRange = portRange } diff --git a/internal/cmd/security-group/rule/create/create_test.go b/internal/cmd/security-group/rule/create/create_test.go index 13cdac884..de81f8ca9 100644 --- a/internal/cmd/security-group/rule/create/create_test.go +++ b/internal/cmd/security-group/rule/create/create_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -23,7 +23,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testSecurityGroupId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Verbosity: globalflags.VerbosityDefault, }, SecurityGroupId: testSecurityGroupId, - Direction: utils.Ptr("ingress"), + Direction: "ingress", Description: utils.Ptr("example-description"), EtherType: utils.Ptr("ether"), IcmpParameterCode: utils.Ptr(int64(0)), @@ -80,7 +80,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateSecurityGroupRuleRequest)) iaas.ApiCreateSecurityGroupRuleRequest { - request := testClient.CreateSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId) + request := testClient.DefaultAPI.CreateSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId) request = request.CreateSecurityGroupRulePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -89,9 +89,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateSecurityGroupRuleRequest } func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateSecurityGroupRuleRequest)) iaas.ApiCreateSecurityGroupRuleRequest { - request := testClient.CreateSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId) + request := testClient.DefaultAPI.CreateSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId) request = request.CreateSecurityGroupRulePayload(iaas.CreateSecurityGroupRulePayload{ - Direction: utils.Ptr("ingress"), + Direction: "ingress", }) for _, mod := range mods { mod(&request) @@ -101,17 +101,17 @@ func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateSecurityGroupRul func fixturePayload(mods ...func(payload *iaas.CreateSecurityGroupRulePayload)) iaas.CreateSecurityGroupRulePayload { payload := iaas.CreateSecurityGroupRulePayload{ - Direction: utils.Ptr("ingress"), + Direction: "ingress", Description: utils.Ptr("example-description"), Ethertype: utils.Ptr("ether"), IcmpParameters: &iaas.ICMPParameters{ - Code: utils.Ptr(int64(0)), - Type: utils.Ptr(int64(8)), + Code: int64(0), + Type: int64(8), }, IpRange: utils.Ptr("10.1.2.3"), PortRange: &iaas.PortRange{ - Max: utils.Ptr(int64(24)), - Min: utils.Ptr(int64(22)), + Max: int64(24), + Min: int64(22), }, Protocol: &iaas.CreateProtocol{ Int64: utils.Ptr(int64(1)), @@ -275,7 +275,7 @@ func TestBuildRequest(t *testing.T) { Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, - Direction: utils.Ptr("ingress"), + Direction: "ingress", SecurityGroupId: testSecurityGroupId, }, expectedRequest: fixtureRequiredRequest(), @@ -287,7 +287,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), cmp.AllowUnexported(iaas.NullableString{}), ) if diff != "" { diff --git a/internal/cmd/security-group/rule/delete/delete.go b/internal/cmd/security-group/rule/delete/delete.go index 837a94b9c..916acd6ac 100644 --- a/internal/cmd/security-group/rule/delete/delete.go +++ b/internal/cmd/security-group/rule/delete/delete.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -60,13 +60,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get security group name: %v", err) securityGroupLabel = model.SecurityGroupId } - securityGroupRuleLabel, err := iaasUtils.GetSecurityGroupRuleName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupRuleId, model.SecurityGroupId) + securityGroupRuleLabel, err := iaasUtils.GetSecurityGroupRuleName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupRuleId, model.SecurityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get security group rule name: %v", err) securityGroupRuleLabel = model.SecurityGroupRuleId @@ -119,5 +119,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteSecurityGroupRuleRequest { - return apiClient.DeleteSecurityGroupRule(ctx, model.ProjectId, model.Region, model.SecurityGroupId, model.SecurityGroupRuleId) + return apiClient.DefaultAPI.DeleteSecurityGroupRule(ctx, model.ProjectId, model.Region, model.SecurityGroupId, model.SecurityGroupRuleId) } diff --git a/internal/cmd/security-group/rule/delete/delete_test.go b/internal/cmd/security-group/rule/delete/delete_test.go index ba83af3b1..c162029b7 100644 --- a/internal/cmd/security-group/rule/delete/delete_test.go +++ b/internal/cmd/security-group/rule/delete/delete_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testSecurityGroupId = uuid.NewString() @@ -67,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteSecurityGroupRuleRequest)) iaas.ApiDeleteSecurityGroupRuleRequest { - request := testClient.DeleteSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId, testSecurityGroupRuleId) + request := testClient.DefaultAPI.DeleteSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId, testSecurityGroupRuleId) for _, mod := range mods { mod(&request) } @@ -230,7 +230,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/security-group/rule/describe/describe.go b/internal/cmd/security-group/rule/describe/describe.go index c4e421fa6..c6b2c9ea5 100644 --- a/internal/cmd/security-group/rule/describe/describe.go +++ b/internal/cmd/security-group/rule/describe/describe.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -102,7 +102,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetSecurityGroupRuleRequest { - return apiClient.GetSecurityGroupRule(ctx, model.ProjectId, model.Region, model.SecurityGroupId, model.SecurityGroupRuleId) + return apiClient.DefaultAPI.GetSecurityGroupRule(ctx, model.ProjectId, model.Region, model.SecurityGroupId, model.SecurityGroupRuleId) } func outputResult(p *print.Printer, outputFormat string, securityGroupRule *iaas.SecurityGroupRule) error { @@ -126,19 +126,14 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRule *iaas } } - table.AddRow("DIRECTION", utils.PtrString(securityGroupRule.Direction)) + table.AddRow("DIRECTION", securityGroupRule.Direction) table.AddSeparator() if securityGroupRule.PortRange != nil { - if securityGroupRule.PortRange.Min != nil { - table.AddRow("START PORT", *securityGroupRule.PortRange.Min) - table.AddSeparator() - } - - if securityGroupRule.PortRange.Max != nil { - table.AddRow("END PORT", *securityGroupRule.PortRange.Max) - table.AddSeparator() - } + table.AddRow("START PORT", securityGroupRule.PortRange.Min) + table.AddSeparator() + table.AddRow("END PORT", securityGroupRule.PortRange.Max) + table.AddSeparator() } if securityGroupRule.Ethertype != nil { diff --git a/internal/cmd/security-group/rule/describe/describe_test.go b/internal/cmd/security-group/rule/describe/describe_test.go index bf5780214..445338cb6 100644 --- a/internal/cmd/security-group/rule/describe/describe_test.go +++ b/internal/cmd/security-group/rule/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testSecurityGroupId = uuid.NewString() var testSecurityGroupRuleId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetSecurityGroupRuleRequest)) iaas.ApiGetSecurityGroupRuleRequest { - request := testClient.GetSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId, testSecurityGroupRuleId) + request := testClient.DefaultAPI.GetSecurityGroupRule(testCtx, testProjectId, testRegion, testSecurityGroupId, testSecurityGroupRuleId) for _, mod := range mods { mod(&request) } @@ -194,7 +194,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/security-group/rule/list/list.go b/internal/cmd/security-group/rule/list/list.go index b552a1e73..f357d01c3 100644 --- a/internal/cmd/security-group/rule/list/list.go +++ b/internal/cmd/security-group/rule/list/list.go @@ -19,7 +19,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -76,7 +76,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { items := resp.GetItems() - securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get security group name: %v", err) securityGroupLabel = model.SecurityGroupId @@ -133,7 +133,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListSecurityGroupRulesRequest { - return apiClient.ListSecurityGroupRules(ctx, model.ProjectId, model.Region, model.SecurityGroupId) + return apiClient.DefaultAPI.ListSecurityGroupRules(ctx, model.ProjectId, model.Region, model.SecurityGroupId) } func outputResult(p *print.Printer, outputFormat, projectLabel, securityGroupLabel string, securityGroupRules []iaas.SecurityGroupRule) error { @@ -158,7 +158,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel, securityGroupLab table.AddRow( utils.PtrString(securityGroupRule.Id), etherType, - utils.PtrString(securityGroupRule.Direction), + securityGroupRule.Direction, protocolName, utils.PtrString(securityGroupRule.RemoteSecurityGroupId), ) diff --git a/internal/cmd/security-group/rule/list/list_test.go b/internal/cmd/security-group/rule/list/list_test.go index 8833b4ae7..1f3c7de50 100644 --- a/internal/cmd/security-group/rule/list/list_test.go +++ b/internal/cmd/security-group/rule/list/list_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testSecurityGroupId = uuid.NewString() @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListSecurityGroupRulesRequest)) iaas.ApiListSecurityGroupRulesRequest { - request := testClient.ListSecurityGroupRules(testCtx, testProjectId, testRegion, testSecurityGroupId) + request := testClient.DefaultAPI.ListSecurityGroupRules(testCtx, testProjectId, testRegion, testSecurityGroupId) for _, mod := range mods { mod(&request) } @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/security-group/update/update.go b/internal/cmd/security-group/update/update.go index d73590631..c62db431f 100644 --- a/internal/cmd/security-group/update/update.go +++ b/internal/cmd/security-group/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -23,7 +23,7 @@ import ( type inputModel struct { *globalflags.GlobalFlagModel - Labels *map[string]string + Labels map[string]any Description *string Name *string SecurityGroupId string @@ -66,7 +66,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { projectLabel = model.ProjectId } - groupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + groupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Warn("cannot retrieve groupname: %v", err) groupLabel = model.SecurityGroupId @@ -85,7 +85,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("update security group: %w", err) } - params.Printer.Info("Updated security group \"%v\" for %q\n", utils.PtrString(resp.Name), projectLabel) + params.Printer.Info("Updated security group \"%v\" for %q\n", resp.Name, projectLabel) return nil }, @@ -109,7 +109,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM model := inputModel{ GlobalFlagModel: globalFlags, - Labels: flags.FlagToStringToStringPointer(p, cmd, labelsArg), + Labels: flags.FlagToStringToAny(p, cmd, labelsArg), Description: flags.FlagToStringPointer(p, cmd, descriptionArg), Name: flags.FlagToStringPointer(p, cmd, nameArg), SecurityGroupId: cliArgs[0], @@ -124,10 +124,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateSecurityGroupRequest { - request := apiClient.UpdateSecurityGroup(ctx, model.ProjectId, model.Region, model.SecurityGroupId) + request := apiClient.DefaultAPI.UpdateSecurityGroup(ctx, model.ProjectId, model.Region, model.SecurityGroupId) payload := iaas.NewUpdateSecurityGroupPayload() payload.Description = model.Description - payload.Labels = utils.ConvertStringMapToInterfaceMap(model.Labels) + payload.Labels = model.Labels payload.Name = model.Name request = request.UpdateSecurityGroupPayload(*payload) diff --git a/internal/cmd/security-group/update/update_test.go b/internal/cmd/security-group/update/update_test.go index afd0d2dbe..1b5324968 100644 --- a/internal/cmd/security-group/update/update_test.go +++ b/internal/cmd/security-group/update/update_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" ) const ( @@ -22,29 +21,18 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testGroupId = []string{uuid.NewString()} testName = "new-security-group" testDescription = "a test description" - testLabels = map[string]string{ + testLabels = map[string]any{ "fooKey": "fooValue", "barKey": "barValue", "bazKey": "bazValue", } ) -func toStringAnyMapPtr(m map[string]string) map[string]any { - if m == nil { - return nil - } - result := map[string]any{} - for k, v := range m { - result[k] = v - } - return result -} - func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ globalflags.ProjectIdFlag: testProjectId, @@ -67,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, - Labels: &testLabels, + Labels: testLabels, Description: &testDescription, Name: &testName, SecurityGroupId: testGroupId[0], @@ -79,10 +67,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateSecurityGroupRequest)) iaas.ApiUpdateSecurityGroupRequest { - request := testClient.UpdateSecurityGroup(testCtx, testProjectId, testRegion, testGroupId[0]) + request := testClient.DefaultAPI.UpdateSecurityGroup(testCtx, testProjectId, testRegion, testGroupId[0]) request = request.UpdateSecurityGroupPayload(iaas.UpdateSecurityGroupPayload{ Description: &testDescription, - Labels: utils.Ptr(toStringAnyMapPtr(testLabels)), + Labels: testLabels, Name: &testName, }) for _, mod := range mods { @@ -185,7 +173,7 @@ func TestParseInput(t *testing.T) { args: testGroupId, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = &map[string]string{ + model.Labels = map[string]any{ "foo": "bar", } }), @@ -276,7 +264,7 @@ func TestBuildRequest(t *testing.T) { model.Labels = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiUpdateSecurityGroupRequest) { - *request = (*request).UpdateSecurityGroupPayload(iaas.UpdateSecurityGroupPayload{ + *request = request.UpdateSecurityGroupPayload(iaas.UpdateSecurityGroupPayload{ Description: &testDescription, Labels: nil, Name: &testName, @@ -290,7 +278,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/backup/create/create.go b/internal/cmd/server/backup/create/create.go index 50b36dce4..98318ae47 100644 --- a/internal/cmd/server/backup/create/create.go +++ b/internal/cmd/server/backup/create/create.go @@ -71,7 +71,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/backup/disable/disable.go b/internal/cmd/server/backup/disable/disable.go index 4aecf6553..83ffbc08c 100644 --- a/internal/cmd/server/backup/disable/disable.go +++ b/internal/cmd/server/backup/disable/disable.go @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/backup/enable/enable.go b/internal/cmd/server/backup/enable/enable.go index 7f6854be3..b2f51fc87 100644 --- a/internal/cmd/server/backup/enable/enable.go +++ b/internal/cmd/server/backup/enable/enable.go @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/backup/list/list.go b/internal/cmd/server/backup/list/list.go index c8b99bcb7..23196666d 100644 --- a/internal/cmd/server/backup/list/list.go +++ b/internal/cmd/server/backup/list/list.go @@ -72,7 +72,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Get server name serverLabel := model.ServerId if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/backup/schedule/create/create.go b/internal/cmd/server/backup/schedule/create/create.go index 6b722c0b0..9ab3a6098 100644 --- a/internal/cmd/server/backup/schedule/create/create.go +++ b/internal/cmd/server/backup/schedule/create/create.go @@ -79,7 +79,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/backup/schedule/delete/delete.go b/internal/cmd/server/backup/schedule/delete/delete.go index 42e4c07ef..c0584eefa 100644 --- a/internal/cmd/server/backup/schedule/delete/delete.go +++ b/internal/cmd/server/backup/schedule/delete/delete.go @@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/backup/schedule/list/list.go b/internal/cmd/server/backup/schedule/list/list.go index b9481b506..c04b2628c 100644 --- a/internal/cmd/server/backup/schedule/list/list.go +++ b/internal/cmd/server/backup/schedule/list/list.go @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/command/create/create.go b/internal/cmd/server/command/create/create.go index 9259e3046..924a53fcb 100644 --- a/internal/cmd/server/command/create/create.go +++ b/internal/cmd/server/command/create/create.go @@ -68,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/command/list/list.go b/internal/cmd/server/command/list/list.go index 3072a18f5..8d5e1cb77 100644 --- a/internal/cmd/server/command/list/list.go +++ b/internal/cmd/server/command/list/list.go @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/console/console.go b/internal/cmd/server/console/console.go index 48e061615..3fb53c919 100644 --- a/internal/cmd/server/console/console.go +++ b/internal/cmd/server/console/console.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -59,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return fmt.Errorf("server console: %w", err) } - return outputResult(params.Printer, model.OutputFormat, serverLabel, *resp) + return outputResult(params.Printer, model.OutputFormat, serverLabel, resp) }, } return cmd @@ -98,10 +98,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetServerConsoleRequest { - return apiClient.GetServerConsole(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.GetServerConsole(ctx, model.ProjectId, model.Region, model.ServerId) } -func outputResult(p *print.Printer, outputFormat, serverLabel string, serverUrl iaas.ServerConsoleUrl) error { +func outputResult(p *print.Printer, outputFormat, serverLabel string, serverUrl *iaas.ServerConsoleUrl) error { return p.OutputResult(outputFormat, serverUrl, func() error { if _, ok := serverUrl.GetUrlOk(); !ok { return fmt.Errorf("server url is nil") diff --git a/internal/cmd/server/console/console_test.go b/internal/cmd/server/console/console_test.go index bad03b81d..3a49d0002 100644 --- a/internal/cmd/server/console/console_test.go +++ b/internal/cmd/server/console/console_test.go @@ -4,15 +4,14 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" - "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" + "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" ) const ( @@ -22,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -63,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetServerConsoleRequest)) iaas.ApiGetServerConsoleRequest { - request := testClient.GetServerConsole(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.GetServerConsole(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -157,7 +156,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -169,7 +168,7 @@ func TestBuildRequest(t *testing.T) { func TestOutputResult(t *testing.T) { type args struct { outputFormat, serverLabel string - serverUrl iaas.ServerConsoleUrl + serverUrl *iaas.ServerConsoleUrl } tests := []struct { name string @@ -184,8 +183,8 @@ func TestOutputResult(t *testing.T) { { name: "set server url", args: args{ - serverUrl: iaas.ServerConsoleUrl{ - Url: utils.Ptr(""), + serverUrl: &iaas.ServerConsoleUrl{ + Url: "", }, }, wantErr: false, diff --git a/internal/cmd/server/create/create.go b/internal/cmd/server/create/create.go index 5960a6bb7..0f7e68f33 100644 --- a/internal/cmd/server/create/create.go +++ b/internal/cmd/server/create/create.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -47,25 +47,25 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Name *string - MachineType *string + Name string + MachineType string AffinityGroup *string AvailabilityZone *string AgentProvisioningPolicy *string - BootVolumeSourceId *string - BootVolumeSourceType *string + BootVolumeSourceId string + BootVolumeSourceType string BootVolumeSize *int64 BootVolumePerformanceClass *string BootVolumeDeleteOnTermination *bool ImageId *string KeypairName *string - Labels *map[string]string + Labels map[string]any NetworkId *string - NetworkInterfaceIds *[]string - SecurityGroups *[]string - ServiceAccountMails *[]string + NetworkInterfaceIds []string + SecurityGroups []string + ServiceAccountMails []string UserData *string - Volumes *[]string + Volumes []string } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -152,7 +152,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Creating server", func() error { - _, err = wait.CreateServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, serverId).WaitWithContext(ctx) + _, err = wait.CreateServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, serverId).WaitWithContext(ctx) return err }) if err != nil { @@ -254,25 +254,25 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, - Name: flags.FlagToStringPointer(p, cmd, nameFlag), - MachineType: flags.FlagToStringPointer(p, cmd, machineTypeFlag), + Name: flags.FlagToStringValue(p, cmd, nameFlag), + MachineType: flags.FlagToStringValue(p, cmd, machineTypeFlag), AffinityGroup: flags.FlagToStringPointer(p, cmd, affinityGroupFlag), AvailabilityZone: flags.FlagToStringPointer(p, cmd, availabilityZoneFlag), AgentProvisioningPolicy: flags.FlagToStringPointer(p, cmd, agentProvisioningPolicyFlag), - BootVolumeSourceId: flags.FlagToStringPointer(p, cmd, bootVolumeSourceIdFlag), - BootVolumeSourceType: flags.FlagToStringPointer(p, cmd, bootVolumeSourceTypeFlag), + BootVolumeSourceId: flags.FlagToStringValue(p, cmd, bootVolumeSourceIdFlag), + BootVolumeSourceType: flags.FlagToStringValue(p, cmd, bootVolumeSourceTypeFlag), BootVolumeSize: flags.FlagToInt64Pointer(p, cmd, bootVolumeSizeFlag), BootVolumePerformanceClass: flags.FlagToStringPointer(p, cmd, bootVolumePerformanceClassFlag), BootVolumeDeleteOnTermination: flags.FlagToBoolPointer(p, cmd, bootVolumeDeleteOnTerminationFlag), ImageId: flags.FlagToStringPointer(p, cmd, imageIdFlag), KeypairName: flags.FlagToStringPointer(p, cmd, keypairNameFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), NetworkId: flags.FlagToStringPointer(p, cmd, networkIdFlag), - NetworkInterfaceIds: flags.FlagToStringSlicePointer(p, cmd, networkInterfaceIdsFlag), - SecurityGroups: flags.FlagToStringSlicePointer(p, cmd, securityGroupsFlag), - ServiceAccountMails: flags.FlagToStringSlicePointer(p, cmd, serviceAccountEmailsFlag), + NetworkInterfaceIds: flags.FlagToStringSliceValue(p, cmd, networkInterfaceIdsFlag), + SecurityGroups: flags.FlagToStringSliceValue(p, cmd, securityGroupsFlag), + ServiceAccountMails: flags.FlagToStringSliceValue(p, cmd, serviceAccountEmailsFlag), UserData: flags.FlagToStringPointer(p, cmd, userDataFlag), - Volumes: flags.FlagToStringSlicePointer(p, cmd, volumesFlag), + Volumes: flags.FlagToStringSliceValue(p, cmd, volumesFlag), } p.DebugInputModel(model) @@ -280,12 +280,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateServerRequest { - req := apiClient.CreateServer(ctx, model.ProjectId, model.Region) - - var userData *[]byte - if model.UserData != nil { - userData = utils.Ptr([]byte(*model.UserData)) - } + req := apiClient.DefaultAPI.CreateServer(ctx, model.ProjectId, model.Region) payload := iaas.CreateServerPayload{ Name: model.Name, @@ -297,9 +292,9 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli KeypairName: model.KeypairName, SecurityGroups: model.SecurityGroups, ServiceAccountMails: model.ServiceAccountMails, - UserData: userData, + UserData: model.UserData, Volumes: model.Volumes, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } if model.AgentProvisioningPolicy != nil { @@ -311,8 +306,8 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli } } - if model.BootVolumePerformanceClass != nil || model.BootVolumeSize != nil || model.BootVolumeDeleteOnTermination != nil || model.BootVolumeSourceId != nil || model.BootVolumeSourceType != nil { - payload.BootVolume = &iaas.ServerBootVolume{ + if model.BootVolumePerformanceClass != nil || model.BootVolumeSize != nil || model.BootVolumeDeleteOnTermination != nil { + payload.BootVolume = &iaas.BootVolume{ PerformanceClass: model.BootVolumePerformanceClass, Size: model.BootVolumeSize, DeleteOnTermination: model.BootVolumeDeleteOnTermination, @@ -324,7 +319,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli } if model.NetworkInterfaceIds != nil || model.NetworkId != nil { - payload.Networking = &iaas.CreateServerPayloadAllOfNetworking{} + payload.Networking = iaas.CreateServerPayloadAllOfNetworking{} if model.NetworkInterfaceIds != nil { payload.Networking.CreateServerNetworkingWithNics = &iaas.CreateServerNetworkingWithNics{ diff --git a/internal/cmd/server/create/create_test.go b/internal/cmd/server/create/create_test.go index d28ea513a..a554eb508 100644 --- a/internal/cmd/server/create/create_test.go +++ b/internal/cmd/server/create/create_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testSourceId = uuid.NewString() @@ -68,23 +68,23 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, AgentProvisioningPolicy: utils.Ptr("INHERIT"), AvailabilityZone: utils.Ptr("eu01-1"), - Name: utils.Ptr("test-server-name"), - MachineType: utils.Ptr("t1.1"), + Name: "test-server-name", + MachineType: "t1.1", AffinityGroup: utils.Ptr("test-affinity-group"), BootVolumePerformanceClass: utils.Ptr("test-perf-class"), BootVolumeSize: utils.Ptr(int64(5)), - BootVolumeSourceId: utils.Ptr(testSourceId), - BootVolumeSourceType: utils.Ptr("test-source-type"), + BootVolumeSourceId: testSourceId, + BootVolumeSourceType: "test-source-type", BootVolumeDeleteOnTermination: utils.Ptr(false), KeypairName: utils.Ptr("test-keypair-name"), NetworkId: utils.Ptr(testNetworkId), - SecurityGroups: utils.Ptr([]string{"test-security-groups"}), - ServiceAccountMails: utils.Ptr([]string{"test-service-account"}), + SecurityGroups: []string{"test-security-groups"}, + ServiceAccountMails: []string{"test-service-account"}, UserData: utils.Ptr("test-user-data"), - Volumes: utils.Ptr([]string{testVolumeId}), - Labels: utils.Ptr(map[string]string{ + Volumes: []string{testVolumeId}, + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -93,7 +93,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateServerRequest)) iaas.ApiCreateServerRequest { - request := testClient.CreateServer(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateServer(testCtx, testProjectId, testRegion) request = request.CreateServerPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -102,10 +102,10 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateServerRequest)) iaas.Api } func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateServerRequest)) iaas.ApiCreateServerRequest { - request := testClient.CreateServer(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateServer(testCtx, testProjectId, testRegion) request = request.CreateServerPayload(iaas.CreateServerPayload{ - MachineType: utils.Ptr("t1.1"), - Name: utils.Ptr("test-server-name"), + MachineType: "t1.1", + Name: "test-server-name", }) for _, mod := range mods { mod(&request) @@ -115,28 +115,28 @@ func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateServerRequest)) func fixturePayload(mods ...func(payload *iaas.CreateServerPayload)) iaas.CreateServerPayload { payload := iaas.CreateServerPayload{ - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), - MachineType: utils.Ptr("t1.1"), - Name: utils.Ptr("test-server-name"), + }, + MachineType: "t1.1", + Name: "test-server-name", AvailabilityZone: utils.Ptr("eu01-1"), AffinityGroup: utils.Ptr("test-affinity-group"), KeypairName: utils.Ptr("test-keypair-name"), - SecurityGroups: utils.Ptr([]string{"test-security-groups"}), - ServiceAccountMails: utils.Ptr([]string{"test-service-account"}), - UserData: utils.Ptr([]byte("test-user-data")), - Volumes: utils.Ptr([]string{testVolumeId}), - BootVolume: &iaas.ServerBootVolume{ + SecurityGroups: []string{"test-security-groups"}, + ServiceAccountMails: []string{"test-service-account"}, + UserData: utils.Ptr("test-user-data"), + Volumes: []string{testVolumeId}, + BootVolume: &iaas.BootVolume{ PerformanceClass: utils.Ptr("test-perf-class"), Size: utils.Ptr(int64(5)), DeleteOnTermination: utils.Ptr(false), Source: &iaas.BootVolumeSource{ - Id: utils.Ptr(testSourceId), - Type: utils.Ptr("test-source-type"), + Id: testSourceId, + Type: "test-source-type", }, }, - Networking: &iaas.CreateServerPayloadAllOfNetworking{ + Networking: iaas.CreateServerPayloadAllOfNetworking{ CreateServerNetworking: &iaas.CreateServerNetworking{ NetworkId: utils.Ptr(testNetworkId), }, @@ -188,8 +188,8 @@ func TestParseInput(t *testing.T) { model.AgentProvisioningPolicy = nil model.AvailabilityZone = nil model.Labels = nil - model.BootVolumeSourceId = nil - model.BootVolumeSourceType = nil + model.BootVolumeSourceId = "" + model.BootVolumeSourceType = "" model.BootVolumeSize = nil model.BootVolumePerformanceClass = nil model.BootVolumeDeleteOnTermination = nil @@ -252,8 +252,8 @@ func TestParseInput(t *testing.T) { isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { model.NetworkId = utils.Ptr(testNetworkId) - model.Name = utils.Ptr("test-server-name") - model.MachineType = utils.Ptr("t1.1") + model.Name = "test-server-name" + model.MachineType = "t1.1" }), }, { @@ -264,8 +264,8 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.BootVolumeSourceId = utils.Ptr(testImageId) - model.BootVolumeSourceType = utils.Ptr("image") + model.BootVolumeSourceId = testImageId + model.BootVolumeSourceType = "image" }), }, { @@ -303,8 +303,8 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.BootVolumeSourceId = nil - model.BootVolumeSourceType = nil + model.BootVolumeSourceId = "" + model.BootVolumeSourceType = "" model.BootVolumeSize = nil model.ImageId = utils.Ptr(testImageId) }), @@ -379,8 +379,8 @@ func TestBuildRequest(t *testing.T) { Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, - MachineType: utils.Ptr("t1.1"), - Name: utils.Ptr("test-server-name"), + MachineType: "t1.1", + Name: "test-server-name", }, expectedRequest: fixtureRequiredRequest(), }, @@ -394,7 +394,7 @@ func TestBuildRequest(t *testing.T) { payload.Agent = &iaas.ServerAgent{ Provisioned: utils.Ptr(true), } - *request = (*request).CreateServerPayload(payload) + *request = request.CreateServerPayload(payload) }), }, } @@ -405,7 +405,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/deallocate/deallocate.go b/internal/cmd/server/deallocate/deallocate.go index 41886042d..d6f710e29 100644 --- a/internal/cmd/server/deallocate/deallocate.go +++ b/internal/cmd/server/deallocate/deallocate.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -80,7 +80,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Deallocating server", func() error { - _, err = wait.DeallocateServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.DeallocateServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -118,5 +118,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeallocateServerRequest { - return apiClient.DeallocateServer(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.DeallocateServer(ctx, model.ProjectId, model.Region, model.ServerId) } diff --git a/internal/cmd/server/deallocate/deallocate_test.go b/internal/cmd/server/deallocate/deallocate_test.go index efb00e27f..5e882a1b7 100644 --- a/internal/cmd/server/deallocate/deallocate_test.go +++ b/internal/cmd/server/deallocate/deallocate_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeallocateServerRequest)) iaas.ApiDeallocateServerRequest { - request := testClient.DeallocateServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.DeallocateServer(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -155,7 +155,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/delete/delete.go b/internal/cmd/server/delete/delete.go index cbedd5a29..d09e219aa 100644 --- a/internal/cmd/server/delete/delete.go +++ b/internal/cmd/server/delete/delete.go @@ -4,12 +4,12 @@ import ( "context" "fmt" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -59,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -83,7 +83,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Deleting server", func() error { - _, err = wait.DeleteServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.DeleteServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -120,5 +120,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteServerRequest { - return apiClient.DeleteServer(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.DeleteServer(ctx, model.ProjectId, model.Region, model.ServerId) } diff --git a/internal/cmd/server/delete/delete_test.go b/internal/cmd/server/delete/delete_test.go index 9534c8b22..e7a01ccaf 100644 --- a/internal/cmd/server/delete/delete_test.go +++ b/internal/cmd/server/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testServerId = uuid.NewString() var testProjectId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteServerRequest)) iaas.ApiDeleteServerRequest { - request := testClient.DeleteServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.DeleteServer(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -165,7 +165,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/describe/describe.go b/internal/cmd/server/describe/describe.go index 3d77219b5..c9f77db0f 100644 --- a/internal/cmd/server/describe/describe.go +++ b/internal/cmd/server/describe/describe.go @@ -19,7 +19,7 @@ import ( "github.com/goccy/go-yaml" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -91,7 +91,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetServerRequest { - req := apiClient.GetServer(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.GetServer(ctx, model.ProjectId, model.Region, model.ServerId) req = req.Details(true) return req @@ -131,7 +131,7 @@ func outputResult(p *print.Printer, outputFormat string, server *iaas.Server) er table.AddRow("ID", utils.PtrString(server.Id)) table.AddSeparator() - table.AddRow("NAME", utils.PtrString(server.Name)) + table.AddRow("NAME", server.Name) table.AddSeparator() table.AddRow("STATE", utils.PtrString(server.Status)) table.AddSeparator() @@ -166,44 +166,42 @@ func outputResult(p *print.Printer, outputFormat string, server *iaas.Server) er table.AddSeparator() } - if server.MachineType != nil { - table.AddRow("MACHINE TYPE", *server.MachineType) - table.AddSeparator() - } + table.AddRow("MACHINE TYPE", server.MachineType) + table.AddSeparator() - if server.Labels != nil && len(*server.Labels) > 0 { + if server.Labels != nil && len(server.Labels) > 0 { labels := []string{} - for key, value := range *server.Labels { + for key, value := range server.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) table.AddSeparator() } - if server.ServiceAccountMails != nil && len(*server.ServiceAccountMails) > 0 { - table.AddRow("SERVICE ACCOUNTS", strings.Join(*server.ServiceAccountMails, "\n")) + if len(server.ServiceAccountMails) > 0 { + table.AddRow("SERVICE ACCOUNTS", strings.Join(server.ServiceAccountMails, "\n")) table.AddSeparator() } - if server.Volumes != nil && len(*server.Volumes) > 0 { + if len(server.Volumes) > 0 { volumes := []string{} - volumes = append(volumes, *server.Volumes...) + volumes = append(volumes, server.Volumes...) table.AddRow("VOLUMES", strings.Join(volumes, "\n")) table.AddSeparator() } content = append(content, table) - if server.Nics != nil && len(*server.Nics) > 0 { + if server.Nics != nil && len(server.Nics) > 0 { nicsTable := tables.NewTable() nicsTable.SetTitle("Attached Network Interfaces") nicsTable.SetHeader("ID", "NETWORK ID", "NETWORK NAME", "IPv4", "PUBLIC IP") - for _, nic := range *server.Nics { + for _, nic := range server.Nics { nicsTable.AddRow( - utils.PtrString(nic.NicId), - utils.PtrString(nic.NetworkId), - utils.PtrString(nic.NetworkName), + nic.NicId, + nic.NetworkId, + nic.NetworkName, utils.PtrString(nic.Ipv4), utils.PtrString(nic.PublicIp), ) @@ -217,28 +215,23 @@ func outputResult(p *print.Printer, outputFormat string, server *iaas.Server) er maintenanceWindow := tables.NewTable() maintenanceWindow.SetTitle("Maintenance Window") - if server.MaintenanceWindow.Status != nil { - maintenanceWindow.AddRow("STATUS", *server.MaintenanceWindow.Status) - maintenanceWindow.AddSeparator() - } + maintenanceWindow.AddRow("STATUS", server.MaintenanceWindow.Status) + maintenanceWindow.AddSeparator() + if server.MaintenanceWindow.Details != nil { maintenanceWindow.AddRow("DETAILS", *server.MaintenanceWindow.Details) maintenanceWindow.AddSeparator() } - if server.MaintenanceWindow.StartsAt != nil { - maintenanceWindow.AddRow( - "STARTS AT", - utils.ConvertTimePToDateTimeString(server.MaintenanceWindow.StartsAt), - ) - maintenanceWindow.AddSeparator() - } - if server.MaintenanceWindow.EndsAt != nil { - maintenanceWindow.AddRow( - "ENDS AT", - utils.ConvertTimePToDateTimeString(server.MaintenanceWindow.EndsAt), - ) - maintenanceWindow.AddSeparator() - } + maintenanceWindow.AddRow( + "STARTS AT", + utils.ConvertTimePToDateTimeString(&server.MaintenanceWindow.StartsAt), + ) + maintenanceWindow.AddSeparator() + maintenanceWindow.AddRow( + "ENDS AT", + utils.ConvertTimePToDateTimeString(&server.MaintenanceWindow.EndsAt), + ) + maintenanceWindow.AddSeparator() content = append(content, maintenanceWindow) } diff --git a/internal/cmd/server/describe/describe_test.go b/internal/cmd/server/describe/describe_test.go index db84e30f2..80f4be4c9 100644 --- a/internal/cmd/server/describe/describe_test.go +++ b/internal/cmd/server/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetServerRequest)) iaas.ApiGetServerRequest { - request := testClient.GetServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.GetServer(testCtx, testProjectId, testRegion, testServerId) request = request.Details(true) for _, mod := range mods { mod(&request) @@ -167,7 +167,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/list/list.go b/internal/cmd/server/list/list.go index 988654de4..6bf36485c 100644 --- a/internal/cmd/server/list/list.go +++ b/internal/cmd/server/list/list.go @@ -20,7 +20,7 @@ import ( "github.com/goccy/go-yaml" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -128,7 +128,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListServersRequest { - req := apiClient.ListServers(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListServers(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -173,13 +173,13 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, servers [ nicIPv4 := "" publicIPs := "" - if server.Nics != nil && len(*server.Nics) > 0 { - for i, nic := range *server.Nics { + if len(server.Nics) > 0 { + for i, nic := range server.Nics { if nic.Ipv4 != nil || nic.PublicIp != nil { nicIPv4 += utils.PtrString(nic.Ipv4) publicIPs += utils.PtrString(nic.PublicIp) - if i != len(*server.Nics)-1 { + if i != len(server.Nics)-1 { publicIPs += "\n" nicIPv4 += "\n" } @@ -194,9 +194,9 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, servers [ table.AddRow( utils.PtrString(server.Id), - utils.PtrString(server.Name), + server.Name, utils.PtrString(server.Status), - utils.PtrString(server.MachineType), + server.MachineType, utils.PtrString(server.AvailabilityZone), nicIPv4, publicIPs, diff --git a/internal/cmd/server/list/list_test.go b/internal/cmd/server/list/list_test.go index 22f3285d5..13eda55f4 100644 --- a/internal/cmd/server/list/list_test.go +++ b/internal/cmd/server/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testLabelSelector = "label" @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListServersRequest)) iaas.ApiListServersRequest { - request := testClient.ListServers(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListServers(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabelSelector) request = request.Details(true) for _, mod := range mods { @@ -163,7 +163,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/log/log.go b/internal/cmd/server/log/log.go index 086e228b4..da9d90a9a 100644 --- a/internal/cmd/server/log/log.go +++ b/internal/cmd/server/log/log.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -68,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -130,7 +130,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetServerLogRequest { - return apiClient.GetServerLog(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.GetServerLog(ctx, model.ProjectId, model.Region, model.ServerId) } func outputResult(p *print.Printer, outputFormat, serverLabel, log string) error { diff --git a/internal/cmd/server/log/log_test.go b/internal/cmd/server/log/log_test.go index 93b7750c6..62232e266 100644 --- a/internal/cmd/server/log/log_test.go +++ b/internal/cmd/server/log/log_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetServerLogRequest)) iaas.ApiGetServerLogRequest { - request := testClient.GetServerLog(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.GetServerLog(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -171,7 +171,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/machine-type/describe/describe.go b/internal/cmd/server/machine-type/describe/describe.go index 4bd07771e..92ba40cde 100644 --- a/internal/cmd/server/machine-type/describe/describe.go +++ b/internal/cmd/server/machine-type/describe/describe.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -89,7 +89,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetMachineTypeRequest { - return apiClient.GetMachineType(ctx, model.ProjectId, model.Region, model.MachineType) + return apiClient.DefaultAPI.GetMachineType(ctx, model.ProjectId, model.Region, model.MachineType) } func outputResult(p *print.Printer, outputFormat string, machineType *iaas.MachineType) error { @@ -98,13 +98,13 @@ func outputResult(p *print.Printer, outputFormat string, machineType *iaas.Machi } return p.OutputResult(outputFormat, machineType, func() error { table := tables.NewTable() - table.AddRow("NAME", utils.PtrString(machineType.Name)) + table.AddRow("NAME", machineType.Name) table.AddSeparator() - table.AddRow("VCPUS", utils.PtrString(machineType.Vcpus)) + table.AddRow("VCPUS", machineType.Vcpus) table.AddSeparator() - table.AddRow("RAM (in MB)", utils.PtrString(machineType.Ram)) + table.AddRow("RAM (in MB)", machineType.Ram) table.AddSeparator() - table.AddRow("DISK SIZE (in GB)", utils.PtrString(machineType.Disk)) + table.AddRow("DISK SIZE (in GB)", machineType.Disk) table.AddSeparator() table.AddRow("DESCRIPTION", utils.PtrString(machineType.Description)) table.AddSeparator() diff --git a/internal/cmd/server/machine-type/describe/describe_test.go b/internal/cmd/server/machine-type/describe/describe_test.go index 982967d3b..01f52cf5a 100644 --- a/internal/cmd/server/machine-type/describe/describe_test.go +++ b/internal/cmd/server/machine-type/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testMachineType = "t1.1" @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetMachineTypeRequest)) iaas.ApiGetMachineTypeRequest { - request := testClient.GetMachineType(testCtx, testProjectId, testRegion, testMachineType) + request := testClient.DefaultAPI.GetMachineType(testCtx, testProjectId, testRegion, testMachineType) for _, mod := range mods { mod(&request) } @@ -154,7 +154,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/machine-type/list/list.go b/internal/cmd/server/machine-type/list/list.go index 1ead9fea7..0f5cd707c 100644 --- a/internal/cmd/server/machine-type/list/list.go +++ b/internal/cmd/server/machine-type/list/list.go @@ -18,7 +18,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) type inputModel struct { @@ -87,8 +87,8 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // limit output - if model.Limit != nil && len(*resp.Items) > int(*model.Limit) { - *resp.Items = (*resp.Items)[:*model.Limit] + if model.Limit != nil && len(resp.Items) > int(*model.Limit) { + resp.Items = (resp.Items)[:*model.Limit] } return outputResult(params.Printer, model.OutputFormat, projectLabel, *resp) @@ -129,7 +129,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListMachineTypesRequest { - req := apiClient.ListMachineTypes(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListMachineTypes(ctx, model.ProjectId, model.Region) if model.Filter != nil { req = req.Filter(*model.Filter) } @@ -138,7 +138,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli func outputResult(p *print.Printer, outputFormat, projectLabel string, machineTypes iaas.MachineTypeListResponse) error { return p.OutputResult(outputFormat, machineTypes, func() error { - if machineTypes.Items == nil || len(*machineTypes.Items) == 0 { + if len(machineTypes.Items) == 0 { p.Outputf("No machine-types found for project %q\n", projectLabel) return nil } @@ -148,19 +148,16 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, machineTy if items := machineTypes.GetItems(); len(items) > 0 { for _, machineType := range items { extraSpecMap := make(map[string]string) - if machineType.ExtraSpecs != nil && len(*machineType.ExtraSpecs) > 0 { - for key, value := range *machineType.ExtraSpecs { + if len(machineType.ExtraSpecs) > 0 { + for key, value := range machineType.ExtraSpecs { extraSpecMap[key] = fmt.Sprintf("%v", value) } } - ramGB := int64(0) - if machineType.Ram != nil { - ramGB = *machineType.Ram / 1024 - } + ramGB := machineType.Ram / 1024 table.AddRow( - utils.PtrString(machineType.Name), - utils.PtrValue(machineType.Vcpus), + machineType.Name, + machineType.Vcpus, ramGB, utils.PtrString(machineType.Description), utils.JoinStringMap(extraSpecMap, ": ", "\n"), diff --git a/internal/cmd/server/machine-type/list/list_test.go b/internal/cmd/server/machine-type/list/list_test.go index 23913272f..4f1b707cc 100644 --- a/internal/cmd/server/machine-type/list/list_test.go +++ b/internal/cmd/server/machine-type/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -54,7 +54,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListMachineTypesRequest)) iaas.ApiListMachineTypesRequest { - request := testClient.ListMachineTypes(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListMachineTypes(testCtx, testProjectId, testRegion) for _, mod := range mods { mod(&request) } @@ -156,7 +156,7 @@ func TestBuildRequest(t *testing.T) { model.Filter = utils.Ptr("vcpus==2") }), expectedRequest: fixtureRequest(func(request *iaas.ApiListMachineTypesRequest) { - *request = (*request).Filter("vcpus==2") + *request = request.Filter("vcpus==2") }), }, } @@ -167,7 +167,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -197,20 +197,20 @@ func TestOutputResult(t *testing.T) { args: args{ outputFormat: "table", machineTypes: iaas.MachineTypeListResponse{ - Items: &[]iaas.MachineType{ + Items: []iaas.MachineType{ { - Name: utils.Ptr("c1.2"), - Vcpus: utils.Ptr(int64(2)), - Ram: utils.Ptr(int64(2048)), // Should display as 2 GB + Name: "c1.2", + Vcpus: int64(2), + Ram: int64(2048), // Should display as 2 GB Description: utils.Ptr("Compute optimized 2 vCPU"), - ExtraSpecs: &map[string]interface{}{ + ExtraSpecs: map[string]interface{}{ "cpu": "intel-icelake-generic", }, }, { - Name: utils.Ptr("m1.2"), - Vcpus: utils.Ptr(int64(2)), - Ram: utils.Ptr(int64(8192)), // Should display as 8 GB + Name: "m1.2", + Vcpus: int64(2), + Ram: int64(8192), // Should display as 8 GB Description: utils.Ptr("Memory optimized 2 vCPU"), // No ExtraSpecs provided to test nil safety }, diff --git a/internal/cmd/server/network-interface/attach/attach.go b/internal/cmd/server/network-interface/attach/attach.go index 9d1da9752..582dfbb7c 100644 --- a/internal/cmd/server/network-interface/attach/attach.go +++ b/internal/cmd/server/network-interface/attach/attach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -66,7 +66,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, *model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = *model.ServerId @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // if the create flag is provided a network interface will be created and attached if model.Create != nil && *model.Create { - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, *model.NetworkId) + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.NetworkId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) networkLabel = *model.NetworkId @@ -156,9 +156,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequestAttach(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiAddNicToServerRequest { - return apiClient.AddNicToServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NicId) + return apiClient.DefaultAPI.AddNicToServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NicId) } func buildRequestCreateAndAttach(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiAddNetworkToServerRequest { - return apiClient.AddNetworkToServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NetworkId) + return apiClient.DefaultAPI.AddNetworkToServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NetworkId) } diff --git a/internal/cmd/server/network-interface/attach/attach_test.go b/internal/cmd/server/network-interface/attach/attach_test.go index 6e2898b32..89e90b462 100644 --- a/internal/cmd/server/network-interface/attach/attach_test.go +++ b/internal/cmd/server/network-interface/attach/attach_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testNicId = uuid.NewString() @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequestAttach(mods ...func(request *iaas.ApiAddNicToServerRequest)) iaas.ApiAddNicToServerRequest { - request := testClient.AddNicToServer(testCtx, testProjectId, testRegion, testServerId, testNicId) + request := testClient.DefaultAPI.AddNicToServer(testCtx, testProjectId, testRegion, testServerId, testNicId) for _, mod := range mods { mod(&request) } @@ -67,7 +67,7 @@ func fixtureRequestAttach(mods ...func(request *iaas.ApiAddNicToServerRequest)) } func fixtureRequestCreateAndAttach(mods ...func(request *iaas.ApiAddNetworkToServerRequest)) iaas.ApiAddNetworkToServerRequest { - request := testClient.AddNetworkToServer(testCtx, testProjectId, testRegion, testServerId, testNetworkId) + request := testClient.DefaultAPI.AddNetworkToServer(testCtx, testProjectId, testRegion, testServerId, testNetworkId) for _, mod := range mods { mod(&request) } @@ -228,7 +228,7 @@ func TestBuildRequestAttach(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -260,7 +260,7 @@ func TestBuildRequestCreateAndAttach(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/network-interface/detach/detach.go b/internal/cmd/server/network-interface/detach/detach.go index 41e9cf194..96123ed72 100644 --- a/internal/cmd/server/network-interface/detach/detach.go +++ b/internal/cmd/server/network-interface/detach/detach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -66,7 +66,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, *model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = *model.ServerId @@ -76,7 +76,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // if the delete flag is provided a network interface is detached and deleted if model.Delete != nil && *model.Delete { - networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient, model.ProjectId, model.Region, *model.NetworkId) + networkLabel, err := iaasUtils.GetNetworkName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *model.NetworkId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get network name: %v", err) networkLabel = *model.NetworkId @@ -158,9 +158,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequestDetach(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRemoveNicFromServerRequest { - return apiClient.RemoveNicFromServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NicId) + return apiClient.DefaultAPI.RemoveNicFromServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NicId) } func buildRequestDetachAndDelete(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRemoveNetworkFromServerRequest { - return apiClient.RemoveNetworkFromServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NetworkId) + return apiClient.DefaultAPI.RemoveNetworkFromServer(ctx, model.ProjectId, model.Region, *model.ServerId, *model.NetworkId) } diff --git a/internal/cmd/server/network-interface/detach/detach_test.go b/internal/cmd/server/network-interface/detach/detach_test.go index 4946e3e41..5c2782a19 100644 --- a/internal/cmd/server/network-interface/detach/detach_test.go +++ b/internal/cmd/server/network-interface/detach/detach_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testNicId = uuid.NewString() @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequestDetach(mods ...func(request *iaas.ApiRemoveNicFromServerRequest)) iaas.ApiRemoveNicFromServerRequest { - request := testClient.RemoveNicFromServer(testCtx, testProjectId, testRegion, testServerId, testNicId) + request := testClient.DefaultAPI.RemoveNicFromServer(testCtx, testProjectId, testRegion, testServerId, testNicId) for _, mod := range mods { mod(&request) } @@ -67,7 +67,7 @@ func fixtureRequestDetach(mods ...func(request *iaas.ApiRemoveNicFromServerReque } func fixtureRequestDetachAndDelete(mods ...func(request *iaas.ApiRemoveNetworkFromServerRequest)) iaas.ApiRemoveNetworkFromServerRequest { - request := testClient.RemoveNetworkFromServer(testCtx, testProjectId, testRegion, testServerId, testNetworkId) + request := testClient.DefaultAPI.RemoveNetworkFromServer(testCtx, testProjectId, testRegion, testServerId, testNetworkId) for _, mod := range mods { mod(&request) } @@ -228,7 +228,7 @@ func TestBuildRequestDetach(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) @@ -260,7 +260,7 @@ func TestBuildRequestDetachAndDelete(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/network-interface/list/list.go b/internal/cmd/server/network-interface/list/list.go index 012a359f0..4fa16c117 100644 --- a/internal/cmd/server/network-interface/list/list.go +++ b/internal/cmd/server/network-interface/list/list.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { items := resp.GetItems() - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -127,7 +127,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListServerNICsRequest { - return apiClient.ListServerNICs(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.ListServerNICs(ctx, model.ProjectId, model.Region, model.ServerId) } func outputResult(p *print.Printer, outputFormat, serverId, serverLabel string, serverNics []iaas.NIC) error { diff --git a/internal/cmd/server/network-interface/list/list_test.go b/internal/cmd/server/network-interface/list/list_test.go index 471f19681..424a0f254 100644 --- a/internal/cmd/server/network-interface/list/list_test.go +++ b/internal/cmd/server/network-interface/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListServerNICsRequest)) iaas.ApiListServerNICsRequest { - request := testClient.ListServerNICs(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.ListServerNICs(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -167,7 +167,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/os-update/create/create.go b/internal/cmd/server/os-update/create/create.go index 1d1ad8962..eb0f26614 100644 --- a/internal/cmd/server/os-update/create/create.go +++ b/internal/cmd/server/os-update/create/create.go @@ -66,7 +66,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/os-update/disable/disable.go b/internal/cmd/server/os-update/disable/disable.go index c2a308710..b5e63b750 100644 --- a/internal/cmd/server/os-update/disable/disable.go +++ b/internal/cmd/server/os-update/disable/disable.go @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/os-update/enable/enable.go b/internal/cmd/server/os-update/enable/enable.go index 0d4630c45..b8eba5760 100644 --- a/internal/cmd/server/os-update/enable/enable.go +++ b/internal/cmd/server/os-update/enable/enable.go @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/os-update/list/list.go b/internal/cmd/server/os-update/list/list.go index 93ae13298..6dc0557c5 100644 --- a/internal/cmd/server/os-update/list/list.go +++ b/internal/cmd/server/os-update/list/list.go @@ -72,7 +72,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/os-update/schedule/create/create.go b/internal/cmd/server/os-update/schedule/create/create.go index 421a173c6..b77a50483 100644 --- a/internal/cmd/server/os-update/schedule/create/create.go +++ b/internal/cmd/server/os-update/schedule/create/create.go @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/os-update/schedule/list/list.go b/internal/cmd/server/os-update/schedule/list/list.go index 2a55f845c..7f7f7162a 100644 --- a/internal/cmd/server/os-update/schedule/list/list.go +++ b/internal/cmd/server/os-update/schedule/list/list.go @@ -73,7 +73,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel := model.ServerId // Get server name if iaasApiClient, err := iaasClient.ConfigureClient(params.Printer, params.CliVersion); err == nil { - serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, iaasApiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) } else if serverName != "" { diff --git a/internal/cmd/server/public-ip/attach/attach.go b/internal/cmd/server/public-ip/attach/attach.go index af300bb19..28307f9ea 100644 --- a/internal/cmd/server/public-ip/attach/attach.go +++ b/internal/cmd/server/public-ip/attach/attach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId) + publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.PublicIpId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get public ip name: %v", err) publicIpLabel = model.PublicIpId @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { publicIpLabel = model.PublicIpId } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -118,5 +118,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiAddPublicIpToServerRequest { - return apiClient.AddPublicIpToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.PublicIpId) + return apiClient.DefaultAPI.AddPublicIpToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.PublicIpId) } diff --git a/internal/cmd/server/public-ip/attach/attach_test.go b/internal/cmd/server/public-ip/attach/attach_test.go index 96d4a67fe..fac9945d4 100644 --- a/internal/cmd/server/public-ip/attach/attach_test.go +++ b/internal/cmd/server/public-ip/attach/attach_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testPublicIpId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiAddPublicIpToServerRequest)) iaas.ApiAddPublicIpToServerRequest { - request := testClient.AddPublicIpToServer(testCtx, testProjectId, testRegion, testServerId, testPublicIpId) + request := testClient.DefaultAPI.AddPublicIpToServer(testCtx, testProjectId, testRegion, testServerId, testPublicIpId) for _, mod := range mods { mod(&request) } @@ -222,7 +222,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/public-ip/detach/detach.go b/internal/cmd/server/public-ip/detach/detach.go index 4e53bdf0c..7dabbf5f8 100644 --- a/internal/cmd/server/public-ip/detach/detach.go +++ b/internal/cmd/server/public-ip/detach/detach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.Region, model.PublicIpId) + publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.PublicIpId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get public ip: %v", err) publicIpLabel = model.PublicIpId @@ -65,7 +65,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { publicIpLabel = model.PublicIpId } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -119,5 +119,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRemovePublicIpFromServerRequest { - return apiClient.RemovePublicIpFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.PublicIpId) + return apiClient.DefaultAPI.RemovePublicIpFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.PublicIpId) } diff --git a/internal/cmd/server/public-ip/detach/detach_test.go b/internal/cmd/server/public-ip/detach/detach_test.go index 8fa80ff12..4260b4881 100644 --- a/internal/cmd/server/public-ip/detach/detach_test.go +++ b/internal/cmd/server/public-ip/detach/detach_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testPublicIpId = uuid.NewString() @@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRemovePublicIpFromServerRequest)) iaas.ApiRemovePublicIpFromServerRequest { - request := testClient.RemovePublicIpFromServer(testCtx, testProjectId, testRegion, testServerId, testPublicIpId) + request := testClient.DefaultAPI.RemovePublicIpFromServer(testCtx, testProjectId, testRegion, testServerId, testPublicIpId) for _, mod := range mods { mod(&request) } @@ -220,7 +220,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/reboot/reboot.go b/internal/cmd/server/reboot/reboot.go index fcc57bc08..5b81f4bc6 100644 --- a/internal/cmd/server/reboot/reboot.go +++ b/internal/cmd/server/reboot/reboot.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -64,7 +64,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -116,7 +116,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRebootServerRequest { - req := apiClient.RebootServer(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.RebootServer(ctx, model.ProjectId, model.Region, model.ServerId) // if hard reboot is set the action must be set (soft is default) if model.HardReboot { req = req.Action(hardRebootAction) diff --git a/internal/cmd/server/reboot/reboot_test.go b/internal/cmd/server/reboot/reboot_test.go index 1a05016e1..a6664291b 100644 --- a/internal/cmd/server/reboot/reboot_test.go +++ b/internal/cmd/server/reboot/reboot_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -64,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRebootServerRequest)) iaas.ApiRebootServerRequest { - request := testClient.RebootServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.RebootServer(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -156,7 +156,7 @@ func TestBuildRequest(t *testing.T) { model.HardReboot = true }), expectedRequest: fixtureRequest(func(request *iaas.ApiRebootServerRequest) { - *request = (*request).Action("hard") + *request = request.Action("hard") }), }, } @@ -167,7 +167,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/rescue/rescue.go b/internal/cmd/server/rescue/rescue.go index 9dbd1aa73..363b12a3e 100644 --- a/internal/cmd/server/rescue/rescue.go +++ b/internal/cmd/server/rescue/rescue.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -32,7 +32,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel ServerId string - ImageId *string + ImageId string } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -60,7 +60,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -84,7 +84,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Rescuing server", func() error { - _, err = wait.RescueServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.RescueServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -96,7 +96,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if model.Async { operationState = "Triggered rescue of" } - params.Printer.Info("%s server %q. Image %q is used as temporary boot image\n", operationState, serverLabel, utils.PtrString(model.ImageId)) + params.Printer.Info("%s server %q. Image %q is used as temporary boot image\n", operationState, serverLabel, model.ImageId) return nil }, @@ -123,7 +123,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu model := inputModel{ GlobalFlagModel: globalFlags, ServerId: serverId, - ImageId: flags.FlagToStringPointer(p, cmd, imageIdFlag), + ImageId: flags.FlagToStringValue(p, cmd, imageIdFlag), } p.DebugInputModel(model) @@ -131,7 +131,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRescueServerRequest { - req := apiClient.RescueServer(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.RescueServer(ctx, model.ProjectId, model.Region, model.ServerId) payload := iaas.RescueServerPayload{ Image: model.ImageId, } diff --git a/internal/cmd/server/rescue/rescue_test.go b/internal/cmd/server/rescue/rescue_test.go index b7ec93e90..9a66072f5 100644 --- a/internal/cmd/server/rescue/rescue_test.go +++ b/internal/cmd/server/rescue/rescue_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" ) const ( @@ -21,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testImageId = uuid.NewString() @@ -57,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, }, ServerId: testServerId, - ImageId: utils.Ptr(testImageId), + ImageId: testImageId, } for _, mod := range mods { mod(model) @@ -66,9 +65,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRescueServerRequest)) iaas.ApiRescueServerRequest { - request := testClient.RescueServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.RescueServer(testCtx, testProjectId, testRegion, testServerId) request = request.RescueServerPayload(iaas.RescueServerPayload{ - Image: utils.Ptr(testImageId), + Image: testImageId, }) for _, mod := range mods { mod(&request) @@ -173,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/resize/resize.go b/internal/cmd/server/resize/resize.go index 582341781..b6a7840f3 100644 --- a/internal/cmd/server/resize/resize.go +++ b/internal/cmd/server/resize/resize.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -32,7 +32,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel ServerId string - MachineType *string + MachineType string } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -60,7 +60,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -68,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel = model.ServerId } - prompt := fmt.Sprintf("Are you sure you want to resize server %q to machine type %q?", serverLabel, *model.MachineType) + prompt := fmt.Sprintf("Are you sure you want to resize server %q to machine type %q?", serverLabel, model.MachineType) err = params.Printer.PromptForConfirmation(prompt) if err != nil { return err @@ -84,7 +84,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Resizing server", func() error { - _, err = wait.ResizeServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.ResizeServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -123,7 +123,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu model := inputModel{ GlobalFlagModel: globalFlags, ServerId: serverId, - MachineType: flags.FlagToStringPointer(p, cmd, machineTypeFlag), + MachineType: flags.FlagToStringValue(p, cmd, machineTypeFlag), } p.DebugInputModel(model) @@ -131,7 +131,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiResizeServerRequest { - req := apiClient.ResizeServer(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.ResizeServer(ctx, model.ProjectId, model.Region, model.ServerId) payload := iaas.ResizeServerPayload{ MachineType: model.MachineType, } diff --git a/internal/cmd/server/resize/resize_test.go b/internal/cmd/server/resize/resize_test.go index 3ba39088f..3739ab759 100644 --- a/internal/cmd/server/resize/resize_test.go +++ b/internal/cmd/server/resize/resize_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" ) const ( @@ -21,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -56,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, }, ServerId: testServerId, - MachineType: utils.Ptr("t1.2"), + MachineType: "t1.2", } for _, mod := range mods { mod(model) @@ -65,9 +64,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiResizeServerRequest)) iaas.ApiResizeServerRequest { - request := testClient.ResizeServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.ResizeServer(testCtx, testProjectId, testRegion, testServerId) request = request.ResizeServerPayload(iaas.ResizeServerPayload{ - MachineType: utils.Ptr("t1.2"), + MachineType: "t1.2", }) for _, mod := range mods { mod(&request) @@ -172,7 +171,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/security-group/attach/attach.go b/internal/cmd/server/security-group/attach/attach.go index f6324237c..1d2d54c9f 100644 --- a/internal/cmd/server/security-group/attach/attach.go +++ b/internal/cmd/server/security-group/attach/attach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel = model.ServerId } - securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get security group name: %v", err) securityGroupLabel = model.SecurityGroupId @@ -115,6 +115,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiAddSecurityGroupToServerRequest { - req := apiClient.AddSecurityGroupToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.SecurityGroupId) + req := apiClient.DefaultAPI.AddSecurityGroupToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.SecurityGroupId) return req } diff --git a/internal/cmd/server/security-group/attach/attach_test.go b/internal/cmd/server/security-group/attach/attach_test.go index 9056e3f8e..30465b515 100644 --- a/internal/cmd/server/security-group/attach/attach_test.go +++ b/internal/cmd/server/security-group/attach/attach_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testSecurityGroupId = uuid.NewString() @@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiAddSecurityGroupToServerRequest)) iaas.ApiAddSecurityGroupToServerRequest { - request := testClient.AddSecurityGroupToServer(testCtx, testProjectId, testRegion, testServerId, testSecurityGroupId) + request := testClient.DefaultAPI.AddSecurityGroupToServer(testCtx, testProjectId, testRegion, testServerId, testSecurityGroupId) for _, mod := range mods { mod(&request) } @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/security-group/detach/detach.go b/internal/cmd/server/security-group/detach/detach.go index 81fe5b30a..54ccf89f0 100644 --- a/internal/cmd/server/security-group/detach/detach.go +++ b/internal/cmd/server/security-group/detach/detach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { serverLabel = model.ServerId } - securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient, model.ProjectId, model.Region, model.SecurityGroupId) + securityGroupLabel, err := iaasUtils.GetSecurityGroupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SecurityGroupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get security group name: %v", err) securityGroupLabel = model.SecurityGroupId @@ -115,6 +115,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRemoveSecurityGroupFromServerRequest { - req := apiClient.RemoveSecurityGroupFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.SecurityGroupId) + req := apiClient.DefaultAPI.RemoveSecurityGroupFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.SecurityGroupId) return req } diff --git a/internal/cmd/server/security-group/detach/detach_test.go b/internal/cmd/server/security-group/detach/detach_test.go index dbf4cc8f3..7cc01f278 100644 --- a/internal/cmd/server/security-group/detach/detach_test.go +++ b/internal/cmd/server/security-group/detach/detach_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testSecurityGroupId = uuid.NewString() @@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRemoveSecurityGroupFromServerRequest)) iaas.ApiRemoveSecurityGroupFromServerRequest { - request := testClient.RemoveSecurityGroupFromServer(testCtx, testProjectId, testRegion, testServerId, testSecurityGroupId) + request := testClient.DefaultAPI.RemoveSecurityGroupFromServer(testCtx, testProjectId, testRegion, testServerId, testSecurityGroupId) for _, mod := range mods { mod(&request) } @@ -172,7 +172,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/service-account/attach/attach.go b/internal/cmd/server/service-account/attach/attach.go index e7c7ea762..e9166c801 100644 --- a/internal/cmd/server/service-account/attach/attach.go +++ b/internal/cmd/server/service-account/attach/attach.go @@ -16,7 +16,7 @@ import ( iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -108,7 +108,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiAddServiceAccountToServerRequest { - req := apiClient.AddServiceAccountToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.ServiceAccMail) + req := apiClient.DefaultAPI.AddServiceAccountToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.ServiceAccMail) return req } diff --git a/internal/cmd/server/service-account/attach/attach_test.go b/internal/cmd/server/service-account/attach/attach_test.go index 1d9edb52e..b7affe1ce 100644 --- a/internal/cmd/server/service-account/attach/attach_test.go +++ b/internal/cmd/server/service-account/attach/attach_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), &testCtxKey{}, "test") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testServiceAccount = "test@example.com" @@ -67,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiAddServiceAccountToServerRequest)) iaas.ApiAddServiceAccountToServerRequest { - request := testClient.AddServiceAccountToServer(testCtx, testProjectId, testRegion, testServerId, testServiceAccount) + request := testClient.DefaultAPI.AddServiceAccountToServer(testCtx, testProjectId, testRegion, testServerId, testServiceAccount) for _, mod := range mods { mod(&request) } @@ -222,7 +222,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/service-account/detach/detach.go b/internal/cmd/server/service-account/detach/detach.go index 07b34db82..671a7a883 100644 --- a/internal/cmd/server/service-account/detach/detach.go +++ b/internal/cmd/server/service-account/detach/detach.go @@ -16,7 +16,7 @@ import ( iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -108,7 +108,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRemoveServiceAccountFromServerRequest { - req := apiClient.RemoveServiceAccountFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.ServiceAccMail) + req := apiClient.DefaultAPI.RemoveServiceAccountFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.ServiceAccMail) return req } diff --git a/internal/cmd/server/service-account/detach/detach_test.go b/internal/cmd/server/service-account/detach/detach_test.go index cf8d6dc2d..39750bd8b 100644 --- a/internal/cmd/server/service-account/detach/detach_test.go +++ b/internal/cmd/server/service-account/detach/detach_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), &testCtxKey{}, "test") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testServiceAccount = "test@example.com" @@ -67,7 +67,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRemoveServiceAccountFromServerRequest)) iaas.ApiRemoveServiceAccountFromServerRequest { - request := testClient.RemoveServiceAccountFromServer(testCtx, testProjectId, testRegion, testServerId, testServiceAccount) + request := testClient.DefaultAPI.RemoveServiceAccountFromServer(testCtx, testProjectId, testRegion, testServerId, testServiceAccount) for _, mod := range mods { mod(&request) } @@ -222,7 +222,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/service-account/list/list.go b/internal/cmd/server/service-account/list/list.go index 28c2e701a..1967b1ad3 100644 --- a/internal/cmd/server/service-account/list/list.go +++ b/internal/cmd/server/service-account/list/list.go @@ -16,7 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverName, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverName, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverName = model.ServerId @@ -77,7 +77,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("list service accounts: %w", err) } - serviceAccounts := *resp.Items + serviceAccounts := resp.Items if model.Limit != nil && len(serviceAccounts) > int(*model.Limit) { serviceAccounts = serviceAccounts[:int(*model.Limit)] @@ -123,7 +123,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListServerServiceAccountsRequest { - req := apiClient.ListServerServiceAccounts(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.ListServerServiceAccounts(ctx, model.ProjectId, model.Region, model.ServerId) return req } diff --git a/internal/cmd/server/service-account/list/list_test.go b/internal/cmd/server/service-account/list/list_test.go index 295e2fac8..0b7c21376 100644 --- a/internal/cmd/server/service-account/list/list_test.go +++ b/internal/cmd/server/service-account/list/list_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,7 +23,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), &testCtxKey{}, "test") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testLimit = int64(10) @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(inputModel *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListServerServiceAccountsRequest)) iaas.ApiListServerServiceAccountsRequest { - request := testClient.ListServerServiceAccounts(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.ListServerServiceAccounts(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -179,7 +179,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Request does not match: %s", diff) diff --git a/internal/cmd/server/start/start.go b/internal/cmd/server/start/start.go index 69ea27c96..907118ee2 100644 --- a/internal/cmd/server/start/start.go +++ b/internal/cmd/server/start/start.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Starting server", func() error { - _, err = wait.StartServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.StartServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -112,5 +112,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiStartServerRequest { - return apiClient.StartServer(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.StartServer(ctx, model.ProjectId, model.Region, model.ServerId) } diff --git a/internal/cmd/server/start/start_test.go b/internal/cmd/server/start/start_test.go index f5e64b2d2..fffb02378 100644 --- a/internal/cmd/server/start/start_test.go +++ b/internal/cmd/server/start/start_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiStartServerRequest)) iaas.ApiStartServerRequest { - request := testClient.StartServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.StartServer(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -155,7 +155,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/stop/stop.go b/internal/cmd/server/stop/stop.go index 3b74699c5..5f42f6b34 100644 --- a/internal/cmd/server/stop/stop.go +++ b/internal/cmd/server/stop/stop.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -80,7 +80,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Stopping server", func() error { - _, err = wait.StopServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.StopServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -118,5 +118,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiStopServerRequest { - return apiClient.StopServer(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.StopServer(ctx, model.ProjectId, model.Region, model.ServerId) } diff --git a/internal/cmd/server/stop/stop_test.go b/internal/cmd/server/stop/stop_test.go index 29980a4b9..8ba4144c7 100644 --- a/internal/cmd/server/stop/stop_test.go +++ b/internal/cmd/server/stop/stop_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiStopServerRequest)) iaas.ApiStopServerRequest { - request := testClient.StopServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.StopServer(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -155,7 +155,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/unrescue/unrescue.go b/internal/cmd/server/unrescue/unrescue.go index 0dbc71319..4815baad6 100644 --- a/internal/cmd/server/unrescue/unrescue.go +++ b/internal/cmd/server/unrescue/unrescue.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -80,7 +80,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Unrescuing server", func() error { - _, err = wait.UnrescueServerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) + _, err = wait.UnrescueServerWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId).WaitWithContext(ctx) return err }) if err != nil { @@ -118,5 +118,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUnrescueServerRequest { - return apiClient.UnrescueServer(ctx, model.ProjectId, model.Region, model.ServerId) + return apiClient.DefaultAPI.UnrescueServer(ctx, model.ProjectId, model.Region, model.ServerId) } diff --git a/internal/cmd/server/unrescue/unrescue_test.go b/internal/cmd/server/unrescue/unrescue_test.go index 708fe68d8..72edc1bef 100644 --- a/internal/cmd/server/unrescue/unrescue_test.go +++ b/internal/cmd/server/unrescue/unrescue_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUnrescueServerRequest)) iaas.ApiUnrescueServerRequest { - request := testClient.UnrescueServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.UnrescueServer(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -155,7 +155,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/update/update.go b/internal/cmd/server/update/update.go index 570c45019..1ce7a8e88 100644 --- a/internal/cmd/server/update/update.go +++ b/internal/cmd/server/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -31,7 +31,7 @@ type inputModel struct { *globalflags.GlobalFlagModel ServerId string Name *string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -63,7 +63,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -108,7 +108,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu GlobalFlagModel: globalFlags, Name: flags.FlagToStringPointer(p, cmd, nameFlag), ServerId: serverId, - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } p.DebugInputModel(model) @@ -116,11 +116,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateServerRequest { - req := apiClient.UpdateServer(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.UpdateServer(ctx, model.ProjectId, model.Region, model.ServerId) payload := iaas.UpdateServerPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.UpdateServerPayload(payload) diff --git a/internal/cmd/server/update/update_test.go b/internal/cmd/server/update/update_test.go index d498c9d62..bd66b8572 100644 --- a/internal/cmd/server/update/update_test.go +++ b/internal/cmd/server/update/update_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -59,9 +59,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, Name: utils.Ptr("example-server-name"), ServerId: testServerId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -70,7 +70,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateServerRequest)) iaas.ApiUpdateServerRequest { - request := testClient.UpdateServer(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.UpdateServer(testCtx, testProjectId, testRegion, testServerId) request = request.UpdateServerPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -81,9 +81,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiUpdateServerRequest)) iaas.Api func fixturePayload(mods ...func(payload *iaas.UpdateServerPayload)) iaas.UpdateServerPayload { payload := iaas.UpdateServerPayload{ Name: utils.Ptr("example-server-name"), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(&payload) @@ -167,7 +167,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = &map[string]string{ + model.Labels = map[string]any{ "key": "value", } }), @@ -247,7 +247,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/volume/attach/attach.go b/internal/cmd/server/volume/attach/attach.go index a1b1695a7..97667419b 100644 --- a/internal/cmd/server/volume/attach/attach.go +++ b/internal/cmd/server/volume/attach/attach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -65,13 +65,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -126,7 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiAddVolumeToServerRequest { - req := apiClient.AddVolumeToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) + req := apiClient.DefaultAPI.AddVolumeToServer(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) payload := iaas.AddVolumeToServerPayload{ DeleteOnTermination: model.DeleteOnTermination, } diff --git a/internal/cmd/server/volume/attach/attach_test.go b/internal/cmd/server/volume/attach/attach_test.go index dbdd63148..841a19fa1 100644 --- a/internal/cmd/server/volume/attach/attach_test.go +++ b/internal/cmd/server/volume/attach/attach_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -78,7 +78,7 @@ func fixturePayload(mods ...func(payload *iaas.AddVolumeToServerPayload)) iaas.A } func fixtureRequest(mods ...func(request *iaas.ApiAddVolumeToServerRequest)) iaas.ApiAddVolumeToServerRequest { - request := testClient.AddVolumeToServer(testCtx, testProjectId, testRegion, testServerId, testVolumeId) + request := testClient.DefaultAPI.AddVolumeToServer(testCtx, testProjectId, testRegion, testServerId, testVolumeId) request = request.AddVolumeToServerPayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -246,7 +246,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/volume/describe/describe.go b/internal/cmd/server/volume/describe/describe.go index bd1328de8..d7730cadb 100644 --- a/internal/cmd/server/volume/describe/describe.go +++ b/internal/cmd/server/volume/describe/describe.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -65,13 +65,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -118,7 +118,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetAttachedVolumeRequest { - req := apiClient.GetAttachedVolume(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) + req := apiClient.DefaultAPI.GetAttachedVolume(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) return req } diff --git a/internal/cmd/server/volume/describe/describe_test.go b/internal/cmd/server/volume/describe/describe_test.go index 868511240..37791b9b9 100644 --- a/internal/cmd/server/volume/describe/describe_test.go +++ b/internal/cmd/server/volume/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetAttachedVolumeRequest)) iaas.ApiGetAttachedVolumeRequest { - request := testClient.GetAttachedVolume(testCtx, testProjectId, testRegion, testServerId, testVolumeId) + request := testClient.DefaultAPI.GetAttachedVolume(testCtx, testProjectId, testRegion, testServerId, testVolumeId) for _, mod := range mods { mod(&request) } @@ -222,7 +222,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/volume/detach/detach.go b/internal/cmd/server/volume/detach/detach.go index 4e46187ee..713a3d205 100644 --- a/internal/cmd/server/volume/detach/detach.go +++ b/internal/cmd/server/volume/detach/detach.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -57,13 +57,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -117,6 +117,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRemoveVolumeFromServerRequest { - req := apiClient.RemoveVolumeFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) + req := apiClient.DefaultAPI.RemoveVolumeFromServer(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) return req } diff --git a/internal/cmd/server/volume/detach/detach_test.go b/internal/cmd/server/volume/detach/detach_test.go index d56a5d9dd..3541c79c3 100644 --- a/internal/cmd/server/volume/detach/detach_test.go +++ b/internal/cmd/server/volume/detach/detach_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -66,7 +66,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRemoveVolumeFromServerRequest)) iaas.ApiRemoveVolumeFromServerRequest { - request := testClient.RemoveVolumeFromServer(testCtx, testProjectId, testRegion, testServerId, testVolumeId) + request := testClient.DefaultAPI.RemoveVolumeFromServer(testCtx, testProjectId, testRegion, testServerId, testVolumeId) for _, mod := range mods { mod(&request) } @@ -221,7 +221,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/volume/list/list.go b/internal/cmd/server/volume/list/list.go index 2cd23fd02..148bae43c 100644 --- a/internal/cmd/server/volume/list/list.go +++ b/internal/cmd/server/volume/list/list.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -57,7 +57,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -77,7 +77,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // get volume names var volumeNames []string for i := range volumes { - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, *volumes[i].VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *volumes[i].VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = "" @@ -115,7 +115,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListAttachedVolumesRequest { - req := apiClient.ListAttachedVolumes(ctx, model.ProjectId, model.Region, model.ServerId) + req := apiClient.DefaultAPI.ListAttachedVolumes(ctx, model.ProjectId, model.Region, model.ServerId) return req } diff --git a/internal/cmd/server/volume/list/list_test.go b/internal/cmd/server/volume/list/list_test.go index 3c4ecc72c..38b8cbd29 100644 --- a/internal/cmd/server/volume/list/list_test.go +++ b/internal/cmd/server/volume/list/list_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() @@ -54,7 +54,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListAttachedVolumesRequest)) iaas.ApiListAttachedVolumesRequest { - request := testClient.ListAttachedVolumes(testCtx, testProjectId, testRegion, testServerId) + request := testClient.DefaultAPI.ListAttachedVolumes(testCtx, testProjectId, testRegion, testServerId) for _, mod := range mods { mod(&request) } @@ -150,7 +150,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/server/volume/update/update.go b/internal/cmd/server/volume/update/update.go index 389ad26a6..61d74ac32 100644 --- a/internal/cmd/server/volume/update/update.go +++ b/internal/cmd/server/volume/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -61,13 +61,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId } - serverLabel, err := iaasUtils.GetServerName(ctx, apiClient, model.ProjectId, model.Region, model.ServerId) + serverLabel, err := iaasUtils.GetServerName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.ServerId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get server name: %v", err) serverLabel = model.ServerId @@ -122,7 +122,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateAttachedVolumeRequest { - req := apiClient.UpdateAttachedVolume(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) + req := apiClient.DefaultAPI.UpdateAttachedVolume(ctx, model.ProjectId, model.Region, model.ServerId, model.VolumeId) payload := iaas.UpdateAttachedVolumePayload{ DeleteOnTermination: model.DeleteOnTermination, } diff --git a/internal/cmd/server/volume/update/update_test.go b/internal/cmd/server/volume/update/update_test.go index af29cce5b..6cbd5205b 100644 --- a/internal/cmd/server/volume/update/update_test.go +++ b/internal/cmd/server/volume/update/update_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testServerId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -78,7 +78,7 @@ func fixturePayload(mods ...func(payload *iaas.UpdateAttachedVolumePayload)) iaa } func fixtureRequest(mods ...func(request *iaas.ApiUpdateAttachedVolumeRequest)) iaas.ApiUpdateAttachedVolumeRequest { - request := testClient.UpdateAttachedVolume(testCtx, testProjectId, testRegion, testServerId, testVolumeId) + request := testClient.DefaultAPI.UpdateAttachedVolume(testCtx, testProjectId, testRegion, testServerId, testVolumeId) request = request.UpdateAttachedVolumePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -245,7 +245,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/backup/create/create.go b/internal/cmd/volume/backup/create/create.go index c2211a3ad..2c5022ce2 100644 --- a/internal/cmd/volume/backup/create/create.go +++ b/internal/cmd/volume/backup/create/create.go @@ -19,8 +19,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" ) const ( @@ -37,7 +37,7 @@ type inputModel struct { SourceID string SourceType string Name *string - Labels map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -81,14 +81,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command { switch model.SourceType { case "volume": - name, err := iaasutils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.SourceID) + name, err := iaasutils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SourceID) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) } else if name != "" { sourceLabel = name } case "snapshot": - name, err := iaasutils.GetSnapshotName(ctx, apiClient, model.ProjectId, model.Region, model.SourceID) + name, err := iaasutils.GetSnapshotName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SourceID) if err != nil { params.Printer.Debug(print.ErrorLevel, "get snapshot name: %v", err) } else if name != "" { @@ -116,7 +116,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { resp, err = spinner.Run2(params.Printer, "Creating backup", func() (*iaas.Backup, error) { - return wait.CreateBackupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, volumeId).WaitWithContext(ctx) + return wait.CreateBackupWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, volumeId).WaitWithContext(ctx) }) if err != nil { return fmt.Errorf("wait for backup creation: %w", err) @@ -155,9 +155,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, sourceType := flags.FlagToStringValue(p, cmd, sourceTypeFlag) name := flags.FlagToStringPointer(p, cmd, nameFlag) - labels := flags.FlagToStringToStringPointer(p, cmd, labelsFlag) + labels := flags.FlagToStringToAny(p, cmd, labelsFlag) if labels == nil { - labels = &map[string]string{} + labels = map[string]any{} } model := inputModel{ @@ -165,7 +165,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, SourceID: sourceID, SourceType: sourceType, Name: name, - Labels: *labels, + Labels: labels, } p.DebugInputModel(model) @@ -173,14 +173,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateBackupRequest { - req := apiClient.CreateBackup(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreateBackup(ctx, model.ProjectId, model.Region) payload := iaas.CreateBackupPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(utils.Ptr(model.Labels)), - Source: &iaas.BackupSource{ - Id: &model.SourceID, - Type: &model.SourceType, + Labels: model.Labels, + Source: iaas.BackupSource{ + Id: model.SourceID, + Type: model.SourceType, }, } diff --git a/internal/cmd/volume/backup/create/create_test.go b/internal/cmd/volume/backup/create/create_test.go index 155fd23a3..36689449b 100644 --- a/internal/cmd/volume/backup/create/create_test.go +++ b/internal/cmd/volume/backup/create/create_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -26,10 +26,10 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testSourceId = uuid.NewString() - testLabels = map[string]string{"key1": "value1"} + testLabels = map[string]any{"key1": "value1"} ) func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -67,16 +67,16 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateBackupRequest)) iaas.ApiCreateBackupRequest { - request := testClient.CreateBackup(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateBackup(testCtx, testProjectId, testRegion) createPayload := iaas.NewCreateBackupPayloadWithDefaults() createPayload.Name = utils.Ptr(testName) - createPayload.Labels = &map[string]interface{}{ + createPayload.Labels = map[string]any{ "key1": "value1", } - createPayload.Source = &iaas.BackupSource{ - Id: &testSourceId, - Type: utils.Ptr(testSourceType), + createPayload.Source = iaas.BackupSource{ + Id: testSourceId, + Type: testSourceType, } request = request.CreateBackupPayload(*createPayload) @@ -149,7 +149,7 @@ func TestParseInput(t *testing.T) { isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { model.Name = nil - model.Labels = make(map[string]string) + model.Labels = make(map[string]any) }), }, } @@ -180,7 +180,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/backup/delete/delete.go b/internal/cmd/volume/backup/delete/delete.go index fdb2fe458..8913a2048 100644 --- a/internal/cmd/volume/backup/delete/delete.go +++ b/internal/cmd/volume/backup/delete/delete.go @@ -17,8 +17,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" iaasutils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" ) @@ -55,7 +55,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.Region, model.BackupId) + backupLabel, err := iaasutils.GetBackupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BackupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get backup name: %v", err) } @@ -76,7 +76,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Deleting backup", func() error { - _, err = wait.DeleteBackupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BackupId).WaitWithContext(ctx) + _, err = wait.DeleteBackupWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BackupId).WaitWithContext(ctx) return err }) if err != nil { @@ -113,6 +113,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteBackupRequest { - req := apiClient.DeleteBackup(ctx, model.ProjectId, model.Region, model.BackupId) + req := apiClient.DefaultAPI.DeleteBackup(ctx, model.ProjectId, model.Region, model.BackupId) return req } diff --git a/internal/cmd/volume/backup/delete/delete_test.go b/internal/cmd/volume/backup/delete/delete_test.go index 26623975f..0950dcab7 100644 --- a/internal/cmd/volume/backup/delete/delete_test.go +++ b/internal/cmd/volume/backup/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testBackupId = uuid.NewString() ) @@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteBackupRequest)) iaas.ApiDeleteBackupRequest { - request := testClient.DeleteBackup(testCtx, testProjectId, testRegion, testBackupId) + request := testClient.DefaultAPI.DeleteBackup(testCtx, testProjectId, testRegion, testBackupId) for _, mod := range mods { mod(&request) } @@ -139,7 +139,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/backup/describe/describe.go b/internal/cmd/volume/backup/describe/describe.go index 78cc4790e..d3daa92ad 100644 --- a/internal/cmd/volume/backup/describe/describe.go +++ b/internal/cmd/volume/backup/describe/describe.go @@ -18,7 +18,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -88,7 +88,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetBackupRequest { - req := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.BackupId) + req := apiClient.DefaultAPI.GetBackup(ctx, model.ProjectId, model.Region, model.BackupId) return req } @@ -114,9 +114,9 @@ func outputResult(p *print.Printer, outputFormat string, backup *iaas.Backup) er table.AddRow("AVAILABILITY ZONE", utils.PtrString(backup.AvailabilityZone)) table.AddSeparator() - if backup.Labels != nil && len(*backup.Labels) > 0 { + if len(backup.Labels) > 0 { var labels []string - for key, value := range *backup.Labels { + for key, value := range backup.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/volume/backup/describe/describe_test.go b/internal/cmd/volume/backup/describe/describe_test.go index 40984f119..4b550d82b 100644 --- a/internal/cmd/volume/backup/describe/describe_test.go +++ b/internal/cmd/volume/backup/describe/describe_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -22,7 +22,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testBackupId = uuid.NewString() ) @@ -64,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetBackupRequest)) iaas.ApiGetBackupRequest { - request := testClient.GetBackup(testCtx, testProjectId, testRegion, testBackupId) + request := testClient.DefaultAPI.GetBackup(testCtx, testProjectId, testRegion, testBackupId) for _, mod := range mods { mod(&request) } @@ -140,7 +140,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/backup/list/list.go b/internal/cmd/volume/backup/list/list.go index a555d8fb9..245050aea 100644 --- a/internal/cmd/volume/backup/list/list.go +++ b/internal/cmd/volume/backup/list/list.go @@ -8,7 +8,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -126,7 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListBackupsRequest { - req := apiClient.ListBackups(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListBackups(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) @@ -148,7 +148,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, backups [ var labelsString string if backup.Labels != nil { var labels []string - for key, value := range *backup.Labels { + for key, value := range backup.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } labelsString = strings.Join(labels, ", ") diff --git a/internal/cmd/volume/backup/list/list_test.go b/internal/cmd/volume/backup/list/list_test.go index debb31c96..b1183e124 100644 --- a/internal/cmd/volume/backup/list/list_test.go +++ b/internal/cmd/volume/backup/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,7 +23,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() ) @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListBackupsRequest)) iaas.ApiListBackupsRequest { - request := testClient.ListBackups(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListBackups(testCtx, testProjectId, testRegion) request = request.LabelSelector("key1=value1") for _, mod := range mods { mod(&request) @@ -148,7 +148,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/backup/restore/restore.go b/internal/cmd/volume/backup/restore/restore.go index d98478dee..842d86921 100644 --- a/internal/cmd/volume/backup/restore/restore.go +++ b/internal/cmd/volume/backup/restore/restore.go @@ -17,8 +17,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" iaasutils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" ) @@ -55,17 +55,17 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.Region, model.BackupId) + backupLabel, err := iaasutils.GetBackupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BackupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get backup details: %v", err) } // Get source details for labels var sourceLabel string - backup, err := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.BackupId).Execute() + backup, err := apiClient.DefaultAPI.GetBackup(ctx, model.ProjectId, model.Region, model.BackupId).Execute() if err == nil && backup != nil && backup.VolumeId != nil { sourceLabel = *backup.VolumeId - name, err := iaasutils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, *backup.VolumeId) + name, err := iaasutils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *backup.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume details: %v", err) } else if name != "" { @@ -89,7 +89,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Restoring backup", func() error { - _, err = wait.RestoreBackupWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.BackupId).WaitWithContext(ctx) + _, err = wait.RestoreBackupWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BackupId).WaitWithContext(ctx) return err }) if err != nil { @@ -126,6 +126,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiRestoreBackupRequest { - req := apiClient.RestoreBackup(ctx, model.ProjectId, model.Region, model.BackupId) + req := apiClient.DefaultAPI.RestoreBackup(ctx, model.ProjectId, model.Region, model.BackupId) return req } diff --git a/internal/cmd/volume/backup/restore/restore_test.go b/internal/cmd/volume/backup/restore/restore_test.go index 1bd31ce17..2d666666c 100644 --- a/internal/cmd/volume/backup/restore/restore_test.go +++ b/internal/cmd/volume/backup/restore/restore_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testBackupId = uuid.NewString() ) @@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiRestoreBackupRequest)) iaas.ApiRestoreBackupRequest { - request := testClient.RestoreBackup(testCtx, testProjectId, testRegion, testBackupId) + request := testClient.DefaultAPI.RestoreBackup(testCtx, testProjectId, testRegion, testBackupId) for _, mod := range mods { mod(&request) } @@ -139,7 +139,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/backup/update/update.go b/internal/cmd/volume/backup/update/update.go index 4a61e582a..1ec7cf927 100644 --- a/internal/cmd/volume/backup/update/update.go +++ b/internal/cmd/volume/backup/update/update.go @@ -18,7 +18,7 @@ import ( iaasutils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -31,7 +31,7 @@ type inputModel struct { *globalflags.GlobalFlagModel BackupId string Name *string - Labels map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -61,7 +61,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - backupLabel, err := iaasutils.GetBackupName(ctx, apiClient, model.ProjectId, model.Region, model.BackupId) + backupLabel, err := iaasutils.GetBackupName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.BackupId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get backup name: %v", err) } @@ -101,16 +101,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } name := flags.FlagToStringPointer(p, cmd, nameFlag) - labels := flags.FlagToStringToStringPointer(p, cmd, labelsFlag) + labels := flags.FlagToStringToAny(p, cmd, labelsFlag) if labels == nil { - labels = &map[string]string{} + labels = map[string]any{} } model := inputModel{ GlobalFlagModel: globalFlags, BackupId: backupId, Name: name, - Labels: *labels, + Labels: labels, } p.DebugInputModel(model) @@ -118,11 +118,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateBackupRequest { - req := apiClient.UpdateBackup(ctx, model.ProjectId, model.Region, model.BackupId) + req := apiClient.DefaultAPI.UpdateBackup(ctx, model.ProjectId, model.Region, model.BackupId) payload := iaas.UpdateBackupPayload{ Name: model.Name, - Labels: utils.ConvertStringMapToInterfaceMap(utils.Ptr(model.Labels)), + Labels: model.Labels, } req = req.UpdateBackupPayload(payload) diff --git a/internal/cmd/volume/backup/update/update_test.go b/internal/cmd/volume/backup/update/update_test.go index 94860245a..585e8117b 100644 --- a/internal/cmd/volume/backup/update/update_test.go +++ b/internal/cmd/volume/backup/update/update_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,10 +23,10 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testBackupId = uuid.NewString() - testLabels = map[string]string{"key1": "value1"} + testLabels = map[string]any{"key1": "value1"} ) func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -71,11 +71,11 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateBackupRequest)) iaas.ApiUpdateBackupRequest { - request := testClient.UpdateBackup(testCtx, testProjectId, testRegion, testBackupId) + request := testClient.DefaultAPI.UpdateBackup(testCtx, testProjectId, testRegion, testBackupId) payload := iaas.NewUpdateBackupPayloadWithDefaults() payload.Name = utils.Ptr(testName) - payload.Labels = utils.ConvertStringMapToInterfaceMap(utils.Ptr(testLabels)) + payload.Labels = testLabels request = request.UpdateBackupPayload(*payload) for _, mod := range mods { @@ -145,7 +145,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/create/create.go b/internal/cmd/volume/create/create.go index f0c672602..767f69e5f 100644 --- a/internal/cmd/volume/create/create.go +++ b/internal/cmd/volume/create/create.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -36,10 +36,10 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - AvailabilityZone *string + AvailabilityZone string Name *string Description *string - Labels *map[string]string + Labels map[string]any PerformanceClass *string Size *int64 SourceId *string @@ -106,7 +106,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Creating volume", func() error { - _, err = wait.CreateVolumeWaitHandler(ctx, apiClient, model.ProjectId, model.Region, volumeId).WaitWithContext(ctx) + _, err = wait.CreateVolumeWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, volumeId).WaitWithContext(ctx) return err }) if err != nil { @@ -143,10 +143,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, model := inputModel{ GlobalFlagModel: globalFlags, - AvailabilityZone: flags.FlagToStringPointer(p, cmd, availabilityZoneFlag), + AvailabilityZone: flags.FlagToStringValue(p, cmd, availabilityZoneFlag), Name: flags.FlagToStringPointer(p, cmd, nameFlag), Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), PerformanceClass: flags.FlagToStringPointer(p, cmd, performanceClassFlag), Size: flags.FlagToInt64Pointer(p, cmd, sizeFlag), SourceId: flags.FlagToStringPointer(p, cmd, sourceIdFlag), @@ -158,23 +158,22 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateVolumeRequest { - req := apiClient.CreateVolume(ctx, model.ProjectId, model.Region) - source := &iaas.VolumeSource{ - Id: model.SourceId, - Type: model.SourceType, - } + req := apiClient.DefaultAPI.CreateVolume(ctx, model.ProjectId, model.Region) payload := iaas.CreateVolumePayload{ AvailabilityZone: model.AvailabilityZone, Name: model.Name, Description: model.Description, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, PerformanceClass: model.PerformanceClass, Size: model.Size, } if model.SourceId != nil && model.SourceType != nil { - payload.Source = source + payload.Source = &iaas.VolumeSource{ + Id: *model.SourceId, + Type: *model.SourceType, + } } return req.CreateVolumePayload(payload) diff --git a/internal/cmd/volume/create/create_test.go b/internal/cmd/volume/create/create_test.go index cdf118b75..3848a5e1f 100644 --- a/internal/cmd/volume/create/create_test.go +++ b/internal/cmd/volume/create/create_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testSourceId = uuid.NewString() @@ -54,16 +54,16 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - AvailabilityZone: utils.Ptr("eu01-1"), + AvailabilityZone: "eu01-1", Name: utils.Ptr("example-volume-name"), Description: utils.Ptr("example-volume-description"), PerformanceClass: utils.Ptr("example-perf-class"), Size: utils.Ptr(int64(5)), - SourceId: utils.Ptr(testSourceId), + SourceId: &testSourceId, SourceType: utils.Ptr("example-source-type"), - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -72,7 +72,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateVolumeRequest)) iaas.ApiCreateVolumeRequest { - request := testClient.CreateVolume(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateVolume(testCtx, testProjectId, testRegion) request = request.CreateVolumePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -81,9 +81,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiCreateVolumeRequest)) iaas.Api } func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateVolumeRequest)) iaas.ApiCreateVolumeRequest { - request := testClient.CreateVolume(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateVolume(testCtx, testProjectId, testRegion) request = request.CreateVolumePayload(iaas.CreateVolumePayload{ - AvailabilityZone: utils.Ptr("eu01-1"), + AvailabilityZone: "eu01-1", }) for _, mod := range mods { mod(&request) @@ -93,17 +93,17 @@ func fixtureRequiredRequest(mods ...func(request *iaas.ApiCreateVolumeRequest)) func fixturePayload(mods ...func(payload *iaas.CreateVolumePayload)) iaas.CreateVolumePayload { payload := iaas.CreateVolumePayload{ - AvailabilityZone: utils.Ptr("eu01-1"), + AvailabilityZone: "eu01-1", Name: utils.Ptr("example-volume-name"), Description: utils.Ptr("example-volume-description"), PerformanceClass: utils.Ptr("example-perf-class"), Size: utils.Ptr(int64(5)), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, Source: &iaas.VolumeSource{ - Id: utils.Ptr(testSourceId), - Type: utils.Ptr("example-source-type"), + Id: testSourceId, + Type: "example-source-type", }, } for _, mod := range mods { @@ -201,7 +201,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.SourceId = utils.Ptr(testSourceId) + model.SourceId = &testSourceId model.SourceType = utils.Ptr("example-source-type") }), }, @@ -233,7 +233,7 @@ func TestBuildRequest(t *testing.T) { Verbosity: globalflags.VerbosityDefault, Region: testRegion, }, - AvailabilityZone: utils.Ptr("eu01-1"), + AvailabilityZone: "eu01-1", }, expectedRequest: fixtureRequiredRequest(), }, @@ -245,7 +245,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/delete/delete.go b/internal/cmd/volume/delete/delete.go index 11984713b..f094ff20e 100644 --- a/internal/cmd/volume/delete/delete.go +++ b/internal/cmd/volume/delete/delete.go @@ -6,8 +6,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -59,7 +59,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId @@ -81,7 +81,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Deleting volume", func() error { - _, err = wait.DeleteVolumeWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId).WaitWithContext(ctx) + _, err = wait.DeleteVolumeWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId).WaitWithContext(ctx) return err }) if err != nil { @@ -118,5 +118,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteVolumeRequest { - return apiClient.DeleteVolume(ctx, model.ProjectId, model.Region, model.VolumeId) + return apiClient.DefaultAPI.DeleteVolume(ctx, model.ProjectId, model.Region, model.VolumeId) } diff --git a/internal/cmd/volume/delete/delete_test.go b/internal/cmd/volume/delete/delete_test.go index 42d63db2b..6408764fb 100644 --- a/internal/cmd/volume/delete/delete_test.go +++ b/internal/cmd/volume/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -20,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testVolumeId = uuid.NewString() var testProjectId = uuid.NewString() @@ -61,7 +61,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteVolumeRequest)) iaas.ApiDeleteVolumeRequest { - request := testClient.DeleteVolume(testCtx, testProjectId, testRegion, testVolumeId) + request := testClient.DefaultAPI.DeleteVolume(testCtx, testProjectId, testRegion, testVolumeId) for _, mod := range mods { mod(&request) } @@ -165,7 +165,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/describe/describe.go b/internal/cmd/volume/describe/describe.go index e8c009a65..1ac849084 100644 --- a/internal/cmd/volume/describe/describe.go +++ b/internal/cmd/volume/describe/describe.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -90,7 +90,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetVolumeRequest { - return apiClient.GetVolume(ctx, model.ProjectId, model.Region, model.VolumeId) + return apiClient.DefaultAPI.GetVolume(ctx, model.ProjectId, model.Region, model.VolumeId) } func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) error { @@ -109,11 +109,11 @@ func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) er table.AddSeparator() table.AddRow("PERFORMANCE CLASS", utils.PtrString(volume.PerformanceClass)) table.AddSeparator() - table.AddRow("AVAILABILITY ZONE", utils.PtrString(volume.AvailabilityZone)) + table.AddRow("AVAILABILITY ZONE", volume.AvailabilityZone) table.AddSeparator() if volume.Source != nil { - sourceId := *volume.Source.Id + sourceId := volume.Source.Id table.AddRow("SOURCE", sourceId) table.AddSeparator() } @@ -124,9 +124,9 @@ func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) er table.AddSeparator() } - if volume.Labels != nil && len(*volume.Labels) > 0 { + if len(volume.Labels) > 0 { labels := []string{} - for key, value := range *volume.Labels { + for key, value := range volume.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/volume/describe/describe_test.go b/internal/cmd/volume/describe/describe_test.go index 66c607e2a..70ba621f0 100644 --- a/internal/cmd/volume/describe/describe_test.go +++ b/internal/cmd/volume/describe/describe_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -21,7 +21,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -62,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetVolumeRequest)) iaas.ApiGetVolumeRequest { - request := testClient.GetVolume(testCtx, testProjectId, testRegion, testVolumeId) + request := testClient.DefaultAPI.GetVolume(testCtx, testProjectId, testRegion, testVolumeId) for _, mod := range mods { mod(&request) } @@ -166,7 +166,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/list/list.go b/internal/cmd/volume/list/list.go index ed0192343..cf2cb500c 100644 --- a/internal/cmd/volume/list/list.go +++ b/internal/cmd/volume/list/list.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -126,7 +126,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListVolumesRequest { - req := apiClient.ListVolumes(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListVolumes(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -150,7 +150,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, volumes [ utils.PtrString(volume.Name), utils.PtrString(volume.Status), utils.PtrString(volume.ServerId), - utils.PtrString(volume.AvailabilityZone), + volume.AvailabilityZone, utils.PtrString(volume.Size), ) table.AddSeparator() diff --git a/internal/cmd/volume/list/list_test.go b/internal/cmd/volume/list/list_test.go index 7fafae739..65667f341 100644 --- a/internal/cmd/volume/list/list_test.go +++ b/internal/cmd/volume/list/list_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testLabelSelector = "label" @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListVolumesRequest)) iaas.ApiListVolumesRequest { - request := testClient.ListVolumes(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListVolumes(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/performance-class/describe/describe.go b/internal/cmd/volume/performance-class/describe/describe.go index c75a3cb50..617dcfd99 100644 --- a/internal/cmd/volume/performance-class/describe/describe.go +++ b/internal/cmd/volume/performance-class/describe/describe.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -90,7 +90,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetVolumePerformanceClassRequest { - return apiClient.GetVolumePerformanceClass(ctx, model.ProjectId, model.Region, model.VolumePerformanceClass) + return apiClient.DefaultAPI.GetVolumePerformanceClass(ctx, model.ProjectId, model.Region, model.VolumePerformanceClass) } func outputResult(p *print.Printer, outputFormat string, performanceClass *iaas.VolumePerformanceClass) error { @@ -99,7 +99,7 @@ func outputResult(p *print.Printer, outputFormat string, performanceClass *iaas. } return p.OutputResult(outputFormat, performanceClass, func() error { table := tables.NewTable() - table.AddRow("NAME", utils.PtrString(performanceClass.Name)) + table.AddRow("NAME", performanceClass.Name) table.AddSeparator() table.AddRow("DESCRIPTION", utils.PtrString(performanceClass.Description)) table.AddSeparator() @@ -108,9 +108,9 @@ func outputResult(p *print.Printer, outputFormat string, performanceClass *iaas. table.AddRow("THROUGHPUT", utils.PtrString(performanceClass.Throughput)) table.AddSeparator() - if performanceClass.Labels != nil && len(*performanceClass.Labels) > 0 { + if len(performanceClass.Labels) > 0 { labels := []string{} - for key, value := range *performanceClass.Labels { + for key, value := range performanceClass.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/volume/performance-class/describe/describe_test.go b/internal/cmd/volume/performance-class/describe/describe_test.go index ef7c0d8c9..607b5ccd4 100644 --- a/internal/cmd/volume/performance-class/describe/describe_test.go +++ b/internal/cmd/volume/performance-class/describe/describe_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" ) @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testVolumePerformanceClass = "storage_premium_perf6" @@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetVolumePerformanceClassRequest)) iaas.ApiGetVolumePerformanceClassRequest { - request := testClient.GetVolumePerformanceClass(testCtx, testProjectId, testRegion, testVolumePerformanceClass) + request := testClient.DefaultAPI.GetVolumePerformanceClass(testCtx, testProjectId, testRegion, testVolumePerformanceClass) for _, mod := range mods { mod(&request) } @@ -161,7 +161,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/performance-class/list/list.go b/internal/cmd/volume/performance-class/list/list.go index 9e4f9a453..830fbbb09 100644 --- a/internal/cmd/volume/performance-class/list/list.go +++ b/internal/cmd/volume/performance-class/list/list.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -127,7 +127,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListVolumePerformanceClassesRequest { - req := apiClient.ListVolumePerformanceClasses(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListVolumePerformanceClasses(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -145,7 +145,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, performan table.SetHeader("Name", "Description") for _, performanceClass := range performanceClasses { - table.AddRow(utils.PtrString(performanceClass.Name), utils.PtrString(performanceClass.Description)) + table.AddRow(performanceClass.Name, utils.PtrString(performanceClass.Description)) table.AddSeparator() } diff --git a/internal/cmd/volume/performance-class/list/list_test.go b/internal/cmd/volume/performance-class/list/list_test.go index 0ad6eb32b..aac385672 100644 --- a/internal/cmd/volume/performance-class/list/list_test.go +++ b/internal/cmd/volume/performance-class/list/list_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testLabelSelector = "label" @@ -57,7 +57,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListVolumePerformanceClassesRequest)) iaas.ApiListVolumePerformanceClassesRequest { - request := testClient.ListVolumePerformanceClasses(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListVolumePerformanceClasses(testCtx, testProjectId, testRegion) request = request.LabelSelector(testLabelSelector) for _, mod := range mods { mod(&request) @@ -162,7 +162,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/resize/resize.go b/internal/cmd/volume/resize/resize.go index 1207eee46..c34b6d41e 100644 --- a/internal/cmd/volume/resize/resize.go +++ b/internal/cmd/volume/resize/resize.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -30,7 +30,7 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel VolumeId string - Size *int64 + Size int64 } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -58,7 +58,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId @@ -102,7 +102,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu model := inputModel{ GlobalFlagModel: globalFlags, - Size: flags.FlagToInt64Pointer(p, cmd, sizeFlag), + Size: *flags.FlagToInt64Pointer(p, cmd, sizeFlag), VolumeId: volumeId, } @@ -111,7 +111,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiResizeVolumeRequest { - req := apiClient.ResizeVolume(ctx, model.ProjectId, model.Region, model.VolumeId) + req := apiClient.DefaultAPI.ResizeVolume(ctx, model.ProjectId, model.Region, model.VolumeId) payload := iaas.ResizeVolumePayload{ Size: model.Size, diff --git a/internal/cmd/volume/resize/resize_test.go b/internal/cmd/volume/resize/resize_test.go index 8bfe83342..0e7cbaf69 100644 --- a/internal/cmd/volume/resize/resize_test.go +++ b/internal/cmd/volume/resize/resize_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" - "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" ) const ( @@ -21,7 +20,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -56,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Region: testRegion, Verbosity: globalflags.VerbosityDefault, }, - Size: utils.Ptr(int64(10)), + Size: int64(10), VolumeId: testVolumeId, } for _, mod := range mods { @@ -66,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiResizeVolumeRequest)) iaas.ApiResizeVolumeRequest { - request := testClient.ResizeVolume(testCtx, testProjectId, testRegion, testVolumeId) + request := testClient.DefaultAPI.ResizeVolume(testCtx, testProjectId, testRegion, testVolumeId) request = request.ResizeVolumePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -76,7 +75,7 @@ func fixtureRequest(mods ...func(request *iaas.ApiResizeVolumeRequest)) iaas.Api func fixturePayload(mods ...func(payload *iaas.ResizeVolumePayload)) iaas.ResizeVolumePayload { payload := iaas.ResizeVolumePayload{ - Size: utils.Ptr(int64(10)), + Size: int64(10), } for _, mod := range mods { mod(&payload) @@ -149,7 +148,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Size = utils.Ptr(int64(15)) + model.Size = int64(15) }), }, } @@ -227,7 +226,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/snapshot/create/create.go b/internal/cmd/volume/snapshot/create/create.go index 836794612..68ce82eb6 100644 --- a/internal/cmd/volume/snapshot/create/create.go +++ b/internal/cmd/volume/snapshot/create/create.go @@ -20,8 +20,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" ) const ( @@ -34,7 +34,7 @@ type inputModel struct { *globalflags.GlobalFlagModel VolumeID string Name *string - Labels map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -74,7 +74,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get volume name for label - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeID) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeID) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeID @@ -96,7 +96,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { resp, err = spinner.Run2(params.Printer, "Creating snapshot", func() (*iaas.Snapshot, error) { - return wait.CreateSnapshotWaitHandler(ctx, apiClient, model.ProjectId, model.Region, *resp.Id).WaitWithContext(ctx) + return wait.CreateSnapshotWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, *resp.Id).WaitWithContext(ctx) }) if err != nil { return fmt.Errorf("wait for snapshot creation: %w", err) @@ -134,16 +134,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, volumeID := flags.FlagToStringValue(p, cmd, volumeIdFlag) name := flags.FlagToStringPointer(p, cmd, nameFlag) - labels := flags.FlagToStringToStringPointer(p, cmd, labelsFlag) + labels := flags.FlagToStringToAny(p, cmd, labelsFlag) if labels == nil { - labels = &map[string]string{} + labels = map[string]any{} } model := inputModel{ GlobalFlagModel: globalFlags, VolumeID: volumeID, Name: name, - Labels: *labels, + Labels: labels, } p.DebugInputModel(model) @@ -151,11 +151,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiCreateSnapshotRequest { - req := apiClient.CreateSnapshot(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.CreateSnapshot(ctx, model.ProjectId, model.Region) payload := iaas.NewCreateSnapshotPayloadWithDefaults() - payload.VolumeId = &model.VolumeID + payload.VolumeId = model.VolumeID payload.Name = model.Name - payload.Labels = utils.ConvertStringMapToInterfaceMap(utils.Ptr(model.Labels)) + payload.Labels = model.Labels req = req.CreateSnapshotPayload(*payload) return req diff --git a/internal/cmd/volume/snapshot/create/create_test.go b/internal/cmd/volume/snapshot/create/create_test.go index 7dbc2681f..ac2744f9d 100644 --- a/internal/cmd/volume/snapshot/create/create_test.go +++ b/internal/cmd/volume/snapshot/create/create_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" @@ -23,10 +23,10 @@ const ( var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testVolumeId = uuid.NewString() - testLabels = map[string]string{"key1": "value1"} + testLabels = map[string]any{"key1": "value1"} ) func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -62,12 +62,12 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiCreateSnapshotRequest)) iaas.ApiCreateSnapshotRequest { - request := testClient.CreateSnapshot(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.CreateSnapshot(testCtx, testProjectId, testRegion) payload := iaas.NewCreateSnapshotPayloadWithDefaults() - payload.VolumeId = &testVolumeId + payload.VolumeId = testVolumeId payload.Name = utils.Ptr(testName) - payload.Labels = utils.ConvertStringMapToInterfaceMap(utils.Ptr(testLabels)) + payload.Labels = testLabels request = request.CreateSnapshotPayload(*payload) for _, mod := range mods { @@ -132,7 +132,7 @@ func TestParseInput(t *testing.T) { isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { model.Name = nil - model.Labels = make(map[string]string) + model.Labels = make(map[string]any) }), }, } @@ -163,7 +163,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/snapshot/delete/delete.go b/internal/cmd/volume/snapshot/delete/delete.go index 9a60e5a13..7c8e06535 100644 --- a/internal/cmd/volume/snapshot/delete/delete.go +++ b/internal/cmd/volume/snapshot/delete/delete.go @@ -18,8 +18,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" + wait "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api/wait" ) const ( @@ -56,7 +56,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get snapshot name for label - snapshotLabel, err := iaasUtils.GetSnapshotName(ctx, apiClient, model.ProjectId, model.Region, model.SnapshotId) + snapshotLabel, err := iaasUtils.GetSnapshotName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SnapshotId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get snapshot name: %v", err) snapshotLabel = model.SnapshotId @@ -78,7 +78,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Deleting snapshot", func() error { - _, err = wait.DeleteSnapshotWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.SnapshotId).WaitWithContext(ctx) + _, err = wait.DeleteSnapshotWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SnapshotId).WaitWithContext(ctx) return err }) if err != nil { @@ -115,5 +115,5 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteSnapshotRequest { - return apiClient.DeleteSnapshot(ctx, model.ProjectId, model.Region, model.SnapshotId) + return apiClient.DefaultAPI.DeleteSnapshot(ctx, model.ProjectId, model.Region, model.SnapshotId) } diff --git a/internal/cmd/volume/snapshot/delete/delete_test.go b/internal/cmd/volume/snapshot/delete/delete_test.go index 6ffa3d880..f1b7d8d89 100644 --- a/internal/cmd/volume/snapshot/delete/delete_test.go +++ b/internal/cmd/volume/snapshot/delete/delete_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -21,7 +21,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testSnapshotId = uuid.NewString() ) @@ -63,7 +63,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiDeleteSnapshotRequest)) iaas.ApiDeleteSnapshotRequest { - request := testClient.DeleteSnapshot(testCtx, testProjectId, testRegion, testSnapshotId) + request := testClient.DefaultAPI.DeleteSnapshot(testCtx, testProjectId, testRegion, testSnapshotId) for _, mod := range mods { mod(&request) } @@ -153,7 +153,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/snapshot/describe/describe.go b/internal/cmd/volume/snapshot/describe/describe.go index 85e9e0fe2..8067eaad1 100644 --- a/internal/cmd/volume/snapshot/describe/describe.go +++ b/internal/cmd/volume/snapshot/describe/describe.go @@ -18,7 +18,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -88,7 +88,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiGetSnapshotRequest { - return apiClient.GetSnapshot(ctx, model.ProjectId, model.Region, model.SnapshotId) + return apiClient.DefaultAPI.GetSnapshot(ctx, model.ProjectId, model.Region, model.SnapshotId) } func outputResult(p *print.Printer, outputFormat string, snapshot *iaas.Snapshot) error { @@ -106,12 +106,12 @@ func outputResult(p *print.Printer, outputFormat string, snapshot *iaas.Snapshot table.AddSeparator() table.AddRow("STATUS", utils.PtrString(snapshot.Status)) table.AddSeparator() - table.AddRow("VOLUME ID", utils.PtrString(snapshot.VolumeId)) + table.AddRow("VOLUME ID", snapshot.VolumeId) table.AddSeparator() - if snapshot.Labels != nil && len(*snapshot.Labels) > 0 { + if len(snapshot.Labels) > 0 { labels := []string{} - for key, value := range *snapshot.Labels { + for key, value := range snapshot.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } table.AddRow("LABELS", strings.Join(labels, "\n")) diff --git a/internal/cmd/volume/snapshot/describe/describe_test.go b/internal/cmd/volume/snapshot/describe/describe_test.go index 2247eb517..354d999f9 100644 --- a/internal/cmd/volume/snapshot/describe/describe_test.go +++ b/internal/cmd/volume/snapshot/describe/describe_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,7 +23,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testSnapshotId = uuid.NewString() ) @@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiGetSnapshotRequest)) iaas.ApiGetSnapshotRequest { - request := testClient.GetSnapshot(testCtx, testProjectId, testRegion, testSnapshotId) + request := testClient.DefaultAPI.GetSnapshot(testCtx, testProjectId, testRegion, testSnapshotId) for _, mod := range mods { mod(&request) } @@ -155,7 +155,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/snapshot/list/list.go b/internal/cmd/volume/snapshot/list/list.go index 97b624189..25b62470a 100644 --- a/internal/cmd/volume/snapshot/list/list.go +++ b/internal/cmd/volume/snapshot/list/list.go @@ -19,7 +19,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" ) @@ -125,7 +125,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiListSnapshotsInProjectRequest { - req := apiClient.ListSnapshotsInProject(ctx, model.ProjectId, model.Region) + req := apiClient.DefaultAPI.ListSnapshotsInProject(ctx, model.ProjectId, model.Region) if model.LabelSelector != nil { req = req.LabelSelector(*model.LabelSelector) } @@ -145,7 +145,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, snapshots var labelsString string if snapshot.Labels != nil { var labels []string - for key, value := range *snapshot.Labels { + for key, value := range snapshot.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) } labelsString = strings.Join(labels, "\n") @@ -155,7 +155,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, snapshots utils.PtrString(snapshot.Name), utils.PtrGigaByteSizeDefault(snapshot.Size, "n/a"), utils.PtrString(snapshot.Status), - utils.PtrString(snapshot.VolumeId), + snapshot.VolumeId, labelsString, utils.ConvertTimePToDateTimeString(snapshot.CreatedAt), utils.ConvertTimePToDateTimeString(snapshot.UpdatedAt), diff --git a/internal/cmd/volume/snapshot/list/list_test.go b/internal/cmd/volume/snapshot/list/list_test.go index 090db90cf..a579d0107 100644 --- a/internal/cmd/volume/snapshot/list/list_test.go +++ b/internal/cmd/volume/snapshot/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,7 +23,7 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() ) @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiListSnapshotsInProjectRequest)) iaas.ApiListSnapshotsInProjectRequest { - request := testClient.ListSnapshotsInProject(testCtx, testProjectId, testRegion) + request := testClient.DefaultAPI.ListSnapshotsInProject(testCtx, testProjectId, testRegion) request = request.LabelSelector("key1=value1") for _, mod := range mods { mod(&request) @@ -158,7 +158,7 @@ func TestBuildRequest(t *testing.T) { model.LabelSelector = nil }), expectedRequest: fixtureRequest(func(request *iaas.ApiListSnapshotsInProjectRequest) { - *request = testClient.ListSnapshotsInProject(testCtx, testProjectId, testRegion) + *request = testClient.DefaultAPI.ListSnapshotsInProject(testCtx, testProjectId, testRegion) }), }, } @@ -169,7 +169,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/snapshot/update/update.go b/internal/cmd/volume/snapshot/update/update.go index 5b83aaeaf..91a91e168 100644 --- a/internal/cmd/volume/snapshot/update/update.go +++ b/internal/cmd/volume/snapshot/update/update.go @@ -18,7 +18,7 @@ import ( iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -31,7 +31,7 @@ type inputModel struct { *globalflags.GlobalFlagModel SnapshotId string Name *string - Labels map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -62,7 +62,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Get snapshot name for label - snapshotLabel, err := iaasUtils.GetSnapshotName(ctx, apiClient, model.ProjectId, model.Region, model.SnapshotId) + snapshotLabel, err := iaasUtils.GetSnapshotName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.SnapshotId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get snapshot name: %v", err) snapshotLabel = model.SnapshotId @@ -104,12 +104,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } name := flags.FlagToStringPointer(p, cmd, nameFlag) - labels := flags.FlagToStringToStringPointer(p, cmd, labelsFlag) + labels := flags.FlagToStringToAny(p, cmd, labelsFlag) if labels == nil { - labels = &map[string]string{} + labels = map[string]any{} } - if name == nil && len(*labels) == 0 { + if name == nil && len(labels) == 0 { return nil, fmt.Errorf("either name or labels must be provided") } @@ -117,7 +117,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu GlobalFlagModel: globalFlags, SnapshotId: snapshotId, Name: name, - Labels: *labels, + Labels: labels, } p.DebugInputModel(model) @@ -125,10 +125,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateSnapshotRequest { - req := apiClient.UpdateSnapshot(ctx, model.ProjectId, model.Region, model.SnapshotId) + req := apiClient.DefaultAPI.UpdateSnapshot(ctx, model.ProjectId, model.Region, model.SnapshotId) payload := iaas.NewUpdateSnapshotPayloadWithDefaults() payload.Name = model.Name - payload.Labels = utils.ConvertStringMapToInterfaceMap(utils.Ptr(model.Labels)) + payload.Labels = model.Labels req = req.UpdateSnapshotPayload(*payload) return req diff --git a/internal/cmd/volume/snapshot/update/update_test.go b/internal/cmd/volume/snapshot/update/update_test.go index d5e159315..9c61d2e4d 100644 --- a/internal/cmd/volume/snapshot/update/update_test.go +++ b/internal/cmd/volume/snapshot/update/update_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ( @@ -23,10 +23,10 @@ type testCtxKey struct{} var ( testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") - testClient = &iaas.APIClient{} + testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} testProjectId = uuid.NewString() testSnapshotId = uuid.NewString() - testLabels = map[string]string{"key1": "value1"} + testLabels = map[string]any{"key1": "value1"} ) func fixtureArgValues(mods ...func(argValues []string)) []string { @@ -71,10 +71,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateSnapshotRequest)) iaas.ApiUpdateSnapshotRequest { - request := testClient.UpdateSnapshot(testCtx, testProjectId, testRegion, testSnapshotId) + request := testClient.DefaultAPI.UpdateSnapshot(testCtx, testProjectId, testRegion, testSnapshotId) payload := iaas.NewUpdateSnapshotPayloadWithDefaults() payload.Name = utils.Ptr(testName) - payload.Labels = utils.ConvertStringMapToInterfaceMap(utils.Ptr(testLabels)) + payload.Labels = testLabels request = request.UpdateSnapshotPayload(*payload) for _, mod := range mods { @@ -155,7 +155,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = make(map[string]string) + model.Labels = make(map[string]any) }), }, { @@ -197,7 +197,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/cmd/volume/update/update.go b/internal/cmd/volume/update/update.go index 34fd7e31a..f19b1cb20 100644 --- a/internal/cmd/volume/update/update.go +++ b/internal/cmd/volume/update/update.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -33,7 +33,7 @@ type inputModel struct { VolumeId string Name *string Description *string - Labels *map[string]string + Labels map[string]any } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient, model.ProjectId, model.Region, model.VolumeId) + volumeLabel, err := iaasUtils.GetVolumeName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.VolumeId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err) volumeLabel = model.VolumeId @@ -114,7 +114,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu Name: flags.FlagToStringPointer(p, cmd, nameFlag), VolumeId: volumeId, Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), - Labels: flags.FlagToStringToStringPointer(p, cmd, labelFlag), + Labels: flags.FlagToStringToAny(p, cmd, labelFlag), } p.DebugInputModel(model) @@ -122,12 +122,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiUpdateVolumeRequest { - req := apiClient.UpdateVolume(ctx, model.ProjectId, model.Region, model.VolumeId) + req := apiClient.DefaultAPI.UpdateVolume(ctx, model.ProjectId, model.Region, model.VolumeId) payload := iaas.UpdateVolumePayload{ Name: model.Name, Description: model.Description, - Labels: utils.ConvertStringMapToInterfaceMap(model.Labels), + Labels: model.Labels, } return req.UpdateVolumePayload(payload) diff --git a/internal/cmd/volume/update/update_test.go b/internal/cmd/volume/update/update_test.go index a80df082a..8700f35f0 100644 --- a/internal/cmd/volume/update/update_test.go +++ b/internal/cmd/volume/update/update_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -22,7 +22,7 @@ const ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &iaas.APIClient{} +var testClient = &iaas.APIClient{DefaultAPI: &iaas.DefaultAPIService{}} var testProjectId = uuid.NewString() var testVolumeId = uuid.NewString() @@ -62,9 +62,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Name: utils.Ptr("example-volume-name"), Description: utils.Ptr("example-volume-desc"), VolumeId: testVolumeId, - Labels: utils.Ptr(map[string]string{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(model) @@ -73,7 +73,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *iaas.ApiUpdateVolumeRequest)) iaas.ApiUpdateVolumeRequest { - request := testClient.UpdateVolume(testCtx, testProjectId, testRegion, testVolumeId) + request := testClient.DefaultAPI.UpdateVolume(testCtx, testProjectId, testRegion, testVolumeId) request = request.UpdateVolumePayload(fixturePayload()) for _, mod := range mods { mod(&request) @@ -85,9 +85,9 @@ func fixturePayload(mods ...func(payload *iaas.UpdateVolumePayload)) iaas.Update payload := iaas.UpdateVolumePayload{ Name: utils.Ptr("example-volume-name"), Description: utils.Ptr("example-volume-desc"), - Labels: utils.Ptr(map[string]interface{}{ + Labels: map[string]any{ "key": "value", - }), + }, } for _, mod := range mods { mod(&payload) @@ -173,7 +173,7 @@ func TestParseInput(t *testing.T) { }), isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Labels = &map[string]string{ + model.Labels = map[string]any{ "key": "value", } }), @@ -253,7 +253,7 @@ func TestBuildRequest(t *testing.T) { diff := cmp.Diff(request, tt.expectedRequest, cmp.AllowUnexported(tt.expectedRequest), - cmpopts.EquateComparable(testCtx), + cmpopts.EquateComparable(testCtx, iaas.DefaultAPIService{}), ) if diff != "" { t.Fatalf("Data does not match: %s", diff) diff --git a/internal/pkg/flags/flag_to_value.go b/internal/pkg/flags/flag_to_value.go index b7d8194ed..dfcd50893 100644 --- a/internal/pkg/flags/flag_to_value.go +++ b/internal/pkg/flags/flag_to_value.go @@ -76,6 +76,22 @@ func FlagToStringToStringPointer(p *print.Printer, cmd *cobra.Command, flag stri return nil } +func FlagToStringToAny(p *print.Printer, cmd *cobra.Command, flag string) map[string]any { + value, err := cmd.Flags().GetStringToString(flag) + r := make(map[string]any, len(value)) + if err != nil { + p.Debug(print.ErrorLevel, "convert flag to string to any value: %v", err) + return r + } + if !cmd.Flag(flag).Changed { + return nil + } + for k, v := range value { + r[k] = v + } + return r +} + // Returns a pointer to the flag's value. // Returns nil if the flag is not set, if its value can not be converted to int, or if the flag does not exist. func FlagToIntPointer(p *print.Printer, cmd *cobra.Command, flag string) *int { diff --git a/internal/pkg/services/iaas/client/client.go b/internal/pkg/services/iaas/client/client.go index a49f04b7c..16c0d84f6 100644 --- a/internal/pkg/services/iaas/client/client.go +++ b/internal/pkg/services/iaas/client/client.go @@ -6,7 +6,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/viper" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) func ConfigureClient(p *print.Printer, cliVersion string) (*iaas.APIClient, error) { diff --git a/internal/pkg/services/iaas/utils/utils.go b/internal/pkg/services/iaas/utils/utils.go index 8d04cd831..43117701c 100644 --- a/internal/pkg/services/iaas/utils/utils.go +++ b/internal/pkg/services/iaas/utils/utils.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) var ( @@ -14,66 +14,47 @@ var ( ErrItemsNil = errors.New("items is nil") ) -type IaaSClient interface { - GetSecurityGroupRuleExecute(ctx context.Context, projectId, region, securityGroupRuleId, securityGroupId string) (*iaas.SecurityGroupRule, error) - GetSecurityGroupExecute(ctx context.Context, projectId, region, securityGroupId string) (*iaas.SecurityGroup, error) - GetPublicIPExecute(ctx context.Context, projectId, region, publicIpId string) (*iaas.PublicIp, error) - GetServerExecute(ctx context.Context, projectId, region, serverId string) (*iaas.Server, error) - GetVolumeExecute(ctx context.Context, projectId, region, volumeId string) (*iaas.Volume, error) - GetNetworkExecute(ctx context.Context, projectId, region, networkId string) (*iaas.Network, error) - GetRoutingTableOfAreaExecute(ctx context.Context, organizationId, areaId, region, routingTableId string) (*iaas.RoutingTable, error) - GetNetworkAreaExecute(ctx context.Context, organizationId, areaId string) (*iaas.NetworkArea, error) - ListNetworkAreaProjectsExecute(ctx context.Context, organizationId, areaId string) (*iaas.ProjectListResponse, error) - GetNetworkAreaRangeExecute(ctx context.Context, organizationId, areaId, region, networkRangeId string) (*iaas.NetworkRange, error) - GetImageExecute(ctx context.Context, projectId, region, imageId string) (*iaas.Image, error) - GetAffinityGroupExecute(ctx context.Context, projectId, region, affinityGroupId string) (*iaas.AffinityGroup, error) - GetSnapshotExecute(ctx context.Context, projectId, region, snapshotId string) (*iaas.Snapshot, error) - GetBackupExecute(ctx context.Context, projectId, region, backupId string) (*iaas.Backup, error) -} - -func GetSecurityGroupRuleName(ctx context.Context, apiClient IaaSClient, projectId, region, securityGroupRuleId, securityGroupId string) (string, error) { - resp, err := apiClient.GetSecurityGroupRuleExecute(ctx, projectId, region, securityGroupRuleId, securityGroupId) +func GetSecurityGroupRuleName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, securityGroupRuleId, securityGroupId string) (string, error) { + resp, err := apiClient.GetSecurityGroupRule(ctx, projectId, region, securityGroupRuleId, securityGroupId).Execute() if err != nil { return "", fmt.Errorf("get security group rule: %w", err) } - securityGroupRuleName := *resp.Ethertype + ", " + *resp.Direction + securityGroupRuleName := *resp.Ethertype + ", " + resp.Direction return securityGroupRuleName, nil } -func GetSecurityGroupName(ctx context.Context, apiClient IaaSClient, projectId, region, securityGroupId string) (string, error) { - resp, err := apiClient.GetSecurityGroupExecute(ctx, projectId, region, securityGroupId) +func GetSecurityGroupName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, securityGroupId string) (string, error) { + resp, err := apiClient.GetSecurityGroup(ctx, projectId, region, securityGroupId).Execute() if err != nil { return "", fmt.Errorf("get security group: %w", err) } else if resp == nil { return "", ErrResponseNil - } else if resp.Name == nil { - return "", ErrNameNil } - return *resp.Name, nil + return resp.Name, nil } -func GetPublicIP(ctx context.Context, apiClient IaaSClient, projectId, region, publicIpId string) (ip, associatedResource string, err error) { - resp, err := apiClient.GetPublicIPExecute(ctx, projectId, region, publicIpId) +func GetPublicIP(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, publicIpId string) (ip, associatedResource string, err error) { + resp, err := apiClient.GetPublicIP(ctx, projectId, region, publicIpId).Execute() if err != nil { return "", "", fmt.Errorf("get public ip: %w", err) } associatedResourceId := "" - if resp.NetworkInterface != nil { + if resp.NetworkInterface.IsSet() { associatedResourceId = *resp.NetworkInterface.Get() } return *resp.Ip, associatedResourceId, nil } -func GetServerName(ctx context.Context, apiClient IaaSClient, projectId, region, serverId string) (string, error) { - resp, err := apiClient.GetServerExecute(ctx, projectId, region, serverId) +func GetServerName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, serverId string) (string, error) { + resp, err := apiClient.GetServer(ctx, projectId, region, serverId).Execute() if err != nil { return "", fmt.Errorf("get server: %w", err) } - return *resp.Name, nil + return resp.Name, nil } -func GetVolumeName(ctx context.Context, apiClient IaaSClient, projectId, region, volumeId string) (string, error) { - resp, err := apiClient.GetVolumeExecute(ctx, projectId, region, volumeId) +func GetVolumeName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, volumeId string) (string, error) { + resp, err := apiClient.GetVolume(ctx, projectId, region, volumeId).Execute() if err != nil { return "", fmt.Errorf("get volume: %w", err) } else if resp == nil { @@ -84,44 +65,38 @@ func GetVolumeName(ctx context.Context, apiClient IaaSClient, projectId, region, return *resp.Name, nil } -func GetNetworkName(ctx context.Context, apiClient IaaSClient, projectId, region, networkId string) (string, error) { - resp, err := apiClient.GetNetworkExecute(ctx, projectId, region, networkId) +func GetNetworkName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, networkId string) (string, error) { + resp, err := apiClient.GetNetwork(ctx, projectId, region, networkId).Execute() if err != nil { return "", fmt.Errorf("get network: %w", err) } else if resp == nil { return "", ErrResponseNil - } else if resp.Name == nil { - return "", ErrNameNil } - return *resp.Name, nil + return resp.Name, nil } -func GetRoutingTableOfAreaName(ctx context.Context, apiClient IaaSClient, organizationId, areaId, region, routingTableId string) (string, error) { - resp, err := apiClient.GetRoutingTableOfAreaExecute(ctx, organizationId, areaId, region, routingTableId) +func GetRoutingTableOfAreaName(ctx context.Context, apiClient iaas.DefaultAPI, organizationId, areaId, region, routingTableId string) (string, error) { + resp, err := apiClient.GetRoutingTableOfArea(ctx, organizationId, areaId, region, routingTableId).Execute() if err != nil { return "", fmt.Errorf("get routing-table: %w", err) } else if resp == nil { return "", ErrResponseNil - } else if resp.Name == nil { - return "", ErrNameNil } - return *resp.Name, nil + return resp.Name, nil } -func GetNetworkAreaName(ctx context.Context, apiClient IaaSClient, organizationId, areaId string) (string, error) { - resp, err := apiClient.GetNetworkAreaExecute(ctx, organizationId, areaId) +func GetNetworkAreaName(ctx context.Context, apiClient iaas.DefaultAPI, organizationId, areaId string) (string, error) { + resp, err := apiClient.GetNetworkArea(ctx, organizationId, areaId).Execute() if err != nil { return "", fmt.Errorf("get network area: %w", err) } else if resp == nil { return "", ErrResponseNil - } else if resp.Name == nil { - return "", ErrNameNil } - return *resp.Name, nil + return resp.Name, nil } -func ListAttachedProjects(ctx context.Context, apiClient IaaSClient, organizationId, areaId string) ([]string, error) { - resp, err := apiClient.ListNetworkAreaProjectsExecute(ctx, organizationId, areaId) +func ListAttachedProjects(ctx context.Context, apiClient iaas.DefaultAPI, organizationId, areaId string) ([]string, error) { + resp, err := apiClient.ListNetworkAreaProjects(ctx, organizationId, areaId).Execute() if err != nil { return nil, fmt.Errorf("list network area attached projects: %w", err) } else if resp == nil { @@ -129,60 +104,42 @@ func ListAttachedProjects(ctx context.Context, apiClient IaaSClient, organizatio } else if resp.Items == nil { return nil, ErrItemsNil } - return *resp.Items, nil + return resp.Items, nil } -func GetNetworkRangePrefix(ctx context.Context, apiClient IaaSClient, organizationId, areaId, region, networkRangeId string) (string, error) { - resp, err := apiClient.GetNetworkAreaRangeExecute(ctx, organizationId, areaId, region, networkRangeId) +func GetNetworkRangePrefix(ctx context.Context, apiClient iaas.DefaultAPI, organizationId, areaId, region, networkRangeId string) (string, error) { + resp, err := apiClient.GetNetworkAreaRange(ctx, organizationId, areaId, region, networkRangeId).Execute() if err != nil { return "", fmt.Errorf("get network range: %w", err) } - return *resp.Prefix, nil + return resp.Prefix, nil } // GetRouteFromAPIResponse returns the static route from the API response that matches the prefix and nexthop // This works because static routes are unique by prefix and nexthop -func GetRouteFromAPIResponse(destination, nexthop string, routes *[]iaas.Route) (iaas.Route, error) { - for _, route := range *routes { +func GetRouteFromAPIResponse(destination, nexthop string, routes []iaas.Route) (iaas.Route, error) { + for _, route := range routes { // Check if destination matches - if dest := route.Destination; dest != nil { - match := false - if destV4 := dest.DestinationCIDRv4; destV4 != nil { - if destV4.Value != nil && *destV4.Value == destination { - match = true - } - } else if destV6 := dest.DestinationCIDRv6; destV6 != nil { - if destV6.Value != nil && *destV6.Value == destination { - match = true - } - } - if !match { - continue - } + destV4 := route.Destination.DestinationCIDRv4 + destV4Matches := destV4 != nil && destV4.Value == destination + destV6 := route.Destination.DestinationCIDRv6 + destV6Matches := destV6 != nil && destV6.Value == destination + destMatches := destV4Matches || destV6Matches + if !destMatches { + continue } // Check if nexthop matches - if routeNexthop := route.Nexthop; routeNexthop != nil { - match := false - if nexthopIPv4 := routeNexthop.NexthopIPv4; nexthopIPv4 != nil { - if nexthopIPv4.Value != nil && *nexthopIPv4.Value == nexthop { - match = true - } - } else if nexthopIPv6 := routeNexthop.NexthopIPv6; nexthopIPv6 != nil { - if nexthopIPv6.Value != nil && *nexthopIPv6.Value == nexthop { - match = true - } - } else if nexthopInternet := routeNexthop.NexthopInternet; nexthopInternet != nil { - if nexthopInternet.Type != nil && *nexthopInternet.Type == nexthop { - match = true - } - } else if nexthopBlackhole := routeNexthop.NexthopBlackhole; nexthopBlackhole != nil { - if nexthopBlackhole.Type != nil && *nexthopBlackhole.Type == nexthop { - match = true - } - } - if match { - return route, nil - } + nextHopV4 := route.Nexthop.NexthopIPv4 + nextHopV4Matches := nextHopV4 != nil && nextHopV4.Value == nexthop + nextHopV6 := route.Nexthop.NexthopIPv6 + nextHopV6Matches := nextHopV6 != nil && nextHopV6.Value == nexthop + nextHopInet := route.Nexthop.NexthopInternet + nextHopInetMatches := nextHopInet != nil && nextHopInet.Type == nexthop + nextHopBlackhole := route.Nexthop.NexthopBlackhole + nextHopBlackholeMatches := nextHopBlackhole != nil && nextHopBlackhole.Type == nexthop + nextHopMatches := nextHopV4Matches || nextHopV6Matches || nextHopInetMatches || nextHopBlackholeMatches + if nextHopMatches { + return route, nil } } return iaas.Route{}, fmt.Errorf("new static route not found in API response") @@ -190,41 +147,37 @@ func GetRouteFromAPIResponse(destination, nexthop string, routes *[]iaas.Route) // GetNetworkRangeFromAPIResponse returns the network range from the API response that matches the given prefix // This works because network range prefixes are unique in the same SNA -func GetNetworkRangeFromAPIResponse(prefix string, networkRanges *[]iaas.NetworkRange) (iaas.NetworkRange, error) { - for _, networkRange := range *networkRanges { - if *networkRange.Prefix == prefix { +func GetNetworkRangeFromAPIResponse(prefix string, networkRanges []iaas.NetworkRange) (iaas.NetworkRange, error) { + for _, networkRange := range networkRanges { + if networkRange.Prefix == prefix { return networkRange, nil } } return iaas.NetworkRange{}, fmt.Errorf("new network range not found in API response") } -func GetImageName(ctx context.Context, apiClient IaaSClient, projectId, region, imageId string) (string, error) { - resp, err := apiClient.GetImageExecute(ctx, projectId, region, imageId) +func GetImageName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, imageId string) (string, error) { + resp, err := apiClient.GetImage(ctx, projectId, region, imageId).Execute() if err != nil { return "", fmt.Errorf("get image: %w", err) } else if resp == nil { return "", ErrResponseNil - } else if resp.Name == nil { - return "", ErrNameNil } - return *resp.Name, nil + return resp.Name, nil } -func GetAffinityGroupName(ctx context.Context, apiClient IaaSClient, projectId, region, affinityGroupId string) (string, error) { - resp, err := apiClient.GetAffinityGroupExecute(ctx, projectId, region, affinityGroupId) +func GetAffinityGroupName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, affinityGroupId string) (string, error) { + resp, err := apiClient.GetAffinityGroup(ctx, projectId, region, affinityGroupId).Execute() if err != nil { return "", fmt.Errorf("get affinity group: %w", err) } else if resp == nil { return "", ErrResponseNil - } else if resp.Name == nil { - return "", ErrNameNil } - return *resp.Name, nil + return resp.Name, nil } -func GetSnapshotName(ctx context.Context, apiClient IaaSClient, projectId, region, snapshotId string) (string, error) { - resp, err := apiClient.GetSnapshotExecute(ctx, projectId, region, snapshotId) +func GetSnapshotName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, snapshotId string) (string, error) { + resp, err := apiClient.GetSnapshot(ctx, projectId, region, snapshotId).Execute() if err != nil { return "", fmt.Errorf("get snapshot: %w", err) } else if resp == nil { @@ -235,8 +188,8 @@ func GetSnapshotName(ctx context.Context, apiClient IaaSClient, projectId, regio return *resp.Name, nil } -func GetBackupName(ctx context.Context, apiClient IaaSClient, projectId, region, backupId string) (string, error) { - resp, err := apiClient.GetBackupExecute(ctx, projectId, region, backupId) +func GetBackupName(ctx context.Context, apiClient iaas.DefaultAPI, projectId, region, backupId string) (string, error) { + resp, err := apiClient.GetBackup(ctx, projectId, region, backupId).Execute() if err != nil { return backupId, fmt.Errorf("get backup: %w", err) } diff --git a/internal/pkg/services/iaas/utils/utils_test.go b/internal/pkg/services/iaas/utils/utils_test.go index 61ec9b02d..bb27d10cf 100644 --- a/internal/pkg/services/iaas/utils/utils_test.go +++ b/internal/pkg/services/iaas/utils/utils_test.go @@ -6,13 +6,11 @@ import ( "reflect" "testing" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) -var _ IaaSClient = &IaaSClientMocked{} - type IaaSClientMocked struct { GetSecurityGroupRuleFails bool GetSecurityGroupRuleResp *iaas.SecurityGroupRule @@ -44,103 +42,95 @@ type IaaSClientMocked struct { GetSnapshotResp *iaas.Snapshot } -func (m *IaaSClientMocked) GetAffinityGroupExecute(_ context.Context, _, _, _ string) (*iaas.AffinityGroup, error) { - if m.GetAffinityGroupsFails { - return nil, fmt.Errorf("could not get affinity groups") - } - return m.GetAffinityGroupResp, nil -} - -func (m *IaaSClientMocked) GetSecurityGroupRuleExecute(_ context.Context, _, _, _, _ string) (*iaas.SecurityGroupRule, error) { - if m.GetSecurityGroupRuleFails { - return nil, fmt.Errorf("could not get security group rule") - } - return m.GetSecurityGroupRuleResp, nil -} - -func (m *IaaSClientMocked) GetSecurityGroupExecute(_ context.Context, _, _, _ string) (*iaas.SecurityGroup, error) { - if m.GetSecurityGroupFails { - return nil, fmt.Errorf("could not get security group") - } - return m.GetSecurityGroupResp, nil -} - -func (m *IaaSClientMocked) GetPublicIPExecute(_ context.Context, _, _, _ string) (*iaas.PublicIp, error) { - if m.GetPublicIpFails { - return nil, fmt.Errorf("could not get public ip") - } - return m.GetPublicIpResp, nil -} - -func (m *IaaSClientMocked) GetServerExecute(_ context.Context, _, _, _ string) (*iaas.Server, error) { - if m.GetServerFails { - return nil, fmt.Errorf("could not get server") - } - return m.GetServerResp, nil -} - -func (m *IaaSClientMocked) GetVolumeExecute(_ context.Context, _, _, _ string) (*iaas.Volume, error) { - if m.GetVolumeFails { - return nil, fmt.Errorf("could not get volume") - } - return m.GetVolumeResp, nil -} - -func (m *IaaSClientMocked) GetNetworkExecute(_ context.Context, _, _, _ string) (*iaas.Network, error) { - if m.GetNetworkFails { - return nil, fmt.Errorf("could not get network") - } - return m.GetNetworkResp, nil -} - -func (m *IaaSClientMocked) GetRoutingTableOfAreaExecute(_ context.Context, _, _, _, _ string) (*iaas.RoutingTable, error) { - if m.GetRoutingTableOfAreaFails { - return nil, fmt.Errorf("could not get routing table") - } - return m.GetRoutingTableOfAreaResp, nil -} - -func (m *IaaSClientMocked) GetNetworkAreaExecute(_ context.Context, _, _ string) (*iaas.NetworkArea, error) { - if m.GetNetworkAreaFails { - return nil, fmt.Errorf("could not get network area") - } - return m.GetNetworkAreaResp, nil -} - -func (m *IaaSClientMocked) ListNetworkAreaProjectsExecute(_ context.Context, _, _ string) (*iaas.ProjectListResponse, error) { - if m.GetAttachedProjectsFails { - return nil, fmt.Errorf("could not get attached projects") - } - return m.GetAttachedProjectsResp, nil -} - -func (m *IaaSClientMocked) GetNetworkAreaRangeExecute(_ context.Context, _, _, _, _ string) (*iaas.NetworkRange, error) { - if m.GetNetworkAreaRangeFails { - return nil, fmt.Errorf("could not get network range") - } - return m.GetNetworkAreaRangeResp, nil -} - -func (m *IaaSClientMocked) GetImageExecute(_ context.Context, _, _, _ string) (*iaas.Image, error) { - if m.GetImageFails { - return nil, fmt.Errorf("could not get image") - } - return m.GetImageResp, nil -} - -func (m *IaaSClientMocked) GetBackupExecute(_ context.Context, _, _, _ string) (*iaas.Backup, error) { - if m.GetBackupFails { - return nil, fmt.Errorf("could not get backup") +func newMock(m *IaaSClientMocked) iaas.DefaultAPI { + return iaas.DefaultAPIServiceMock{ + GetAffinityGroupExecuteMock: utils.Ptr(func(_ iaas.ApiGetAffinityGroupRequest) (*iaas.AffinityGroup, error) { + if m.GetAffinityGroupsFails { + return nil, fmt.Errorf("could not get affinity groups") + } + return m.GetAffinityGroupResp, nil + }), + GetSecurityGroupRuleExecuteMock: utils.Ptr(func(_ iaas.ApiGetSecurityGroupRuleRequest) (*iaas.SecurityGroupRule, error) { + if m.GetSecurityGroupRuleFails { + return nil, fmt.Errorf("could not get security group rule") + } + return m.GetSecurityGroupRuleResp, nil + }), + GetSecurityGroupExecuteMock: utils.Ptr(func(_ iaas.ApiGetSecurityGroupRequest) (*iaas.SecurityGroup, error) { + if m.GetSecurityGroupFails { + return nil, fmt.Errorf("could not get security group") + } + return m.GetSecurityGroupResp, nil + }), + GetPublicIPExecuteMock: utils.Ptr(func(_ iaas.ApiGetPublicIPRequest) (*iaas.PublicIp, error) { + if m.GetPublicIpFails { + return nil, fmt.Errorf("could not get public ip") + } + return m.GetPublicIpResp, nil + }), + GetServerExecuteMock: utils.Ptr(func(_ iaas.ApiGetServerRequest) (*iaas.Server, error) { + if m.GetServerFails { + return nil, fmt.Errorf("could not get server") + } + return m.GetServerResp, nil + }), + GetVolumeExecuteMock: utils.Ptr(func(_ iaas.ApiGetVolumeRequest) (*iaas.Volume, error) { + if m.GetVolumeFails { + return nil, fmt.Errorf("could not get volume") + } + return m.GetVolumeResp, nil + }), + GetNetworkExecuteMock: utils.Ptr(func(_ iaas.ApiGetNetworkRequest) (*iaas.Network, error) { + if m.GetNetworkFails { + return nil, fmt.Errorf("could not get network") + } + return m.GetNetworkResp, nil + }), + GetRoutingTableOfAreaExecuteMock: utils.Ptr(func(_ iaas.ApiGetRoutingTableOfAreaRequest) (*iaas.RoutingTable, error) { + if m.GetRoutingTableOfAreaFails { + return nil, fmt.Errorf("could not get routing table") + } + return m.GetRoutingTableOfAreaResp, nil + }), + GetNetworkAreaExecuteMock: utils.Ptr(func(_ iaas.ApiGetNetworkAreaRequest) (*iaas.NetworkArea, error) { + if m.GetNetworkAreaFails { + return nil, fmt.Errorf("could not get network area") + } + return m.GetNetworkAreaResp, nil + }), + ListNetworkAreaProjectsExecuteMock: utils.Ptr(func(_ iaas.ApiListNetworkAreaProjectsRequest) (*iaas.ProjectListResponse, error) { + if m.GetAttachedProjectsFails { + return nil, fmt.Errorf("could not get attached projects") + } + return m.GetAttachedProjectsResp, nil + }), + GetNetworkAreaRangeExecuteMock: utils.Ptr(func(_ iaas.ApiGetNetworkAreaRangeRequest) (*iaas.NetworkRange, error) { + if m.GetNetworkAreaRangeFails { + return nil, fmt.Errorf("could not get network range") + } + return m.GetNetworkAreaRangeResp, nil + }), + GetImageExecuteMock: utils.Ptr(func(_ iaas.ApiGetImageRequest) (*iaas.Image, error) { + if m.GetImageFails { + return nil, fmt.Errorf("could not get image") + } + return m.GetImageResp, nil + }), + GetBackupExecuteMock: utils.Ptr(func(_ iaas.ApiGetBackupRequest) (*iaas.Backup, error) { + if m.GetBackupFails { + return nil, fmt.Errorf("could not get backup") + } + return m.GetBackupResp, nil + }), + GetSnapshotExecuteMock: utils.Ptr(func(_ iaas.ApiGetSnapshotRequest) (*iaas.Snapshot, error) { + if m.GetSnapshotFails { + return nil, fmt.Errorf("could not get snapshot") + } + return m.GetSnapshotResp, nil + }), } - return m.GetBackupResp, nil } -func (m *IaaSClientMocked) GetSnapshotExecute(_ context.Context, _, _, _ string) (*iaas.Snapshot, error) { - if m.GetSnapshotFails { - return nil, fmt.Errorf("could not get snapshot") - } - return m.GetSnapshotResp, nil -} func TestGetSecurityGroupRuleName(t *testing.T) { type args struct { getInstanceFails bool @@ -157,7 +147,7 @@ func TestGetSecurityGroupRuleName(t *testing.T) { args: args{ getInstanceResp: &iaas.SecurityGroupRule{ Ethertype: utils.Ptr("IPv6"), - Direction: utils.Ptr("ingress"), + Direction: "ingress", }, }, want: "IPv6, ingress", @@ -176,7 +166,7 @@ func TestGetSecurityGroupRuleName(t *testing.T) { GetSecurityGroupRuleFails: tt.args.getInstanceFails, GetSecurityGroupRuleResp: tt.args.getInstanceResp, } - got, err := GetSecurityGroupRuleName(context.Background(), m, "", "", "", "") + got, err := GetSecurityGroupRuleName(context.Background(), newMock(m), "", "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetSecurityGroupRuleName() error = %v, wantErr %v", err, tt.wantErr) return @@ -203,7 +193,7 @@ func TestGetSecurityGroupName(t *testing.T) { name: "base", args: args{ getInstanceResp: &iaas.SecurityGroup{ - Name: utils.Ptr("test"), + Name: "test", }, }, want: "test", @@ -224,17 +214,6 @@ func TestGetSecurityGroupName(t *testing.T) { wantErr: true, want: "", }, - { - name: "name in response is nil", - args: args{ - getInstanceResp: &iaas.SecurityGroup{ - Name: nil, - }, - getInstanceFails: false, - }, - wantErr: true, - want: "", - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -242,7 +221,7 @@ func TestGetSecurityGroupName(t *testing.T) { GetSecurityGroupFails: tt.args.getInstanceFails, GetSecurityGroupResp: tt.args.getInstanceResp, } - got, err := GetSecurityGroupName(context.Background(), m, "", "", "") + got, err := GetSecurityGroupName(context.Background(), newMock(m), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetSecurityGroupName() error = %v, wantErr %v", err, tt.wantErr) return @@ -271,7 +250,7 @@ func TestGetPublicIp(t *testing.T) { args: args{ getPublicIpResp: &iaas.PublicIp{ Ip: utils.Ptr("1.2.3.4"), - NetworkInterface: iaas.NewNullableString(utils.Ptr("5.6.7.8")), + NetworkInterface: *iaas.NewNullableString(utils.Ptr("5.6.7.8")), }, }, wantPublicIp: "1.2.3.4", @@ -291,7 +270,7 @@ func TestGetPublicIp(t *testing.T) { GetPublicIpFails: tt.args.getPublicIpFails, GetPublicIpResp: tt.args.getPublicIpResp, } - gotPublicIP, gotAssociatedResource, err := GetPublicIP(context.Background(), m, "", "", "") + gotPublicIP, gotAssociatedResource, err := GetPublicIP(context.Background(), newMock(m), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetPublicIP() error = %v, wantErr %v", err, tt.wantErr) return @@ -321,7 +300,7 @@ func TestGetServerName(t *testing.T) { name: "base", args: args{ getInstanceResp: &iaas.Server{ - Name: utils.Ptr("test"), + Name: "test", }, }, want: "test", @@ -340,7 +319,7 @@ func TestGetServerName(t *testing.T) { GetServerFails: tt.args.getInstanceFails, GetServerResp: tt.args.getInstanceResp, } - got, err := GetServerName(context.Background(), m, "", "", "") + got, err := GetServerName(context.Background(), newMock(m), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetServerName() error = %v, wantErr %v", err, tt.wantErr) return @@ -389,7 +368,7 @@ func TestGetVolumeName(t *testing.T) { want: "", }, { - name: "name in response is nil", + name: "name in response is empty", args: args{ getInstanceResp: &iaas.Volume{ Name: nil, @@ -406,7 +385,7 @@ func TestGetVolumeName(t *testing.T) { GetVolumeFails: tt.args.getInstanceFails, GetVolumeResp: tt.args.getInstanceResp, } - got, err := GetVolumeName(context.Background(), m, "", "", "") + got, err := GetVolumeName(context.Background(), newMock(m), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetVolumeName() error = %v, wantErr %v", err, tt.wantErr) return @@ -433,7 +412,7 @@ func TestGetNetworkName(t *testing.T) { name: "base", args: args{ getInstanceResp: &iaas.Network{ - Name: utils.Ptr("test"), + Name: "test", }, }, want: "test", @@ -454,17 +433,6 @@ func TestGetNetworkName(t *testing.T) { wantErr: true, want: "", }, - { - name: "name in response is nil", - args: args{ - getInstanceResp: &iaas.Network{ - Name: nil, - }, - getInstanceFails: false, - }, - wantErr: true, - want: "", - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -472,7 +440,7 @@ func TestGetNetworkName(t *testing.T) { GetNetworkFails: tt.args.getInstanceFails, GetNetworkResp: tt.args.getInstanceResp, } - got, err := GetNetworkName(context.Background(), m, "", "", "") + got, err := GetNetworkName(context.Background(), newMock(m), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetNetworkName() error = %v, wantErr %v", err, tt.wantErr) return @@ -499,7 +467,7 @@ func TestGetNetworkAreaName(t *testing.T) { name: "base", args: args{ getInstanceResp: &iaas.NetworkArea{ - Name: utils.Ptr("test"), + Name: "test", }, }, want: "test", @@ -521,17 +489,6 @@ func TestGetNetworkAreaName(t *testing.T) { wantErr: true, want: "", }, - { - name: "name in response is nil", - args: args{ - getInstanceResp: &iaas.NetworkArea{ - Name: nil, - }, - getInstanceFails: false, - }, - wantErr: true, - want: "", - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -539,7 +496,7 @@ func TestGetNetworkAreaName(t *testing.T) { GetNetworkAreaFails: tt.args.getInstanceFails, GetNetworkAreaResp: tt.args.getInstanceResp, } - got, err := GetNetworkAreaName(context.Background(), m, "", "") + got, err := GetNetworkAreaName(context.Background(), newMock(m), "", "") if (err != nil) != tt.wantErr { t.Errorf("GetNetworkAreaName() error = %v, wantErr %v", err, tt.wantErr) return @@ -566,7 +523,7 @@ func TestListAttachedProjects(t *testing.T) { name: "base", args: args{ getAttachedProjectsResp: &iaas.ProjectListResponse{ - Items: &[]string{"test"}, + Items: []string{"test"}, }, }, want: []string{"test"}, @@ -585,7 +542,7 @@ func TestListAttachedProjects(t *testing.T) { GetAttachedProjectsFails: tt.args.getAttachedProjectsFails, GetAttachedProjectsResp: tt.args.getAttachedProjectsResp, } - got, err := ListAttachedProjects(context.Background(), m, "", "") + got, err := ListAttachedProjects(context.Background(), newMock(m), "", "") if (err != nil) != tt.wantErr { t.Errorf("GetAttachedProjects() error = %v, wantErr %v", err, tt.wantErr) return @@ -612,7 +569,7 @@ func TestGetNetworkRangePrefix(t *testing.T) { name: "base", args: args{ getNetworkAreaRangeResp: &iaas.NetworkRange{ - Prefix: utils.Ptr("test"), + Prefix: "test", }, }, want: "test", @@ -631,7 +588,7 @@ func TestGetNetworkRangePrefix(t *testing.T) { GetNetworkAreaRangeFails: tt.args.getNetworkAreaRangeFails, GetNetworkAreaRangeResp: tt.args.getNetworkAreaRangeResp, } - got, err := GetNetworkRangePrefix(context.Background(), m, "", "", "", "") + got, err := GetNetworkRangePrefix(context.Background(), newMock(m), "", "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetNetworkRangePrefix() error = %v, wantErr %v", err, tt.wantErr) return @@ -647,7 +604,7 @@ func TestGetRouteFromAPIResponse(t *testing.T) { type args struct { prefix string nexthop string - routes *[]iaas.Route + routes []iaas.Route } tests := []struct { name string @@ -660,72 +617,72 @@ func TestGetRouteFromAPIResponse(t *testing.T) { args: args{ prefix: "1.1.1.0/24", nexthop: "1.1.1.1", - routes: &[]iaas.Route{ + routes: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr("cidrv4"), - Value: utils.Ptr("1.1.1.0/24"), + Type: "cidrv4", + Value: "1.1.1.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr("ipv4"), - Value: utils.Ptr("1.1.1.1"), + Type: "ipv4", + Value: "1.1.1.1", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr("cidrv4"), - Value: utils.Ptr("2.2.2.0/24"), + Type: "cidrv4", + Value: "2.2.2.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr("ipv4"), - Value: utils.Ptr("2.2.2.2"), + Type: "ipv4", + Value: "2.2.2.2", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("3.3.3.0/24"), + Value: "3.3.3.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr("blackhole"), + Type: "blackhole", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("4.4.4.0/24"), + Value: "4.4.4.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr("internet"), + Type: "internet", }, }, }, }, }, want: iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr("cidrv4"), - Value: utils.Ptr("1.1.1.0/24"), + Type: "cidrv4", + Value: "1.1.1.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr("ipv4"), - Value: utils.Ptr("1.1.1.1"), + Type: "ipv4", + Value: "1.1.1.1", }, }, }, @@ -735,135 +692,135 @@ func TestGetRouteFromAPIResponse(t *testing.T) { args: args{ prefix: "4.4.4.0/24", nexthop: "internet", - routes: &[]iaas.Route{ + routes: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("1.1.1.0/24"), + Value: "1.1.1.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Value: utils.Ptr("1.1.1.1"), + Value: "1.1.1.1", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("2.2.2.0/24"), + Value: "2.2.2.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Value: utils.Ptr("2.2.2.2"), + Value: "2.2.2.2", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("3.3.3.0/24"), + Value: "3.3.3.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr("blackhole"), + Type: "blackhole", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("4.4.4.0/24"), + Value: "4.4.4.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr("internet"), + Type: "internet", }, }, }, }, }, want: iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("4.4.4.0/24"), + Value: "4.4.4.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr("internet"), + Type: "internet", }, }, }, }, { - name: "nexthop backhole", + name: "nexthop blackhole", args: args{ prefix: "3.3.3.0/24", nexthop: "blackhole", - routes: &[]iaas.Route{ + routes: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("1.1.1.0/24"), + Value: "1.1.1.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Value: utils.Ptr("1.1.1.1"), + Value: "1.1.1.1", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("2.2.2.0/24"), + Value: "2.2.2.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Value: utils.Ptr("2.2.2.2"), + Value: "2.2.2.2", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("3.3.3.0/24"), + Value: "3.3.3.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr("blackhole"), + Type: "blackhole", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("4.4.4.0/24"), + Value: "4.4.4.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr("internet"), + Type: "internet", }, }, }, }, }, want: iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("3.3.3.0/24"), + Value: "3.3.3.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr("blackhole"), + Type: "blackhole", }, }, }, @@ -873,28 +830,28 @@ func TestGetRouteFromAPIResponse(t *testing.T) { args: args{ prefix: "1.1.1.0/24", nexthop: "1.1.1.1", - routes: &[]iaas.Route{ + routes: []iaas.Route{ { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("2.2.2.0/24"), + Value: "2.2.2.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Value: utils.Ptr("2.2.2.2"), + Value: "2.2.2.2", }, }, }, { - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Value: utils.Ptr("3.3.3.0/24"), + Value: "3.3.3.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Value: utils.Ptr("3.3.3.3"), + Value: "3.3.3.3", }, }, }, @@ -907,7 +864,7 @@ func TestGetRouteFromAPIResponse(t *testing.T) { args: args{ prefix: "1.1.1.0/24", nexthop: "1.1.1.1", - routes: &[]iaas.Route{}, + routes: []iaas.Route{}, }, wantErr: true, }, @@ -929,7 +886,7 @@ func TestGetRouteFromAPIResponse(t *testing.T) { func TestGetNetworkRangeFromAPIResponse(t *testing.T) { type args struct { prefix string - networkRanges *[]iaas.NetworkRange + networkRanges []iaas.NetworkRange } tests := []struct { name string @@ -941,32 +898,32 @@ func TestGetNetworkRangeFromAPIResponse(t *testing.T) { name: "base", args: args{ prefix: "1.1.1.0/24", - networkRanges: &[]iaas.NetworkRange{ + networkRanges: []iaas.NetworkRange{ { - Prefix: utils.Ptr("1.1.1.0/24"), + Prefix: "1.1.1.0/24", }, { - Prefix: utils.Ptr("2.2.2.0/24"), + Prefix: "2.2.2.0/24", }, { - Prefix: utils.Ptr("3.3.3.0/24"), + Prefix: "3.3.3.0/24", }, }, }, want: iaas.NetworkRange{ - Prefix: utils.Ptr("1.1.1.0/24"), + Prefix: "1.1.1.0/24", }, }, { name: "not found", args: args{ prefix: "1.1.1.0/24", - networkRanges: &[]iaas.NetworkRange{ + networkRanges: []iaas.NetworkRange{ { - Prefix: utils.Ptr("2.2.2.0/24"), + Prefix: "2.2.2.0/24", }, { - Prefix: utils.Ptr("3.3.3.0/24"), + Prefix: "3.3.3.0/24", }, }, }, @@ -976,7 +933,7 @@ func TestGetNetworkRangeFromAPIResponse(t *testing.T) { name: "empty", args: args{ prefix: "1.1.1.0/24", - networkRanges: &[]iaas.NetworkRange{}, + networkRanges: []iaas.NetworkRange{}, }, wantErr: true, }, @@ -1005,7 +962,7 @@ func TestGetImageName(t *testing.T) { }{ { name: "successful retrieval", - imageResp: &iaas.Image{Name: utils.Ptr("test-image")}, + imageResp: &iaas.Image{Name: "test-image"}, want: "test-image", wantErr: false, }, @@ -1021,13 +978,6 @@ func TestGetImageName(t *testing.T) { want: "", wantErr: true, }, - { - name: "name in response is nil", - imageErr: false, - imageResp: &iaas.Image{Name: nil}, - want: "", - wantErr: true, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -1035,7 +985,7 @@ func TestGetImageName(t *testing.T) { GetImageFails: tt.imageErr, GetImageResp: tt.imageResp, } - got, err := GetImageName(context.Background(), client, "", "", "") + got, err := GetImageName(context.Background(), newMock(client), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetImageName() error = %v, wantErr %v", err, tt.wantErr) return @@ -1057,7 +1007,7 @@ func TestGetAffinityGroupName(t *testing.T) { }{ { name: "successful retrieval", - affinityResp: &iaas.AffinityGroup{Name: utils.Ptr("test-affinity")}, + affinityResp: &iaas.AffinityGroup{Name: "test-affinity"}, want: "test-affinity", wantErr: false, }, @@ -1067,22 +1017,11 @@ func TestGetAffinityGroupName(t *testing.T) { wantErr: true, }, { - name: "response is nil", - affinityErr: false, - affinityResp: &iaas.AffinityGroup{ - Name: nil, - }, - want: "", - wantErr: true, - }, - { - name: "affinity group name in response is nil", - affinityErr: false, - affinityResp: &iaas.AffinityGroup{ - Name: nil, - }, - want: "", - wantErr: true, + name: "response is nil", + affinityErr: false, + affinityResp: nil, + want: "", + wantErr: true, }, } for _, tt := range tests { @@ -1092,7 +1031,7 @@ func TestGetAffinityGroupName(t *testing.T) { GetAffinityGroupsFails: tt.affinityErr, GetAffinityGroupResp: tt.affinityResp, } - got, err := GetAffinityGroupName(ctx, client, "", "", "") + got, err := GetAffinityGroupName(ctx, newMock(client), "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetAffinityGroupName() error = %v, wantErr %v", err, tt.wantErr) return @@ -1119,7 +1058,7 @@ func TestGetRoutingTableOfAreaName(t *testing.T) { name: "base", args: args{ getInstanceResp: &iaas.RoutingTable{ - Name: utils.Ptr("test"), + Name: "test", }, }, want: "test", @@ -1141,17 +1080,6 @@ func TestGetRoutingTableOfAreaName(t *testing.T) { wantErr: true, want: "", }, - { - name: "name in response is nil", - args: args{ - getInstanceResp: &iaas.RoutingTable{ - Name: nil, - }, - getInstanceFails: false, - }, - wantErr: true, - want: "", - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -1160,7 +1088,7 @@ func TestGetRoutingTableOfAreaName(t *testing.T) { GetRoutingTableOfAreaResp: tt.args.getInstanceResp, } - got, err := GetRoutingTableOfAreaName(context.Background(), m, "", "", "", "") + got, err := GetRoutingTableOfAreaName(context.Background(), newMock(m), "", "", "", "") if (err != nil) != tt.wantErr { t.Errorf("GetRoutingTableOfAreaName() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/internal/pkg/services/network-area/routing-table/utils/utils.go b/internal/pkg/services/network-area/routing-table/utils/utils.go index 9783dd918..708c43352 100644 --- a/internal/pkg/services/network-area/routing-table/utils/utils.go +++ b/internal/pkg/services/network-area/routing-table/utils/utils.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) @@ -19,36 +19,32 @@ type RouteDetails struct { Labels string } -func ExtractRouteDetails(route iaas.Route) RouteDetails { +func ExtractRouteDetails(route *iaas.Route) RouteDetails { var routeDetails RouteDetails - if route.Destination != nil { - if route.Destination.DestinationCIDRv4 != nil { - routeDetails.DestType = utils.PtrString(route.Destination.DestinationCIDRv4.Type) - routeDetails.DestValue = utils.PtrString(route.Destination.DestinationCIDRv4.Value) - } else if route.Destination.DestinationCIDRv6 != nil { - routeDetails.DestType = utils.PtrString(route.Destination.DestinationCIDRv6.Type) - routeDetails.DestValue = utils.PtrString(route.Destination.DestinationCIDRv6.Value) - } + if route.Destination.DestinationCIDRv4 != nil { + routeDetails.DestType = route.Destination.DestinationCIDRv4.Type + routeDetails.DestValue = route.Destination.DestinationCIDRv4.Value + } else if route.Destination.DestinationCIDRv6 != nil { + routeDetails.DestType = route.Destination.DestinationCIDRv6.Type + routeDetails.DestValue = route.Destination.DestinationCIDRv6.Value } - if route.Nexthop != nil { - if route.Nexthop.NexthopIPv4 != nil { - routeDetails.HopType = utils.PtrString(route.Nexthop.NexthopIPv4.Type) - routeDetails.HopValue = utils.PtrString(route.Nexthop.NexthopIPv4.Value) - } else if route.Nexthop.NexthopIPv6 != nil { - routeDetails.HopType = utils.PtrString(route.Nexthop.NexthopIPv6.Type) - routeDetails.HopValue = utils.PtrString(route.Nexthop.NexthopIPv6.Value) - } else if route.Nexthop.NexthopInternet != nil { - routeDetails.HopType = utils.PtrString(route.Nexthop.NexthopInternet.Type) - } else if route.Nexthop.NexthopBlackhole != nil { - routeDetails.HopType = utils.PtrString(route.Nexthop.NexthopBlackhole.Type) - } + if route.Nexthop.NexthopIPv4 != nil { + routeDetails.HopType = route.Nexthop.NexthopIPv4.Type + routeDetails.HopValue = route.Nexthop.NexthopIPv4.Value + } else if route.Nexthop.NexthopIPv6 != nil { + routeDetails.HopType = route.Nexthop.NexthopIPv6.Type + routeDetails.HopValue = route.Nexthop.NexthopIPv6.Value + } else if route.Nexthop.NexthopInternet != nil { + routeDetails.HopType = route.Nexthop.NexthopInternet.Type + } else if route.Nexthop.NexthopBlackhole != nil { + routeDetails.HopType = route.Nexthop.NexthopBlackhole.Type } - if route.Labels != nil && len(*route.Labels) > 0 { + if len(route.Labels) > 0 { stringMap := make(map[string]string) - for key, value := range *route.Labels { + for key, value := range route.Labels { stringMap[key] = fmt.Sprintf("%v", value) } routeDetails.Labels = utils.JoinStringMap(stringMap, ": ", "\n") diff --git a/internal/pkg/services/network-area/routing-table/utils/utils_test.go b/internal/pkg/services/network-area/routing-table/utils/utils_test.go index d5deee061..a4128d537 100644 --- a/internal/pkg/services/network-area/routing-table/utils/utils_test.go +++ b/internal/pkg/services/network-area/routing-table/utils/utils_test.go @@ -5,9 +5,7 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" ) const ipv4 = "ipv4" @@ -32,10 +30,10 @@ func TestExtractRouteDetails(t *testing.T) { { description: "destination only, no nexthop, no labels", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(cidrv4), - Value: utils.Ptr("10.0.0.0/24"), + Type: cidrv4, + Value: "10.0.0.0/24", }, }, }, @@ -47,13 +45,13 @@ func TestExtractRouteDetails(t *testing.T) { { description: "nexthop only, no destination, empty labels map", input: &iaas.Route{ - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(ipv4), - Value: utils.Ptr("10.0.0.1"), + Type: ipv4, + Value: "10.0.0.1", }, }, - Labels: &map[string]interface{}{}, // empty but non-nil + Labels: map[string]interface{}{}, // empty but non-nil }, want: RouteDetails{ HopType: ipv4, @@ -63,14 +61,13 @@ func TestExtractRouteDetails(t *testing.T) { { description: "destination present, nexthop struct nil, labels nil", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv6: &iaas.DestinationCIDRv6{ - Type: utils.Ptr(cidrv6), - Value: utils.Ptr("2001:db8::/32"), + Type: cidrv6, + Value: "2001:db8::/32", }, }, - Nexthop: nil, - Labels: nil, + Labels: nil, }, want: RouteDetails{ DestType: cidrv6, @@ -80,19 +77,19 @@ func TestExtractRouteDetails(t *testing.T) { { description: "CIDRv4 destination, IPv4 nexthop, with labels", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(cidrv4), - Value: utils.Ptr("10.0.0.0/24"), + Type: cidrv4, + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(ipv4), - Value: utils.Ptr("10.0.0.1"), + Type: ipv4, + Value: "10.0.0.1", }, }, - Labels: &map[string]interface{}{ + Labels: map[string]interface{}{ "key": "value", }, }, @@ -107,16 +104,16 @@ func TestExtractRouteDetails(t *testing.T) { { description: "CIDRv6 destination, IPv6 nexthop, with no labels", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv6: &iaas.DestinationCIDRv6{ - Type: utils.Ptr(cidrv6), - Value: utils.Ptr("2001:db8::/32"), + Type: cidrv6, + Value: "2001:db8::/32", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv6: &iaas.NexthopIPv6{ - Type: utils.Ptr(ipv6), - Value: utils.Ptr("2001:db8::1"), + Type: ipv6, + Value: "2001:db8::1", }, }, Labels: nil, @@ -131,15 +128,15 @@ func TestExtractRouteDetails(t *testing.T) { { description: "Internet nexthop without value", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(cidrv4), - Value: utils.Ptr("0.0.0.0/0"), + Type: cidrv4, + Value: "0.0.0.0/0", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopInternet: &iaas.NexthopInternet{ - Type: utils.Ptr("Internet"), + Type: "Internet", }, }, Labels: nil, @@ -154,15 +151,15 @@ func TestExtractRouteDetails(t *testing.T) { { description: "Blackhole nexthop without value and nil labels map", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv6: &iaas.DestinationCIDRv6{ - Type: utils.Ptr(cidrv6), - Value: utils.Ptr("::/0"), + Type: cidrv6, + Value: "::/0", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopBlackhole: &iaas.NexthopBlackhole{ - Type: utils.Ptr("Blackhole"), + Type: "Blackhole", }, }, Labels: nil, @@ -176,16 +173,16 @@ func TestExtractRouteDetails(t *testing.T) { { description: "route with created and updated timestamps", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(cidrv4), - Value: utils.Ptr("10.0.0.0/24"), + Type: cidrv4, + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(ipv4), - Value: utils.Ptr("10.0.0.1"), + Type: ipv4, + Value: "10.0.0.1", }, }, CreatedAt: &created, @@ -204,16 +201,16 @@ func TestExtractRouteDetails(t *testing.T) { { description: "route with created timestamp only", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(cidrv4), - Value: utils.Ptr("10.0.0.0/24"), + Type: cidrv4, + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(ipv4), - Value: utils.Ptr("10.0.0.1"), + Type: ipv4, + Value: "10.0.0.1", }, }, CreatedAt: &created, @@ -231,16 +228,16 @@ func TestExtractRouteDetails(t *testing.T) { { description: "route with updated timestamp only", input: &iaas.Route{ - Destination: &iaas.RouteDestination{ + Destination: iaas.RouteDestination{ DestinationCIDRv4: &iaas.DestinationCIDRv4{ - Type: utils.Ptr(cidrv4), - Value: utils.Ptr("10.0.0.0/24"), + Type: cidrv4, + Value: "10.0.0.0/24", }, }, - Nexthop: &iaas.RouteNexthop{ + Nexthop: iaas.RouteNexthop{ NexthopIPv4: &iaas.NexthopIPv4{ - Type: utils.Ptr(ipv4), - Value: utils.Ptr("10.0.0.1"), + Type: ipv4, + Value: "10.0.0.1", }, }, UpdatedAt: &updated, @@ -259,7 +256,7 @@ func TestExtractRouteDetails(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - got := ExtractRouteDetails(*tt.input) + got := ExtractRouteDetails(tt.input) if diff := cmp.Diff(tt.want, got); diff != "" { t.Fatalf("ExtractRouteDetails() mismatch (-want +got):\n%s", diff) diff --git a/internal/pkg/utils/utils.go b/internal/pkg/utils/utils.go index f4e8a34fb..e798ad116 100644 --- a/internal/pkg/utils/utils.go +++ b/internal/pkg/utils/utils.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/stackitcloud/stackit-cli/internal/pkg/config" ) @@ -182,7 +182,7 @@ type Base64PatchedServer struct { Name *string `json:"name,omitempty"` Status *string `json:"status,omitempty"` AvailabilityZone *string `json:"availabilityZone,omitempty"` - BootVolume *iaas.ServerBootVolume `json:"bootVolume,omitempty"` + BootVolume *iaas.BootVolume `json:"bootVolume,omitempty"` CreatedAt *time.Time `json:"createdAt,omitempty"` ErrorMessage *string `json:"errorMessage,omitempty"` PowerStatus *string `json:"powerStatus,omitempty"` @@ -190,17 +190,17 @@ type Base64PatchedServer struct { ImageId *string `json:"imageId,omitempty"` KeypairName *string `json:"keypairName,omitempty"` MachineType *string `json:"machineType,omitempty"` - Labels *map[string]interface{} `json:"labels,omitempty"` + Labels map[string]interface{} `json:"labels,omitempty"` LaunchedAt *time.Time `json:"launchedAt,omitempty"` MaintenanceWindow *iaas.ServerMaintenance `json:"maintenanceWindow,omitempty"` - Metadata *map[string]interface{} `json:"metadata,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` Networking *iaas.ServerNetworking `json:"networking,omitempty"` - Nics *[]iaas.ServerNetwork `json:"nics,omitempty"` - SecurityGroups *[]string `json:"securityGroups,omitempty"` - ServiceAccountMails *[]string `json:"serviceAccountMails,omitempty"` + Nics []iaas.ServerNetwork `json:"nics,omitempty"` + SecurityGroups []string `json:"securityGroups,omitempty"` + ServiceAccountMails []string `json:"serviceAccountMails,omitempty"` UpdatedAt *time.Time `json:"updatedAt,omitempty"` UserData *Base64Bytes `json:"userData,omitempty"` - Volumes *[]string `json:"volumes,omitempty"` + Volumes []string `json:"volumes,omitempty"` Agent *iaas.ServerAgent `json:"agent,omitempty"` } @@ -220,7 +220,7 @@ func ConvertToBase64PatchedServer(server *iaas.Server) *Base64PatchedServer { return &Base64PatchedServer{ Id: server.Id, - Name: server.Name, + Name: &server.Name, Status: server.Status, AvailabilityZone: server.AvailabilityZone, BootVolume: server.BootVolume, @@ -230,7 +230,7 @@ func ConvertToBase64PatchedServer(server *iaas.Server) *Base64PatchedServer { AffinityGroup: server.AffinityGroup, ImageId: server.ImageId, KeypairName: server.KeypairName, - MachineType: server.MachineType, + MachineType: &server.MachineType, Labels: server.Labels, LaunchedAt: server.LaunchedAt, MaintenanceWindow: server.MaintenanceWindow, diff --git a/internal/pkg/utils/utils_test.go b/internal/pkg/utils/utils_test.go index 484efcec8..a36e336ec 100644 --- a/internal/pkg/utils/utils_test.go +++ b/internal/pkg/utils/utils_test.go @@ -5,8 +5,9 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api" "github.com/spf13/viper" @@ -269,8 +270,8 @@ func TestConvertStringMapToInterfaceMap(t *testing.T) { func TestConvertToBase64PatchedServer(t *testing.T) { now := time.Now() - userData := []byte("test") - emptyUserData := []byte("") + userData := "test" + emptyUserData := "" tests := []struct { name string @@ -286,10 +287,10 @@ func TestConvertToBase64PatchedServer(t *testing.T) { name: "server with user data", input: &iaas.Server{ Id: Ptr("server-123"), - Name: Ptr("test-server"), + Name: "test-server", Status: Ptr("ACTIVE"), AvailabilityZone: Ptr("eu01-1"), - MachineType: Ptr("t1.1"), + MachineType: "t1.1", UserData: &userData, CreatedAt: &now, PowerStatus: Ptr("RUNNING"), @@ -315,10 +316,10 @@ func TestConvertToBase64PatchedServer(t *testing.T) { name: "server with empty user data", input: &iaas.Server{ Id: Ptr("server-456"), - Name: Ptr("test-server-2"), + Name: "test-server-2", Status: Ptr("STOPPED"), AvailabilityZone: Ptr("eu01-2"), - MachineType: Ptr("t1.2"), + MachineType: "t1.2", UserData: &emptyUserData, }, expected: &Base64PatchedServer{ @@ -334,10 +335,10 @@ func TestConvertToBase64PatchedServer(t *testing.T) { name: "server without user data", input: &iaas.Server{ Id: Ptr("server-789"), - Name: Ptr("test-server-3"), + Name: "test-server-3", Status: Ptr("CREATING"), AvailabilityZone: Ptr("eu01-3"), - MachineType: Ptr("t1.3"), + MachineType: "t1.3", UserData: nil, }, expected: &Base64PatchedServer{ @@ -353,10 +354,10 @@ func TestConvertToBase64PatchedServer(t *testing.T) { name: "server with agent", input: &iaas.Server{ Id: Ptr("server-456"), - Name: Ptr("test-server-2"), + Name: "test-server-2", Status: Ptr("STOPPED"), AvailabilityZone: Ptr("eu01-2"), - MachineType: Ptr("t1.2"), + MachineType: "t1.2", UserData: &emptyUserData, Agent: &iaas.ServerAgent{Provisioned: Ptr(true)}, }, @@ -376,17 +377,8 @@ func TestConvertToBase64PatchedServer(t *testing.T) { t.Run(tt.name, func(t *testing.T) { result := ConvertToBase64PatchedServer(tt.input) - if result == nil && tt.expected == nil { - return - } - - if (result == nil && tt.expected != nil) || (result != nil && tt.expected == nil) { - t.Errorf("ConvertToBase64PatchedServer() = %v, want %v", result, tt.expected) - return - } - - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("ConvertToBase64PatchedServer() = %v, want %v", result, tt.expected) + if diff := cmp.Diff(tt.expected, result); diff != "" { + t.Errorf("ConvertToBase64PatchedServer() mismatch (-want +got):\n%s", diff) } }) } @@ -394,9 +386,9 @@ func TestConvertToBase64PatchedServer(t *testing.T) { func TestConvertToBase64PatchedServers(t *testing.T) { now := time.Now() - userData1 := []byte("test1") - userData2 := []byte("test2") - emptyUserData := []byte("") + userData1 := "test1" + userData2 := "test2" + emptyUserData := "" tests := []struct { name string @@ -418,9 +410,9 @@ func TestConvertToBase64PatchedServers(t *testing.T) { input: []iaas.Server{ { Id: Ptr("server-1"), - Name: Ptr("test-server-1"), + Name: "test-server-1", Status: Ptr("ACTIVE"), - MachineType: Ptr("t1.1"), + MachineType: "t1.1", AvailabilityZone: Ptr("eu01-1"), UserData: &userData1, CreatedAt: &now, @@ -443,34 +435,34 @@ func TestConvertToBase64PatchedServers(t *testing.T) { input: []iaas.Server{ { Id: Ptr("server-1"), - Name: Ptr("test-server-1"), + Name: "test-server-1", Status: Ptr("ACTIVE"), - MachineType: Ptr("t1.1"), + MachineType: "t1.1", AvailabilityZone: Ptr("eu01-1"), UserData: &userData1, CreatedAt: &now, }, { Id: Ptr("server-2"), - Name: Ptr("test-server-2"), + Name: "test-server-2", Status: Ptr("STOPPED"), - MachineType: Ptr("t1.2"), + MachineType: "t1.2", AvailabilityZone: Ptr("eu01-2"), UserData: &userData2, }, { Id: Ptr("server-3"), - Name: Ptr("test-server-3"), + Name: "test-server-3", Status: Ptr("CREATING"), - MachineType: Ptr("t1.3"), + MachineType: "t1.3", AvailabilityZone: Ptr("eu01-3"), UserData: &emptyUserData, }, { Id: Ptr("server-4"), - Name: Ptr("test-server-4"), + Name: "test-server-4", Status: Ptr("ERROR"), - MachineType: Ptr("t1.4"), + MachineType: "t1.4", AvailabilityZone: Ptr("eu01-4"), UserData: nil, },