From 4c9e8c84af9eb0f5e6d648424a2c0a14c50a99ee Mon Sep 17 00:00:00 2001 From: GokceGK Date: Mon, 15 Jun 2026 17:16:12 +0200 Subject: [PATCH 1/2] chore(dns): migrate to new SDK structure relates to STACKITCLI-362 --- docs/stackit_dns_record-set_create.md | 4 +- docs/stackit_dns_record-set_update.md | 2 +- docs/stackit_dns_zone_create.md | 12 +-- docs/stackit_dns_zone_update.md | 10 +-- go.mod | 4 +- go.sum | 8 +- internal/cmd/dns/record-set/create/create.go | 35 ++++---- .../cmd/dns/record-set/create/create_test.go | 34 ++++---- internal/cmd/dns/record-set/delete/delete.go | 12 +-- .../cmd/dns/record-set/delete/delete_test.go | 8 +- .../cmd/dns/record-set/describe/describe.go | 22 ++--- .../dns/record-set/describe/describe_test.go | 10 +-- internal/cmd/dns/record-set/list/list.go | 27 +++---- internal/cmd/dns/record-set/list/list_test.go | 16 ++-- internal/cmd/dns/record-set/update/update.go | 26 +++--- .../cmd/dns/record-set/update/update_test.go | 20 ++--- internal/cmd/dns/zone/clone/clone.go | 16 ++-- internal/cmd/dns/zone/clone/clone_test.go | 16 ++-- internal/cmd/dns/zone/create/create.go | 63 +++++++-------- internal/cmd/dns/zone/create/create_test.go | 80 +++++++++---------- internal/cmd/dns/zone/delete/delete.go | 10 +-- internal/cmd/dns/zone/delete/delete_test.go | 8 +- internal/cmd/dns/zone/describe/describe.go | 28 +++---- .../cmd/dns/zone/describe/describe_test.go | 8 +- internal/cmd/dns/zone/list/list.go | 21 ++--- internal/cmd/dns/zone/list/list_test.go | 16 ++-- internal/cmd/dns/zone/update/update.go | 44 +++++----- internal/cmd/dns/zone/update/update_test.go | 56 +++++++------ internal/pkg/services/dns/client/client.go | 2 +- internal/pkg/services/dns/utils/utils.go | 25 +++--- internal/pkg/services/dns/utils/utils_test.go | 53 ++++++------ 31 files changed, 345 insertions(+), 351 deletions(-) diff --git a/docs/stackit_dns_record-set_create.md b/docs/stackit_dns_record-set_create.md index 4f51534ad..9610ed16a 100644 --- a/docs/stackit_dns_record-set_create.md +++ b/docs/stackit_dns_record-set_create.md @@ -24,8 +24,8 @@ stackit dns record-set create [flags] -h, --help Help for "stackit dns record-set create" --name string Name of the record, should be compliant with RFC1035, Section 2.3.4 --record strings Records belonging to the record set - --ttl int Time to live, if not provided defaults to the zone's default TTL - --type string Record type, one of ["A" "AAAA" "SOA" "CNAME" "NS" "MX" "TXT" "SRV" "PTR" "ALIAS" "DNAME" "CAA" "DNSKEY" "DS" "LOC" "NAPTR" "SSHFP" "TLSA" "URI" "CERT" "SVCB" "TYPE" "CSYNC" "HINFO" "HTTPS"] (default "A") + --ttl int32 Time to live, if not provided defaults to the zone's default TTL + --type string Record type, one of ["A" "AAAA" "SOA" "CNAME" "NS" "MX" "TXT" "SRV" "PTR" "ALIAS" "DNAME" "CAA" "DNSKEY" "DS" "LOC" "NAPTR" "SSHFP" "TLSA" "URI" "CERT" "SVCB" "TYPE" "CSYNC" "HINFO" "HTTPS" "unknown_default_open_api"] (default "A") --zone-id string Zone ID ``` diff --git a/docs/stackit_dns_record-set_update.md b/docs/stackit_dns_record-set_update.md index 9d369c4f6..87215ddfa 100644 --- a/docs/stackit_dns_record-set_update.md +++ b/docs/stackit_dns_record-set_update.md @@ -24,7 +24,7 @@ stackit dns record-set update RECORD_SET_ID [flags] -h, --help Help for "stackit dns record-set update" --name string Name of the record, should be compliant with RFC1035, Section 2.3.4 --record strings Records belonging to the record set. If this flag is used, records already created that aren't set when running the command will be deleted - --ttl int Time to live, if not provided defaults to the zone's default TTL + --ttl int32 Time to live, if not provided defaults to the zone's default TTL --zone-id string Zone ID ``` diff --git a/docs/stackit_dns_zone_create.md b/docs/stackit_dns_zone_create.md index 0a0efde1c..08f4f99d5 100644 --- a/docs/stackit_dns_zone_create.md +++ b/docs/stackit_dns_zone_create.md @@ -25,18 +25,18 @@ stackit dns zone create [flags] ``` --acl string Access control list --contact-email string Contact email for the zone - --default-ttl int Default time to live (default 1000) + --default-ttl int32 Default time to live (default 1000) --description string Description of the zone --dns-name string Fully qualified domain name of the DNS zone - --expire-time int Expire time + --expire-time int32 Expire time -h, --help Help for "stackit dns zone create" --is-reverse-zone Is reverse zone --name string User given name of the zone - --negative-cache int Negative cache + --negative-cache int32 Negative cache --primary strings Primary name server for secondary zone - --refresh-time int Refresh time - --retry-time int Retry time - --type string Zone type, one of: ["primary" "secondary"] + --refresh-time int32 Refresh time + --retry-time int32 Retry time + --type string Zone type, one of: ["primary" "secondary" "unknown_default_open_api"] ``` ### Options inherited from parent commands diff --git a/docs/stackit_dns_zone_update.md b/docs/stackit_dns_zone_update.md index 240885c1b..35e375998 100644 --- a/docs/stackit_dns_zone_update.md +++ b/docs/stackit_dns_zone_update.md @@ -22,15 +22,15 @@ stackit dns zone update ZONE_ID [flags] ``` --acl string Access control list --contact-email string Contact email for the zone - --default-ttl int Default time to live (default 1000) + --default-ttl int32 Default time to live (default 1000) --description string Description of the zone - --expire-time int Expire time + --expire-time int32 Expire time -h, --help Help for "stackit dns zone update" --name string User given name of the zone - --negative-cache int Negative cache + --negative-cache int32 Negative cache --primary strings Primary name server for secondary zone - --refresh-time int Refresh time - --retry-time int Retry time + --refresh-time int32 Refresh time + --retry-time int32 Retry time ``` ### Options inherited from parent commands diff --git a/go.mod b/go.mod index 80338dc54..4724b50e3 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/alb v0.14.2 github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0 - github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 + github.com/stackitcloud/stackit-sdk-go/services/dns v0.21.0 github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0 github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.0 @@ -36,8 +36,8 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.2.7 github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0 - github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0 github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.11.0 + github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0 github.com/zalando/go-keyring v0.2.6 golang.org/x/mod v0.34.0 golang.org/x/oauth2 v0.35.0 diff --git a/go.sum b/go.sum index f9f2fe20e..e7d23dbfd 100644 --- a/go.sum +++ b/go.sum @@ -602,8 +602,8 @@ github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu0 github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0/go.mod h1:uYI9pHAA2g84jJN25ejFUxa0/JtfpPZqMDkctQ1BzJk= github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0 h1:Wqxx0PDTL2F5gqI5jjznuJY0TdqECltjA0aa/rHY63U= github.com/stackitcloud/stackit-sdk-go/services/cdn v1.16.0/go.mod h1:MHB1N3EQ9GuAduAQoNS+gb1MjrWJieszbpOso9TQv5s= -github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6 h1:GBRb49x5Nax/oQQaaf2F3kKwv8DQQOL0TQOC0C/v/Ew= -github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.6/go.mod h1:IX9iL3MigDZUmzwswTJMfYvyi118KAHrFMfjJUy5NYk= +github.com/stackitcloud/stackit-sdk-go/services/dns v0.21.0 h1:ZVkptfVCAqpaPWkE+WIopM9XdzqgbVcwmX5L1jZqqx8= +github.com/stackitcloud/stackit-sdk-go/services/dns v0.21.0/go.mod h1:FiYSv3D9rzgEVzi8Mpq5oYZBosrasa5uUYqVdEIbM1U= github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3 h1:TxChb2qbO82JiQEBYClSSD5HZxqKeKJ6dIvkEUCJmbs= github.com/stackitcloud/stackit-sdk-go/services/edge v0.4.3/go.mod h1:KVWvQHb7CQLD9DzA4Np3WmakiCCsrHaCXvFEnOQ7nPk= github.com/stackitcloud/stackit-sdk-go/services/git v0.14.0 h1:VZBneGprCmHqckcSMPs3puBlK8rBpLMtYKmBktwdoVE= @@ -654,10 +654,10 @@ github.com/stackitcloud/stackit-sdk-go/services/sfs v0.9.0 h1:JWAFnskRbNKT8x62pZ github.com/stackitcloud/stackit-sdk-go/services/sfs v0.9.0/go.mod h1:jMlBoXqrPNX5nXbo6oT7exalqilw1jiLPoIp4Cn0CdI= github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0 h1:QoKyQPe8FqDqJLNgE5uRlZ/y1c1GUxjV1DDLu5QEBD8= github.com/stackitcloud/stackit-sdk-go/services/ske v1.11.0/go.mod h1:KhVYCR58wETqdI7Quwhe3OR3BhB2T/b7DzaMsfDnr8g= -github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0 h1:LMgbzhPunuelsIsfyEj/5O/aYfNcg/eGHsnZ7AZOhYg= -github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0/go.mod h1:toIjQk1dhxdUFVyCWJJja0w/0nFpDid8MWX0ukQfvfo= github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.11.0 h1:PwjQeupEnXxhu+uWCUzO/hUfL4yqNblOcZbP2jvaQtU= github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v1.11.0/go.mod h1:AiUoMAqQcOlMgDtkVJlqI7P/VGD5xjN3dYjERGnwN/M= +github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0 h1:LMgbzhPunuelsIsfyEj/5O/aYfNcg/eGHsnZ7AZOhYg= +github.com/stackitcloud/stackit-sdk-go/services/vpn v0.14.0/go.mod h1:toIjQk1dhxdUFVyCWJJja0w/0nFpDid8MWX0ukQfvfo= github.com/stbenjam/no-sprintf-host-port v0.3.1 h1:AyX7+dxI4IdLBPtDbsGAyqiTSLpCP9hWRrXQDU4Cm/g= github.com/stbenjam/no-sprintf-host-port v0.3.1/go.mod h1:ODbZesTCHMVKthBHskvUUexdcNHAQRXk9NpSsL8p/HQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/cmd/dns/record-set/create/create.go b/internal/cmd/dns/record-set/create/create.go index 1cf8c448b..fa63bdb9a 100644 --- a/internal/cmd/dns/record-set/create/create.go +++ b/internal/cmd/dns/record-set/create/create.go @@ -4,12 +4,12 @@ import ( "context" "fmt" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -20,7 +20,6 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) const ( @@ -41,8 +40,8 @@ type inputModel struct { Comment *string Name *string Records []string - TTL *int64 - Type dns.CreateRecordSetPayloadTypes + TTL *int32 + Type dns.CreateRecordSetPayloadType } func NewCmd(params *types.CmdParams) *cobra.Command { @@ -69,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId @@ -87,12 +86,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("create DNS record set: %w", err) } - recordSetId := *resp.Rrset.Id + recordSetId := resp.Rrset.Id // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Creating record set", func() error { - _, err = wait.CreateRecordSetWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId, recordSetId).WaitWithContext(ctx) + _, err = wait.CreateRecordSetWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId, recordSetId).WaitWithContext(ctx) return err }) if err != nil { @@ -109,14 +108,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command { func configureFlags(cmd *cobra.Command) { var typeFlagOptions []string - for _, val := range dns.AllowedCreateRecordSetPayloadTypesEnumValues { + for _, val := range dns.AllowedCreateRecordSetPayloadTypeEnumValues { typeFlagOptions = append(typeFlagOptions, string(val)) } cmd.Flags().Var(flags.UUIDFlag(), zoneIdFlag, "Zone ID") cmd.Flags().String(commentFlag, "", "User comment") cmd.Flags().String(nameFlag, "", "Name of the record, should be compliant with RFC1035, Section 2.3.4") - cmd.Flags().Int64(ttlFlag, 0, "Time to live, if not provided defaults to the zone's default TTL") + cmd.Flags().Int32(ttlFlag, 0, "Time to live, if not provided defaults to the zone's default TTL") cmd.Flags().StringSlice(recordFlag, []string{}, "Records belonging to the record set") cmd.Flags().Var(flags.EnumFlag(false, string(defaultType), typeFlagOptions...), typeFlag, fmt.Sprintf("Record type, one of %q", typeFlagOptions)) @@ -138,8 +137,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, Comment: flags.FlagToStringPointer(p, cmd, commentFlag), Name: flags.FlagToStringPointer(p, cmd, nameFlag), Records: flags.FlagToStringSliceValue(p, cmd, recordFlag), - TTL: flags.FlagToInt64Pointer(p, cmd, ttlFlag), - Type: dns.CreateRecordSetPayloadTypes(recordType), + TTL: flags.FlagToInt32Pointer(p, cmd, ttlFlag), + Type: dns.CreateRecordSetPayloadType(recordType), } if model.Type == txtType { @@ -163,16 +162,16 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiCreateRecordSetRequest { records := make([]dns.RecordPayload, 0) for _, r := range model.Records { - records = append(records, dns.RecordPayload{Content: utils.Ptr(r)}) + records = append(records, dns.RecordPayload{Content: r}) } - req := apiClient.CreateRecordSet(ctx, model.ProjectId, model.ZoneId) + req := apiClient.DefaultAPI.CreateRecordSet(ctx, model.ProjectId, model.ZoneId) req = req.CreateRecordSetPayload(dns.CreateRecordSetPayload{ Comment: model.Comment, - Name: model.Name, - Records: &records, + Name: *model.Name, + Records: records, Ttl: model.TTL, - Type: &model.Type, + Type: model.Type, }) return req } @@ -186,7 +185,7 @@ func outputResult(p *print.Printer, model *inputModel, zoneLabel string, resp *d if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s record set for zone %s. Record set ID: %s\n", operationState, zoneLabel, utils.PtrString(resp.Rrset.Id)) + p.Outputf("%s record set for zone %s. Record set ID: %s\n", operationState, zoneLabel, resp.Rrset.Id) return nil }) } diff --git a/internal/cmd/dns/record-set/create/create_test.go b/internal/cmd/dns/record-set/create/create_test.go index 483c47d76..03c8a637c 100644 --- a/internal/cmd/dns/record-set/create/create_test.go +++ b/internal/cmd/dns/record-set/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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -20,7 +20,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() @@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Name: utils.Ptr("example.com"), Comment: utils.Ptr("comment"), Records: []string{"1.1.1.1"}, - TTL: utils.Ptr(int64(3600)), + TTL: utils.Ptr(int32(3600)), Type: "SOA", } for _, mod := range mods { @@ -66,15 +66,15 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiCreateRecordSetRequest)) dns.ApiCreateRecordSetRequest { - request := testClient.CreateRecordSet(testCtx, testProjectId, testZoneId) + request := testClient.DefaultAPI.CreateRecordSet(testCtx, testProjectId, testZoneId) request = request.CreateRecordSetPayload(dns.CreateRecordSetPayload{ - Name: utils.Ptr("example.com"), + Name: "example.com", Comment: utils.Ptr("comment"), - Records: &[]dns.RecordPayload{ - {Content: utils.Ptr("1.1.1.1")}, + Records: []dns.RecordPayload{ + {Content: "1.1.1.1"}, }, - Ttl: utils.Ptr(int64(3600)), - Type: dns.CREATERECORDSETPAYLOADTYPE_SOA.Ptr(), + Ttl: utils.Ptr(int32(3600)), + Type: dns.CREATERECORDSETPAYLOADTYPE_SOA, }) for _, mod := range mods { mod(&request) @@ -142,7 +142,7 @@ func TestParseInput(t *testing.T) { Name: utils.Ptr(""), Comment: utils.Ptr(""), Records: []string{"1.1.1.1"}, - TTL: utils.Ptr(int64(0)), + TTL: utils.Ptr(int32(0)), Type: defaultType, }, }, @@ -297,13 +297,13 @@ func TestBuildRequest(t *testing.T) { Records: []string{"1.1.1.1"}, Type: defaultType, }, - expectedRequest: testClient.CreateRecordSet(testCtx, testProjectId, testZoneId). + expectedRequest: testClient.DefaultAPI.CreateRecordSet(testCtx, testProjectId, testZoneId). CreateRecordSetPayload(dns.CreateRecordSetPayload{ - Name: utils.Ptr("example.com"), - Records: &[]dns.RecordPayload{ - {Content: utils.Ptr("1.1.1.1")}, + Name: "example.com", + Records: []dns.RecordPayload{ + {Content: "1.1.1.1"}, }, - Type: utils.Ptr(defaultType), + Type: defaultType, }), }, } @@ -313,7 +313,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -343,7 +343,7 @@ func TestOutputResult(t *testing.T) { name: "only record set as argument", args: args{ model: fixtureInputModel(), - resp: &dns.RecordSetResponse{Rrset: &dns.RecordSet{}}, + resp: &dns.RecordSetResponse{Rrset: dns.RecordSet{}}, }, wantErr: false, }, diff --git a/internal/cmd/dns/record-set/delete/delete.go b/internal/cmd/dns/record-set/delete/delete.go index ff1478ccc..85448ecbf 100644 --- a/internal/cmd/dns/record-set/delete/delete.go +++ b/internal/cmd/dns/record-set/delete/delete.go @@ -18,8 +18,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" ) const ( @@ -58,13 +58,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId } - recordSetLabel, err := dnsUtils.GetRecordSetName(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId) + recordSetLabel, err := dnsUtils.GetRecordSetName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId, model.RecordSetId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get record set name: %v", err) recordSetLabel = model.RecordSetId @@ -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, "Deleting record set", func() error { - _, err = wait.DeleteRecordSetWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId).WaitWithContext(ctx) + _, err = wait.DeleteRecordSetWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId, model.RecordSetId).WaitWithContext(ctx) return err }) if err != nil { @@ -135,6 +135,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiDeleteRecordSetRequest { - req := apiClient.DeleteRecordSet(ctx, model.ProjectId, model.ZoneId, model.RecordSetId) + req := apiClient.DefaultAPI.DeleteRecordSet(ctx, model.ProjectId, model.ZoneId, model.RecordSetId) return req } diff --git a/internal/cmd/dns/record-set/delete/delete_test.go b/internal/cmd/dns/record-set/delete/delete_test.go index 46a5c6d28..13b08f852 100644 --- a/internal/cmd/dns/record-set/delete/delete_test.go +++ b/internal/cmd/dns/record-set/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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() var testRecordSetId = uuid.NewString() @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiDeleteRecordSetRequest)) dns.ApiDeleteRecordSetRequest { - request := testClient.DeleteRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId) + request := testClient.DefaultAPI.DeleteRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId) for _, mod := range mods { mod(&request) } @@ -187,7 +187,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/dns/record-set/describe/describe.go b/internal/cmd/dns/record-set/describe/describe.go index dabe1d5c1..6c7bde12e 100644 --- a/internal/cmd/dns/record-set/describe/describe.go +++ b/internal/cmd/dns/record-set/describe/describe.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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) const ( @@ -68,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } recordSet := resp.Rrset - return outputResult(params.Printer, model.OutputFormat, recordSet) + return outputResult(params.Printer, model.OutputFormat, &recordSet) }, } configureFlags(cmd) @@ -101,7 +101,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiGetRecordSetRequest { - req := apiClient.GetRecordSet(ctx, model.ProjectId, model.ZoneId, model.RecordSetId) + req := apiClient.DefaultAPI.GetRecordSet(ctx, model.ProjectId, model.ZoneId, model.RecordSetId) return req } @@ -111,22 +111,22 @@ func outputResult(p *print.Printer, outputFormat string, recordSet *dns.RecordSe } return p.OutputResult(outputFormat, recordSet, func() error { - recordsData := make([]string, 0, len(*recordSet.Records)) - for _, r := range *recordSet.Records { - recordsData = append(recordsData, *r.Content) + recordsData := make([]string, 0, len(recordSet.Records)) + for _, r := range recordSet.Records { + recordsData = append(recordsData, r.Content) } recordsDataJoin := strings.Join(recordsData, ", ") table := tables.NewTable() - table.AddRow("ID", utils.PtrString(recordSet.Id)) + table.AddRow("ID", recordSet.Id) table.AddSeparator() - table.AddRow("NAME", utils.PtrString(recordSet.Name)) + table.AddRow("NAME", recordSet.Name) table.AddSeparator() - table.AddRow("STATE", utils.PtrString(recordSet.State)) + table.AddRow("STATE", recordSet.State) table.AddSeparator() - table.AddRow("TTL", utils.PtrString(recordSet.Ttl)) + table.AddRow("TTL", recordSet.Ttl) table.AddSeparator() - table.AddRow("TYPE", utils.PtrString(recordSet.Type)) + table.AddRow("TYPE", recordSet.Type) table.AddSeparator() table.AddRow("RECORDS DATA", recordsDataJoin) err := table.Display(p) diff --git a/internal/cmd/dns/record-set/describe/describe_test.go b/internal/cmd/dns/record-set/describe/describe_test.go index 72b8d07fd..e0d3ce184 100644 --- a/internal/cmd/dns/record-set/describe/describe_test.go +++ b/internal/cmd/dns/record-set/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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -17,7 +17,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() var testRecordSetId = uuid.NewString() @@ -59,7 +59,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiGetRecordSetRequest)) dns.ApiGetRecordSetRequest { - request := testClient.GetRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId) + request := testClient.DefaultAPI.GetRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId) for _, mod := range mods { mod(&request) } @@ -188,7 +188,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -216,7 +216,7 @@ func TestOutputResult(t *testing.T) { { name: "only record set as argument", args: args{ - recordSet: &dns.RecordSet{Records: &[]dns.Record{}}, + recordSet: &dns.RecordSet{Records: []dns.Record{}}, }, wantErr: false, }, diff --git a/internal/cmd/dns/record-set/list/list.go b/internal/cmd/dns/record-set/list/list.go index dfd02612c..64f984a8a 100644 --- a/internal/cmd/dns/record-set/list/list.go +++ b/internal/cmd/dns/record-set/list/list.go @@ -9,7 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -20,7 +20,6 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) const ( @@ -88,12 +87,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Fetch record sets - recordSets, err := fetchRecordSets(ctx, model, apiClient) + recordSets, err := fetchRecordSets(ctx, model, apiClient.DefaultAPI) if err != nil { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId @@ -184,7 +183,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient dnsClient, p req = req.NameLike(*model.NameLike) } if model.OrderByName != nil { - req = req.OrderByName(strings.ToUpper(*model.OrderByName)) + req = req.OrderByName(dns.ListRecordSetsOrderByNameParameter(strings.ToUpper(*model.OrderByName))) } // check integer overflows @@ -220,7 +219,7 @@ func fetchRecordSets(ctx context.Context, model *inputModel, apiClient dnsClient if err != nil { return nil, fmt.Errorf("get DNS record sets: %w", err) } - respRecordSets := *resp.RrSets + respRecordSets := resp.RrSets if len(respRecordSets) == 0 { break } @@ -250,17 +249,17 @@ func outputResult(p *print.Printer, outputFormat, zoneLabel string, recordSets [ table.SetHeader("ID", "NAME", "STATUS", "TTL", "TYPE", "RECORD DATA") for i := range recordSets { rs := recordSets[i] - recordData := make([]string, 0, len(*rs.Records)) - for _, r := range *rs.Records { - recordData = append(recordData, *r.Content) + recordData := make([]string, 0, len(rs.Records)) + for _, r := range rs.Records { + recordData = append(recordData, r.Content) } recordDataJoin := strings.Join(recordData, ", ") table.AddRow( - utils.PtrString(rs.Id), - utils.PtrString(rs.Name), - utils.PtrString(rs.State), - utils.PtrString(rs.Ttl), - utils.PtrString(rs.Type), + rs.Id, + rs.Name, + rs.State, + rs.Ttl, + rs.Type, recordDataJoin, ) } diff --git a/internal/cmd/dns/record-set/list/list_test.go b/internal/cmd/dns/record-set/list/list_test.go index 99b9f4233..08bad82db 100644 --- a/internal/cmd/dns/record-set/list/list_test.go +++ b/internal/cmd/dns/record-set/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -23,7 +23,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() @@ -58,7 +58,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiListRecordSetsRequest)) dns.ApiListRecordSetsRequest { - request := testClient.ListRecordSets(testCtx, testProjectId, testZoneId) + request := testClient.DefaultAPI.ListRecordSets(testCtx, testProjectId, testZoneId) request = request.NameLike("some-pattern") request = request.OrderByName("ASC") request = request.PageSize(pageSizeDefault) @@ -273,16 +273,16 @@ func TestBuildRequest(t *testing.T) { PageSize: 10, }, page: 1, - expectedRequest: testClient.ListRecordSets(testCtx, testProjectId, testZoneId).Page(1).PageSize(10).StateNeq(deleteSucceededState), + expectedRequest: testClient.DefaultAPI.ListRecordSets(testCtx, testProjectId, testZoneId).Page(1).PageSize(10).StateNeq(deleteSucceededState), }, } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - request := buildRequest(testCtx, tt.model, testClient, tt.page) + request := buildRequest(testCtx, tt.model, testClient.DefaultAPI, tt.page) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -420,7 +420,7 @@ func TestFetchRecordSets(t *testing.T) { recordSets := make([]dns.RecordSet, numItemsToReturn) mockedResp := dns.ListRecordSetsResponse{ - RrSets: &recordSets, + RrSets: recordSets, } mockedRespBytes, err := json.Marshal(mockedResp) @@ -443,7 +443,7 @@ func TestFetchRecordSets(t *testing.T) { t.Fatalf("Failed to initialize client: %v", err) } - recordSets, err := fetchRecordSets(testCtx, tt.model, client) + recordSets, err := fetchRecordSets(testCtx, tt.model, client.DefaultAPI) if err != nil { if !tt.apiCallFails { t.Fatalf("did not fail on invalid input") diff --git a/internal/cmd/dns/record-set/update/update.go b/internal/cmd/dns/record-set/update/update.go index 6246ff58f..749d0456a 100644 --- a/internal/cmd/dns/record-set/update/update.go +++ b/internal/cmd/dns/record-set/update/update.go @@ -18,8 +18,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" ) const ( @@ -40,7 +40,7 @@ type inputModel struct { Comment *string Name *string Records *[]string - TTL *int64 + TTL *int32 Type *string } @@ -68,19 +68,19 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId } - recordSetLabel, err := dnsUtils.GetRecordSetName(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId) + recordSetLabel, err := dnsUtils.GetRecordSetName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId, model.RecordSetId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get record set name: %v", err) recordSetLabel = model.RecordSetId } - typeLabel, err := dnsUtils.GetRecordSetType(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId) + typeLabel, err := dnsUtils.GetRecordSetType(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId, model.RecordSetId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get record set type: %v", err) } @@ -109,7 +109,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 record set", func() error { - _, err = wait.PartialUpdateRecordSetWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId).WaitWithContext(ctx) + _, err = wait.PartialUpdateRecordSetWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId, model.RecordSetId).WaitWithContext(ctx) return err }) if err != nil { @@ -133,7 +133,7 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), zoneIdFlag, "Zone ID") cmd.Flags().String(commentFlag, "", "User comment") cmd.Flags().String(nameFlag, "", "Name of the record, should be compliant with RFC1035, Section 2.3.4") - cmd.Flags().Int64(ttlFlag, 0, "Time to live, if not provided defaults to the zone's default TTL") + cmd.Flags().Int32(ttlFlag, 0, "Time to live, if not provided defaults to the zone's default TTL") cmd.Flags().StringSlice(recordFlag, []string{}, "Records belonging to the record set. If this flag is used, records already created that aren't set when running the command will be deleted") err := flags.MarkFlagsRequired(cmd, zoneIdFlag) @@ -152,7 +152,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu comment := flags.FlagToStringPointer(p, cmd, commentFlag) name := flags.FlagToStringPointer(p, cmd, nameFlag) records := flags.FlagToStringSlicePointer(p, cmd, recordFlag) - ttl := flags.FlagToInt64Pointer(p, cmd, ttlFlag) + ttl := flags.FlagToInt32Pointer(p, cmd, ttlFlag) if comment == nil && name == nil && records == nil && ttl == nil { return nil, &errors.EmptyUpdateError{} @@ -194,15 +194,15 @@ func parseTxtRecord(records *[]string) error { } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiPartialUpdateRecordSetRequest { - var records *[]dns.RecordPayload = nil + var records []dns.RecordPayload = nil if model.Records != nil { - records = utils.Ptr(make([]dns.RecordPayload, 0)) + records = make([]dns.RecordPayload, 0) for _, r := range *model.Records { - records = utils.Ptr(append(*records, dns.RecordPayload{Content: utils.Ptr(r)})) + records = append(records, dns.RecordPayload{Content: r}) } } - req := apiClient.PartialUpdateRecordSet(ctx, model.ProjectId, model.ZoneId, model.RecordSetId) + req := apiClient.DefaultAPI.PartialUpdateRecordSet(ctx, model.ProjectId, model.ZoneId, model.RecordSetId) req = req.PartialUpdateRecordSetPayload(dns.PartialUpdateRecordSetPayload{ Comment: model.Comment, Name: model.Name, diff --git a/internal/cmd/dns/record-set/update/update_test.go b/internal/cmd/dns/record-set/update/update_test.go index 80bb01c97..03586da3c 100644 --- a/internal/cmd/dns/record-set/update/update_test.go +++ b/internal/cmd/dns/record-set/update/update_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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() var testRecordSetId = uuid.NewString() @@ -65,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { Name: utils.Ptr("example.com"), Comment: utils.Ptr("comment"), Records: &[]string{"1.1.1.1"}, - TTL: utils.Ptr(int64(3600)), + TTL: utils.Ptr(int32(3600)), } for _, mod := range mods { mod(model) @@ -74,14 +74,14 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiPartialUpdateRecordSetRequest)) dns.ApiPartialUpdateRecordSetRequest { - request := testClient.PartialUpdateRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId) + request := testClient.DefaultAPI.PartialUpdateRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId) request = request.PartialUpdateRecordSetPayload(dns.PartialUpdateRecordSetPayload{ Name: utils.Ptr("example.com"), Comment: utils.Ptr("comment"), - Records: &[]dns.RecordPayload{ - {Content: utils.Ptr("1.1.1.1")}, + Records: []dns.RecordPayload{ + {Content: "1.1.1.1"}, }, - Ttl: utils.Ptr(int64(3600)), + Ttl: utils.Ptr(int32(3600)), }) req := &request for _, mod := range mods { @@ -163,7 +163,7 @@ func TestParseInput(t *testing.T) { Name: utils.Ptr(""), Comment: utils.Ptr(""), Records: &[]string{"1.1.1.1"}, - TTL: utils.Ptr(int64(0)), + TTL: utils.Ptr(int32(0)), }, }, { @@ -398,7 +398,7 @@ func TestBuildRequest(t *testing.T) { ZoneId: testZoneId, RecordSetId: testRecordSetId, }, - expectedRequest: testClient.PartialUpdateRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId). + expectedRequest: testClient.DefaultAPI.PartialUpdateRecordSet(testCtx, testProjectId, testZoneId, testRecordSetId). PartialUpdateRecordSetPayload(dns.PartialUpdateRecordSetPayload{}), }, } @@ -408,7 +408,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/dns/zone/clone/clone.go b/internal/cmd/dns/zone/clone/clone.go index de171a2be..e56e9de89 100644 --- a/internal/cmd/dns/zone/clone/clone.go +++ b/internal/cmd/dns/zone/clone/clone.go @@ -18,8 +18,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" ) const ( @@ -69,7 +69,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId @@ -87,12 +87,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("clone DNS zone: %w", err) } - zoneId := *resp.Zone.Id + zoneId := resp.Zone.Id // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Cloning zone", func() error { - _, err = wait.CreateZoneWaitHandler(ctx, apiClient, model.ProjectId, zoneId).WaitWithContext(ctx) + _, err = wait.CreateZoneWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, zoneId).WaitWithContext(ctx) return err }) if err != nil { @@ -139,10 +139,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiCloneZoneRequest { - req := apiClient.CloneZone(ctx, model.ProjectId, model.ZoneId) + req := apiClient.DefaultAPI.CloneZone(ctx, model.ProjectId, model.ZoneId) req = req.CloneZonePayload(dns.CloneZonePayload{ Name: model.Name, - DnsName: model.DnsName, + DnsName: *model.DnsName, Description: model.Description, AdjustRecords: model.AdjustRecords, }) @@ -158,7 +158,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered cloning of" } - p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Zone.Id)) + p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, resp.Zone.Id) return nil }) } diff --git a/internal/cmd/dns/zone/clone/clone_test.go b/internal/cmd/dns/zone/clone/clone_test.go index 9e1f9ff06..7490434f7 100644 --- a/internal/cmd/dns/zone/clone/clone_test.go +++ b/internal/cmd/dns/zone/clone/clone_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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -18,7 +18,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() @@ -65,10 +65,10 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiCloneZoneRequest)) dns.ApiCloneZoneRequest { - request := testClient.CloneZone(testCtx, testProjectId, testZoneId) + request := testClient.DefaultAPI.CloneZone(testCtx, testProjectId, testZoneId) request = request.CloneZonePayload(dns.CloneZonePayload{ Name: utils.Ptr("example"), - DnsName: utils.Ptr("example.com"), + DnsName: "example.com", Description: utils.Ptr("Example"), AdjustRecords: utils.Ptr(false), }) @@ -196,9 +196,9 @@ func TestBuildRequest(t *testing.T) { DnsName: utils.Ptr("example.com"), ZoneId: testZoneId, }, - expectedRequest: testClient.CloneZone(testCtx, testProjectId, testZoneId). + expectedRequest: testClient.DefaultAPI.CloneZone(testCtx, testProjectId, testZoneId). CloneZonePayload(dns.CloneZonePayload{ - DnsName: utils.Ptr("example.com"), + DnsName: "example.com", }), }, } @@ -208,7 +208,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -238,7 +238,7 @@ func TestOutputResult(t *testing.T) { name: "only zone response as argument", args: args{ model: fixtureInputModel(), - resp: &dns.ZoneResponse{Zone: &dns.Zone{}}, + resp: &dns.ZoneResponse{Zone: dns.Zone{}}, }, wantErr: false, }, diff --git a/internal/cmd/dns/zone/create/create.go b/internal/cmd/dns/zone/create/create.go index 5b68f97b8..ffafca427 100644 --- a/internal/cmd/dns/zone/create/create.go +++ b/internal/cmd/dns/zone/create/create.go @@ -15,11 +15,10 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" ) const ( @@ -40,17 +39,17 @@ const ( type inputModel struct { *globalflags.GlobalFlagModel - Name *string - DnsName *string - DefaultTTL *int64 - Primaries *[]string + Name string + DnsName string + DefaultTTL *int32 + Primaries []string Acl *string - Type *dns.CreateZonePayloadTypes - RetryTime *int64 - RefreshTime *int64 - NegativeCache *int64 + Type *dns.CreateZonePayloadType + RetryTime *int32 + RefreshTime *int32 + NegativeCache *int32 IsReverseZone *bool - ExpireTime *int64 + ExpireTime *int32 Description *string ContactEmail *string } @@ -100,12 +99,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { if err != nil { return fmt.Errorf("create DNS zone: %w", err) } - zoneId := *resp.Zone.Id + zoneId := resp.Zone.Id // Wait for async operation, if async mode not enabled if !model.Async { err := spinner.Run(params.Printer, "Creating zone", func() error { - _, err = wait.CreateZoneWaitHandler(ctx, apiClient, model.ProjectId, zoneId).WaitWithContext(ctx) + _, err = wait.CreateZoneWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, zoneId).WaitWithContext(ctx) return err }) if err != nil { @@ -122,21 +121,21 @@ func NewCmd(params *types.CmdParams) *cobra.Command { func configureFlags(cmd *cobra.Command) { var typeFlagOptions []string - for _, val := range dns.AllowedCreateZonePayloadTypesEnumValues { + for _, val := range dns.AllowedCreateZonePayloadTypeEnumValues { typeFlagOptions = append(typeFlagOptions, string(val)) } cmd.Flags().String(nameFlag, "", "User given name of the zone") cmd.Flags().String(dnsNameFlag, "", "Fully qualified domain name of the DNS zone") - cmd.Flags().Int64(defaultTTLFlag, 1000, "Default time to live") + cmd.Flags().Int32(defaultTTLFlag, 1000, "Default time to live") cmd.Flags().StringSlice(primaryFlag, []string{}, "Primary name server for secondary zone") cmd.Flags().String(aclFlag, "", "Access control list") cmd.Flags().Var(flags.EnumFlag(false, "", append(typeFlagOptions, "")...), typeFlag, fmt.Sprintf("Zone type, one of: %q", typeFlagOptions)) - cmd.Flags().Int64(retryTimeFlag, 0, "Retry time") - cmd.Flags().Int64(refreshTimeFlag, 0, "Refresh time") - cmd.Flags().Int64(negativeCacheFlag, 0, "Negative cache") + cmd.Flags().Int32(retryTimeFlag, 0, "Retry time") + cmd.Flags().Int32(refreshTimeFlag, 0, "Refresh time") + cmd.Flags().Int32(negativeCacheFlag, 0, "Negative cache") cmd.Flags().Bool(isReverseZoneFlag, false, "Is reverse zone") - cmd.Flags().Int64(expireTimeFlag, 0, "Expire time") + cmd.Flags().Int32(expireTimeFlag, 0, "Expire time") cmd.Flags().String(descriptionFlag, "", "Description of the zone") cmd.Flags().String(contactEmailFlag, "", "Contact email for the zone") @@ -150,24 +149,24 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, return nil, &errors.ProjectIdError{} } - var zoneType *dns.CreateZonePayloadTypes + var zoneType *dns.CreateZonePayloadType if zoneTypeString := flags.FlagToStringPointer(p, cmd, typeFlag); zoneTypeString != nil && *zoneTypeString != "" { - zoneType = dns.CreateZonePayloadTypes(*zoneTypeString).Ptr() + zoneType = dns.CreateZonePayloadType(*zoneTypeString).Ptr() } model := inputModel{ GlobalFlagModel: globalFlags, - Name: flags.FlagToStringPointer(p, cmd, nameFlag), - DnsName: flags.FlagToStringPointer(p, cmd, dnsNameFlag), - DefaultTTL: flags.FlagToInt64Pointer(p, cmd, defaultTTLFlag), - Primaries: flags.FlagToStringSlicePointer(p, cmd, primaryFlag), + Name: flags.FlagToStringValue(p, cmd, nameFlag), + DnsName: flags.FlagToStringValue(p, cmd, dnsNameFlag), + DefaultTTL: flags.FlagToInt32Pointer(p, cmd, defaultTTLFlag), + Primaries: flags.FlagToStringSliceValue(p, cmd, primaryFlag), Acl: flags.FlagToStringPointer(p, cmd, aclFlag), Type: zoneType, - RetryTime: flags.FlagToInt64Pointer(p, cmd, retryTimeFlag), - RefreshTime: flags.FlagToInt64Pointer(p, cmd, refreshTimeFlag), - NegativeCache: flags.FlagToInt64Pointer(p, cmd, negativeCacheFlag), + RetryTime: flags.FlagToInt32Pointer(p, cmd, retryTimeFlag), + RefreshTime: flags.FlagToInt32Pointer(p, cmd, refreshTimeFlag), + NegativeCache: flags.FlagToInt32Pointer(p, cmd, negativeCacheFlag), IsReverseZone: flags.FlagToBoolPointer(p, cmd, isReverseZoneFlag), - ExpireTime: flags.FlagToInt64Pointer(p, cmd, expireTimeFlag), + ExpireTime: flags.FlagToInt32Pointer(p, cmd, expireTimeFlag), Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), ContactEmail: flags.FlagToStringPointer(p, cmd, contactEmailFlag), } @@ -177,7 +176,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiCreateZoneRequest { - req := apiClient.CreateZone(ctx, model.ProjectId) + req := apiClient.DefaultAPI.CreateZone(ctx, model.ProjectId) req = req.CreateZonePayload(dns.CreateZonePayload{ Name: model.Name, DnsName: model.DnsName, @@ -205,7 +204,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Zone.Id)) + p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, resp.Zone.Id) return nil }) } diff --git a/internal/cmd/dns/zone/create/create_test.go b/internal/cmd/dns/zone/create/create_test.go index aed0ffe2e..84ecf724d 100644 --- a/internal/cmd/dns/zone/create/create_test.go +++ b/internal/cmd/dns/zone/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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -18,7 +18,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -50,17 +50,17 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr("example"), - DnsName: utils.Ptr("example.com"), - DefaultTTL: utils.Ptr(int64(3600)), - Primaries: utils.Ptr([]string{"1.1.1.1"}), + Name: "example", + DnsName: "example.com", + DefaultTTL: utils.Ptr(int32(3600)), + Primaries: []string{"1.1.1.1"}, Acl: utils.Ptr("0.0.0.0/0"), Type: dns.CREATEZONEPAYLOADTYPE_PRIMARY.Ptr(), - RetryTime: utils.Ptr(int64(600)), - RefreshTime: utils.Ptr(int64(3600)), - NegativeCache: utils.Ptr(int64(60)), + RetryTime: utils.Ptr(int32(600)), + RefreshTime: utils.Ptr(int32(3600)), + NegativeCache: utils.Ptr(int32(60)), IsReverseZone: utils.Ptr(false), - ExpireTime: utils.Ptr(int64(36000000)), + ExpireTime: utils.Ptr(int32(36000000)), Description: utils.Ptr("Example"), ContactEmail: utils.Ptr("example@example.com"), } @@ -71,19 +71,19 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiCreateZoneRequest)) dns.ApiCreateZoneRequest { - request := testClient.CreateZone(testCtx, testProjectId) + request := testClient.DefaultAPI.CreateZone(testCtx, testProjectId) request = request.CreateZonePayload(dns.CreateZonePayload{ - Name: utils.Ptr("example"), - DnsName: utils.Ptr("example.com"), - DefaultTTL: utils.Ptr(int64(3600)), - Primaries: utils.Ptr([]string{"1.1.1.1"}), + Name: "example", + DnsName: "example.com", + DefaultTTL: utils.Ptr(int32(3600)), + Primaries: []string{"1.1.1.1"}, Acl: utils.Ptr("0.0.0.0/0"), Type: dns.CREATEZONEPAYLOADTYPE_PRIMARY.Ptr(), - RetryTime: utils.Ptr(int64(600)), - RefreshTime: utils.Ptr(int64(3600)), - NegativeCache: utils.Ptr(int64(60)), + RetryTime: utils.Ptr(int32(600)), + RefreshTime: utils.Ptr(int32(3600)), + NegativeCache: utils.Ptr(int32(60)), IsReverseZone: utils.Ptr(false), - ExpireTime: utils.Ptr(int64(36000000)), + ExpireTime: utils.Ptr(int32(36000000)), Description: utils.Ptr("Example"), ContactEmail: utils.Ptr("example@example.com"), }) @@ -126,8 +126,8 @@ func TestParseInput(t *testing.T) { ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr("example"), - DnsName: utils.Ptr("example.com"), + Name: "example", + DnsName: "example.com", }, }, { @@ -153,17 +153,17 @@ func TestParseInput(t *testing.T) { ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr(""), - DnsName: utils.Ptr(""), - DefaultTTL: utils.Ptr(int64(0)), + Name: "", + DnsName: "", + DefaultTTL: utils.Ptr(int32(0)), Primaries: nil, Acl: utils.Ptr(""), Type: nil, - RetryTime: utils.Ptr(int64(0)), - RefreshTime: utils.Ptr(int64(0)), - NegativeCache: utils.Ptr(int64(0)), + RetryTime: utils.Ptr(int32(0)), + RefreshTime: utils.Ptr(int32(0)), + NegativeCache: utils.Ptr(int32(0)), IsReverseZone: utils.Ptr(false), - ExpireTime: utils.Ptr(int64(0)), + ExpireTime: utils.Ptr(int32(0)), Description: utils.Ptr(""), ContactEmail: utils.Ptr(""), }, @@ -195,9 +195,8 @@ func TestParseInput(t *testing.T) { primaryFlagValues: []string{"1.2.3.4", "5.6.7.8"}, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Primaries = utils.Ptr( - append(*model.Primaries, "1.2.3.4", "5.6.7.8"), - ) + model.Primaries = + append(model.Primaries, "1.2.3.4", "5.6.7.8") }), }, { @@ -206,9 +205,8 @@ func TestParseInput(t *testing.T) { primaryFlagValues: []string{"1.2.3.4,5.6.7.8"}, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Primaries = utils.Ptr( - append(*model.Primaries, "1.2.3.4", "5.6.7.8"), - ) + model.Primaries = + append(model.Primaries, "1.2.3.4", "5.6.7.8") }), }, } @@ -240,13 +238,13 @@ func TestBuildRequest(t *testing.T) { ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault, }, - Name: utils.Ptr("example"), - DnsName: utils.Ptr("example.com"), + Name: "example", + DnsName: "example.com", }, - expectedRequest: testClient.CreateZone(testCtx, testProjectId). + expectedRequest: testClient.DefaultAPI.CreateZone(testCtx, testProjectId). CreateZonePayload(dns.CreateZonePayload{ - Name: utils.Ptr("example"), - DnsName: utils.Ptr("example.com"), + Name: "example", + DnsName: "example.com", }), }, } @@ -256,7 +254,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -286,7 +284,7 @@ func TestOutputResult(t *testing.T) { name: "only zone response as argument", args: args{ model: fixtureInputModel(), - resp: &dns.ZoneResponse{Zone: &dns.Zone{}}, + resp: &dns.ZoneResponse{Zone: dns.Zone{}}, }, wantErr: false, }, diff --git a/internal/cmd/dns/zone/delete/delete.go b/internal/cmd/dns/zone/delete/delete.go index 9945054ee..a299dd074 100644 --- a/internal/cmd/dns/zone/delete/delete.go +++ b/internal/cmd/dns/zone/delete/delete.go @@ -17,8 +17,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" ) const ( @@ -54,7 +54,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId @@ -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 zone", func() error { - _, err = wait.DeleteZoneWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId).WaitWithContext(ctx) + _, err = wait.DeleteZoneWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId).WaitWithContext(ctx) return err }) if err != nil { @@ -114,6 +114,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiDeleteZoneRequest { - req := apiClient.DeleteZone(ctx, model.ProjectId, model.ZoneId) + req := apiClient.DefaultAPI.DeleteZone(ctx, model.ProjectId, model.ZoneId) return req } diff --git a/internal/cmd/dns/zone/delete/delete_test.go b/internal/cmd/dns/zone/delete/delete_test.go index 32eabe63b..51f5ec826 100644 --- a/internal/cmd/dns/zone/delete/delete_test.go +++ b/internal/cmd/dns/zone/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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiDeleteZoneRequest)) dns.ApiDeleteZoneRequest { - request := testClient.DeleteZone(testCtx, testProjectId, testZoneId) + request := testClient.DefaultAPI.DeleteZone(testCtx, testProjectId, testZoneId) for _, mod := range mods { mod(&request) } @@ -160,7 +160,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/dns/zone/describe/describe.go b/internal/cmd/dns/zone/describe/describe.go index 51d2fcc8e..66a28b029 100644 --- a/internal/cmd/dns/zone/describe/describe.go +++ b/internal/cmd/dns/zone/describe/describe.go @@ -16,7 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) const ( @@ -62,7 +62,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } zone := resp.Zone - return outputResult(params.Printer, model.OutputFormat, zone) + return outputResult(params.Printer, model.OutputFormat, &zone) }, } return cmd @@ -86,7 +86,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiGetZoneRequest { - req := apiClient.GetZone(ctx, model.ProjectId, model.ZoneId) + req := apiClient.DefaultAPI.GetZone(ctx, model.ProjectId, model.ZoneId) return req } @@ -97,17 +97,17 @@ func outputResult(p *print.Printer, outputFormat string, zone *dns.Zone) error { return p.OutputResult(outputFormat, zone, func() error { table := tables.NewTable() - table.AddRow("ID", utils.PtrString(zone.Id)) + table.AddRow("ID", zone.Id) table.AddSeparator() - table.AddRow("NAME", utils.PtrString(zone.Name)) + table.AddRow("NAME", zone.Name) table.AddSeparator() table.AddRow("DESCRIPTION", utils.PtrString(zone.Description)) table.AddSeparator() - table.AddRow("STATE", utils.PtrString(zone.State)) + table.AddRow("STATE", zone.State) table.AddSeparator() - table.AddRow("TYPE", utils.PtrString(zone.Type)) + table.AddRow("TYPE", zone.Type) table.AddSeparator() - table.AddRow("DNS NAME", utils.PtrString(zone.DnsName)) + table.AddRow("DNS NAME", zone.DnsName) table.AddSeparator() table.AddRow("REVERSE ZONE", utils.PtrString(zone.IsReverseZone)) table.AddSeparator() @@ -115,17 +115,17 @@ func outputResult(p *print.Printer, outputFormat string, zone *dns.Zone) error { table.AddSeparator() table.AddRow("CONTACT EMAIL", utils.PtrString(zone.ContactEmail)) table.AddSeparator() - table.AddRow("DEFAULT TTL", utils.PtrString(zone.DefaultTTL)) + table.AddRow("DEFAULT TTL", zone.DefaultTTL) table.AddSeparator() - table.AddRow("SERIAL NUMBER", utils.PtrString(zone.SerialNumber)) + table.AddRow("SERIAL NUMBER", zone.SerialNumber) table.AddSeparator() - table.AddRow("REFRESH TIME", utils.PtrString(zone.RefreshTime)) + table.AddRow("REFRESH TIME", zone.RefreshTime) table.AddSeparator() - table.AddRow("RETRY TIME", utils.PtrString(zone.RetryTime)) + table.AddRow("RETRY TIME", zone.RetryTime) table.AddSeparator() - table.AddRow("EXPIRE TIME", utils.PtrString(zone.ExpireTime)) + table.AddRow("EXPIRE TIME", zone.ExpireTime) table.AddSeparator() - table.AddRow("NEGATIVE CACHE", utils.PtrString(zone.NegativeCache)) + table.AddRow("NEGATIVE CACHE", zone.NegativeCache) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/dns/zone/describe/describe_test.go b/internal/cmd/dns/zone/describe/describe_test.go index e0f868150..fbf60363b 100644 --- a/internal/cmd/dns/zone/describe/describe_test.go +++ b/internal/cmd/dns/zone/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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -17,7 +17,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() @@ -56,7 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiGetZoneRequest)) dns.ApiGetZoneRequest { - request := testClient.GetZone(testCtx, testProjectId, testZoneId) + request := testClient.DefaultAPI.GetZone(testCtx, testProjectId, testZoneId) for _, mod := range mods { mod(&request) } @@ -161,7 +161,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/cmd/dns/zone/list/list.go b/internal/cmd/dns/zone/list/list.go index 1a2640fe4..05ba02073 100644 --- a/internal/cmd/dns/zone/list/list.go +++ b/internal/cmd/dns/zone/list/list.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/types" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -17,10 +18,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) const ( @@ -83,7 +83,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } // Fetch zones - zones, err := fetchZones(ctx, model, apiClient) + zones, err := fetchZones(ctx, model, apiClient.DefaultAPI) if err != nil { return err } @@ -168,7 +168,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient dnsClient, p req = req.NameLike(*model.NameLike) } if model.OrderByName != nil { - req = req.OrderByName(strings.ToUpper(*model.OrderByName)) + req = req.OrderByName(dns.ListZonesOrderByNameParameter(strings.ToUpper(*model.OrderByName))) } if !model.IncludeDeleted { req = req.StateNeq(deleteSucceededState) @@ -207,7 +207,7 @@ func fetchZones(ctx context.Context, model *inputModel, apiClient dnsClient) ([] if err != nil { return nil, fmt.Errorf("get DNS zones: %w", err) } - respZones := *resp.Zones + respZones := resp.Zones if len(respZones) == 0 { break } @@ -237,11 +237,12 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, zones []d table.SetHeader("ID", "NAME", "STATE", "TYPE", "DNS NAME", "RECORD COUNT") for i := range zones { z := zones[i] - table.AddRow(utils.PtrString(z.Id), - utils.PtrString(z.Name), - utils.PtrString(z.State), - utils.PtrString(z.Type), - utils.PtrString(z.DnsName), + table.AddRow( + z.Id, + z.Name, + z.State, + z.Type, + z.DnsName, utils.PtrString(z.RecordCount), ) } diff --git a/internal/cmd/dns/zone/list/list_test.go b/internal/cmd/dns/zone/list/list_test.go index f6bd66efe..d2413643e 100644 --- a/internal/cmd/dns/zone/list/list_test.go +++ b/internal/cmd/dns/zone/list/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/testparams" @@ -23,7 +23,7 @@ import ( type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { @@ -55,7 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiListZonesRequest)) dns.ApiListZonesRequest { - request := testClient.ListZones(testCtx, testProjectId) + request := testClient.DefaultAPI.ListZones(testCtx, testProjectId) request = request.NameLike("some-pattern") request = request.OrderByName("ASC") request = request.PageSize(pageSizeDefault) @@ -267,16 +267,16 @@ func TestBuildRequest(t *testing.T) { PageSize: pageSizeDefault, }, page: 1, - expectedRequest: testClient.ListZones(testCtx, testProjectId).Page(1).PageSize(pageSizeDefault).StateNeq(deleteSucceededState), + expectedRequest: testClient.DefaultAPI.ListZones(testCtx, testProjectId).Page(1).PageSize(pageSizeDefault).StateNeq(deleteSucceededState), }, } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - request := buildRequest(testCtx, tt.model, testClient, tt.page) + request := buildRequest(testCtx, tt.model, testClient.DefaultAPI, tt.page) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { @@ -414,7 +414,7 @@ func TestFetchZones(t *testing.T) { zones := make([]dns.Zone, numItemsToReturn) mockedResp := dns.ListZonesResponse{ - Zones: &zones, + Zones: zones, } mockedRespBytes, err := json.Marshal(mockedResp) @@ -437,7 +437,7 @@ func TestFetchZones(t *testing.T) { t.Fatalf("Failed to initialize client: %v", err) } - zones, err := fetchZones(testCtx, tt.model, client) + zones, err := fetchZones(testCtx, tt.model, client.DefaultAPI) if err != nil { if !tt.apiCallFails { t.Fatalf("did not fail on invalid input") diff --git a/internal/cmd/dns/zone/update/update.go b/internal/cmd/dns/zone/update/update.go index c44ba724b..d700214ff 100644 --- a/internal/cmd/dns/zone/update/update.go +++ b/internal/cmd/dns/zone/update/update.go @@ -18,8 +18,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" - "github.com/stackitcloud/stackit-sdk-go/services/dns" - "github.com/stackitcloud/stackit-sdk-go/services/dns/wait" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" ) const ( @@ -41,13 +41,13 @@ type inputModel struct { *globalflags.GlobalFlagModel ZoneId string Name *string - DefaultTTL *int64 - Primaries *[]string + DefaultTTL *int32 + Primaries []string Acl *string - RetryTime *int64 - RefreshTime *int64 - NegativeCache *int64 - ExpireTime *int64 + RetryTime *int32 + RefreshTime *int32 + NegativeCache *int32 + ExpireTime *int32 Description *string ContactEmail *string } @@ -76,7 +76,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command { return err } - zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient, model.ProjectId, model.ZoneId) + zoneLabel, err := dnsUtils.GetZoneName(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId) if err != nil { params.Printer.Debug(print.ErrorLevel, "get zone name: %v", err) zoneLabel = model.ZoneId @@ -101,7 +101,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 zone", func() error { - _, err = wait.PartialUpdateZoneWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId).WaitWithContext(ctx) + _, err = wait.PartialUpdateZoneWaitHandler(ctx, apiClient.DefaultAPI, model.ProjectId, model.ZoneId).WaitWithContext(ctx) return err }) if err != nil { @@ -123,13 +123,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().String(nameFlag, "", "User given name of the zone") - cmd.Flags().Int64(defaultTTLFlag, 1000, "Default time to live") + cmd.Flags().Int32(defaultTTLFlag, 1000, "Default time to live") cmd.Flags().StringSlice(primaryFlag, []string{}, "Primary name server for secondary zone") cmd.Flags().String(aclFlag, "", "Access control list") - cmd.Flags().Int64(retryTimeFlag, 0, "Retry time") - cmd.Flags().Int64(refreshTimeFlag, 0, "Refresh time") - cmd.Flags().Int64(negativeCacheFlag, 0, "Negative cache") - cmd.Flags().Int64(expireTimeFlag, 0, "Expire time") + cmd.Flags().Int32(retryTimeFlag, 0, "Retry time") + cmd.Flags().Int32(refreshTimeFlag, 0, "Refresh time") + cmd.Flags().Int32(negativeCacheFlag, 0, "Negative cache") + cmd.Flags().Int32(expireTimeFlag, 0, "Expire time") cmd.Flags().String(descriptionFlag, "", "Description of the zone") cmd.Flags().String(contactEmailFlag, "", "Contact email for the zone") } @@ -143,13 +143,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } name := flags.FlagToStringPointer(p, cmd, nameFlag) - defaultTTL := flags.FlagToInt64Pointer(p, cmd, defaultTTLFlag) - primaries := flags.FlagToStringSlicePointer(p, cmd, primaryFlag) + defaultTTL := flags.FlagToInt32Pointer(p, cmd, defaultTTLFlag) + primaries := flags.FlagToStringSliceValue(p, cmd, primaryFlag) acl := flags.FlagToStringPointer(p, cmd, aclFlag) - retryTime := flags.FlagToInt64Pointer(p, cmd, retryTimeFlag) - refreshTime := flags.FlagToInt64Pointer(p, cmd, refreshTimeFlag) - negativeCache := flags.FlagToInt64Pointer(p, cmd, negativeCacheFlag) - expireTime := flags.FlagToInt64Pointer(p, cmd, expireTimeFlag) + retryTime := flags.FlagToInt32Pointer(p, cmd, retryTimeFlag) + refreshTime := flags.FlagToInt32Pointer(p, cmd, refreshTimeFlag) + negativeCache := flags.FlagToInt32Pointer(p, cmd, negativeCacheFlag) + expireTime := flags.FlagToInt32Pointer(p, cmd, expireTimeFlag) description := flags.FlagToStringPointer(p, cmd, descriptionFlag) contactEmail := flags.FlagToStringPointer(p, cmd, contactEmailFlag) @@ -180,7 +180,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClient) dns.ApiPartialUpdateZoneRequest { - req := apiClient.PartialUpdateZone(ctx, model.ProjectId, model.ZoneId) + req := apiClient.DefaultAPI.PartialUpdateZone(ctx, model.ProjectId, model.ZoneId) req = req.PartialUpdateZonePayload(dns.PartialUpdateZonePayload{ Name: model.Name, DefaultTTL: model.DefaultTTL, diff --git a/internal/cmd/dns/zone/update/update_test.go b/internal/cmd/dns/zone/update/update_test.go index fef73853f..0dda139c0 100644 --- a/internal/cmd/dns/zone/update/update_test.go +++ b/internal/cmd/dns/zone/update/update_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/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) type testCtxKey struct{} var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") -var testClient = &dns.APIClient{} +var testClient = &dns.APIClient{DefaultAPI: &dns.DefaultAPIService{}} var testProjectId = uuid.NewString() var testZoneId = uuid.NewString() @@ -59,13 +59,13 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { }, ZoneId: testZoneId, Name: utils.Ptr("example"), - DefaultTTL: utils.Ptr(int64(3600)), - Primaries: utils.Ptr([]string{"1.1.1.1"}), + DefaultTTL: utils.Ptr(int32(3600)), + Primaries: []string{"1.1.1.1"}, Acl: utils.Ptr("0.0.0.0/0"), - RetryTime: utils.Ptr(int64(600)), - RefreshTime: utils.Ptr(int64(3600)), - NegativeCache: utils.Ptr(int64(60)), - ExpireTime: utils.Ptr(int64(36000000)), + RetryTime: utils.Ptr(int32(600)), + RefreshTime: utils.Ptr(int32(3600)), + NegativeCache: utils.Ptr(int32(60)), + ExpireTime: utils.Ptr(int32(36000000)), Description: utils.Ptr("Example"), ContactEmail: utils.Ptr("example@example.com"), } @@ -76,16 +76,16 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } func fixtureRequest(mods ...func(request *dns.ApiPartialUpdateZoneRequest)) dns.ApiPartialUpdateZoneRequest { - request := testClient.PartialUpdateZone(testCtx, testProjectId, testZoneId) + request := testClient.DefaultAPI.PartialUpdateZone(testCtx, testProjectId, testZoneId) request = request.PartialUpdateZonePayload(dns.PartialUpdateZonePayload{ Name: utils.Ptr("example"), - DefaultTTL: utils.Ptr(int64(3600)), - Primaries: utils.Ptr([]string{"1.1.1.1"}), + DefaultTTL: utils.Ptr(int32(3600)), + Primaries: []string{"1.1.1.1"}, Acl: utils.Ptr("0.0.0.0/0"), - RetryTime: utils.Ptr(int64(600)), - RefreshTime: utils.Ptr(int64(3600)), - NegativeCache: utils.Ptr(int64(60)), - ExpireTime: utils.Ptr(int64(36000000)), + RetryTime: utils.Ptr(int32(600)), + RefreshTime: utils.Ptr(int32(3600)), + NegativeCache: utils.Ptr(int32(60)), + ExpireTime: utils.Ptr(int32(36000000)), Description: utils.Ptr("Example"), ContactEmail: utils.Ptr("example@example.com"), }) @@ -168,13 +168,13 @@ func TestParseInput(t *testing.T) { }, ZoneId: testZoneId, Name: utils.Ptr(""), - DefaultTTL: utils.Ptr(int64(0)), - Primaries: utils.Ptr([]string{}), + DefaultTTL: utils.Ptr(int32(0)), + Primaries: []string{}, Acl: utils.Ptr(""), - RetryTime: utils.Ptr(int64(0)), - RefreshTime: utils.Ptr(int64(0)), - NegativeCache: utils.Ptr(int64(0)), - ExpireTime: utils.Ptr(int64(0)), + RetryTime: utils.Ptr(int32(0)), + RefreshTime: utils.Ptr(int32(0)), + NegativeCache: utils.Ptr(int32(0)), + ExpireTime: utils.Ptr(int32(0)), Description: utils.Ptr(""), ContactEmail: utils.Ptr(""), }, @@ -222,9 +222,8 @@ func TestParseInput(t *testing.T) { primaryFlagValues: []string{"1.2.3.4", "5.6.7.8"}, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Primaries = utils.Ptr( - append(*model.Primaries, "1.2.3.4", "5.6.7.8"), - ) + model.Primaries = + append(model.Primaries, "1.2.3.4", "5.6.7.8") }), }, { @@ -234,9 +233,8 @@ func TestParseInput(t *testing.T) { primaryFlagValues: []string{"1.2.3.4,5.6.7.8"}, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.Primaries = utils.Ptr( - append(*model.Primaries, "1.2.3.4", "5.6.7.8"), - ) + model.Primaries = + append(model.Primaries, "1.2.3.4", "5.6.7.8") }), }, } @@ -325,7 +323,7 @@ func TestBuildRequest(t *testing.T) { }, ZoneId: testZoneId, }, - expectedRequest: testClient.PartialUpdateZone(testCtx, testProjectId, testZoneId). + expectedRequest: testClient.DefaultAPI.PartialUpdateZone(testCtx, testProjectId, testZoneId). PartialUpdateZonePayload(dns.PartialUpdateZonePayload{}), }, } @@ -335,7 +333,7 @@ func TestBuildRequest(t *testing.T) { request := buildRequest(testCtx, tt.model, testClient) diff := cmp.Diff(request, tt.expectedRequest, - cmp.AllowUnexported(tt.expectedRequest), + cmp.AllowUnexported(tt.expectedRequest, dns.DefaultAPIService{}), cmpopts.EquateComparable(testCtx), ) if diff != "" { diff --git a/internal/pkg/services/dns/client/client.go b/internal/pkg/services/dns/client/client.go index 478fa0a53..7e101b00a 100644 --- a/internal/pkg/services/dns/client/client.go +++ b/internal/pkg/services/dns/client/client.go @@ -7,7 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/viper" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" ) func ConfigureClient(p *print.Printer, cliVersion string) (*dns.APIClient, error) { diff --git a/internal/pkg/services/dns/utils/utils.go b/internal/pkg/services/dns/utils/utils.go index 030c86b55..f58f9c453 100644 --- a/internal/pkg/services/dns/utils/utils.go +++ b/internal/pkg/services/dns/utils/utils.go @@ -5,38 +5,33 @@ import ( "fmt" "math" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) -type DNSClient interface { - GetZoneExecute(ctx context.Context, projectId, zoneId string) (*dns.ZoneResponse, error) - GetRecordSetExecute(ctx context.Context, projectId, zoneId, recordSetId string) (*dns.RecordSetResponse, error) -} - -func GetZoneName(ctx context.Context, apiClient DNSClient, projectId, zoneId string) (string, error) { - resp, err := apiClient.GetZoneExecute(ctx, projectId, zoneId) +func GetZoneName(ctx context.Context, apiClient dns.DefaultAPI, projectId, zoneId string) (string, error) { + resp, err := apiClient.GetZone(ctx, projectId, zoneId).Execute() if err != nil { return "", fmt.Errorf("get DNS zone: %w", err) } - return *resp.Zone.Name, nil + return resp.Zone.Name, nil } -func GetRecordSetName(ctx context.Context, apiClient DNSClient, projectId, zoneId, recordSetId string) (string, error) { - resp, err := apiClient.GetRecordSetExecute(ctx, projectId, zoneId, recordSetId) +func GetRecordSetName(ctx context.Context, apiClient dns.DefaultAPI, projectId, zoneId, recordSetId string) (string, error) { + resp, err := apiClient.GetRecordSet(ctx, projectId, zoneId, recordSetId).Execute() if err != nil { return "", fmt.Errorf("get DNS recordset: %w", err) } - return *resp.Rrset.Name, nil + return resp.Rrset.Name, nil } -func GetRecordSetType(ctx context.Context, apiClient DNSClient, projectId, zoneId, recordSetId string) (*string, error) { - resp, err := apiClient.GetRecordSetExecute(ctx, projectId, zoneId, recordSetId) +func GetRecordSetType(ctx context.Context, apiClient dns.DefaultAPI, projectId, zoneId, recordSetId string) (*string, error) { + resp, err := apiClient.GetRecordSet(ctx, projectId, zoneId, recordSetId).Execute() if err != nil { return utils.Ptr(""), fmt.Errorf("get DNS recordset: %w", err) } - return (*string)(resp.Rrset.Type), nil + return utils.Ptr(string(resp.Rrset.Type)), nil } func FormatTxtRecord(input string) (string, error) { diff --git a/internal/pkg/services/dns/utils/utils_test.go b/internal/pkg/services/dns/utils/utils_test.go index b7c91bff9..0330ce992 100644 --- a/internal/pkg/services/dns/utils/utils_test.go +++ b/internal/pkg/services/dns/utils/utils_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/services/dns" + dns "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" ) @@ -28,25 +28,30 @@ const ( testRecordSetType = "A" ) -type dnsClientMocked struct { +type mockSettings struct { getZoneFails bool getZoneResp *dns.ZoneResponse getRecordSetFails bool getRecordSetResp *dns.RecordSetResponse } -func (m *dnsClientMocked) GetZoneExecute(_ context.Context, _, _ string) (*dns.ZoneResponse, error) { - if m.getZoneFails { - return nil, fmt.Errorf("could not get zone") - } - return m.getZoneResp, nil -} +func newAPIMock(settings *mockSettings) dns.DefaultAPI { + return &dns.DefaultAPIServiceMock{ + GetZoneExecuteMock: utils.Ptr(func(_ dns.ApiGetZoneRequest) (*dns.ZoneResponse, error) { + if settings.getZoneFails { + return nil, fmt.Errorf("could not get zone") + } + + return settings.getZoneResp, nil + }), + GetRecordSetExecuteMock: utils.Ptr(func(_ dns.ApiGetRecordSetRequest) (*dns.RecordSetResponse, error) { + if settings.getRecordSetFails { + return nil, fmt.Errorf("could not get record set") + } -func (m *dnsClientMocked) GetRecordSetExecute(_ context.Context, _, _, _ string) (*dns.RecordSetResponse, error) { - if m.getRecordSetFails { - return nil, fmt.Errorf("could not get record set") + return settings.getRecordSetResp, nil + }), } - return m.getRecordSetResp, nil } func TestGetZoneName(t *testing.T) { @@ -60,8 +65,8 @@ func TestGetZoneName(t *testing.T) { { description: "base", getZoneResp: &dns.ZoneResponse{ - Zone: &dns.Zone{ - Name: utils.Ptr(testZoneName), + Zone: dns.Zone{ + Name: testZoneName, }, }, isValid: true, @@ -76,10 +81,10 @@ func TestGetZoneName(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &dnsClientMocked{ + client := newAPIMock(&mockSettings{ getZoneFails: tt.getZoneFails, getZoneResp: tt.getZoneResp, - } + }) output, err := GetZoneName(context.Background(), client, testProjectId, testZoneId) @@ -110,8 +115,8 @@ func TestGetRecordSetName(t *testing.T) { { description: "base", getRecordSetResp: &dns.RecordSetResponse{ - Rrset: &dns.RecordSet{ - Name: utils.Ptr(testRecordSetName), + Rrset: dns.RecordSet{ + Name: testRecordSetName, }, }, isValid: true, @@ -126,10 +131,10 @@ func TestGetRecordSetName(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &dnsClientMocked{ + client := newAPIMock(&mockSettings{ getRecordSetFails: tt.getRecordSetFails, getRecordSetResp: tt.getRecordSetResp, - } + }) output, err := GetRecordSetName(context.Background(), client, testProjectId, testZoneId, testRecordSetId) @@ -160,8 +165,8 @@ func TestGetRecordSetType(t *testing.T) { { description: "base", getRecordSetResp: &dns.RecordSetResponse{ - Rrset: &dns.RecordSet{ - Name: utils.Ptr(testRecordSetType), + Rrset: dns.RecordSet{ + Name: testRecordSetType, }, }, isValid: true, @@ -176,10 +181,10 @@ func TestGetRecordSetType(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - client := &dnsClientMocked{ + client := newAPIMock(&mockSettings{ getRecordSetFails: tt.getRecordSetFails, getRecordSetResp: tt.getRecordSetResp, - } + }) output, err := GetRecordSetName(context.Background(), client, testProjectId, testZoneId, testRecordSetId) From 574dab09437b53917093de1d8c13744240fd2882 Mon Sep 17 00:00:00 2001 From: GokceGK Date: Wed, 17 Jun 2026 08:38:52 +0200 Subject: [PATCH 2/2] chore(dns): fix the flag possible values relates to STACKITCLI-362 --- docs/stackit_dns_record-set_create.md | 2 +- docs/stackit_dns_zone_create.md | 2 +- internal/cmd/dns/record-set/create/create.go | 10 ++++------ internal/cmd/dns/zone/create/create.go | 10 ++++------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/docs/stackit_dns_record-set_create.md b/docs/stackit_dns_record-set_create.md index 9610ed16a..8f33edd6d 100644 --- a/docs/stackit_dns_record-set_create.md +++ b/docs/stackit_dns_record-set_create.md @@ -25,7 +25,7 @@ stackit dns record-set create [flags] --name string Name of the record, should be compliant with RFC1035, Section 2.3.4 --record strings Records belonging to the record set --ttl int32 Time to live, if not provided defaults to the zone's default TTL - --type string Record type, one of ["A" "AAAA" "SOA" "CNAME" "NS" "MX" "TXT" "SRV" "PTR" "ALIAS" "DNAME" "CAA" "DNSKEY" "DS" "LOC" "NAPTR" "SSHFP" "TLSA" "URI" "CERT" "SVCB" "TYPE" "CSYNC" "HINFO" "HTTPS" "unknown_default_open_api"] (default "A") + --type string Record type, one of ["A" "AAAA" "SOA" "CNAME" "NS" "MX" "TXT" "SRV" "PTR" "ALIAS" "DNAME" "CAA" "DNSKEY" "DS" "LOC" "NAPTR" "SSHFP" "TLSA" "URI" "CERT" "SVCB" "TYPE" "CSYNC" "HINFO" "HTTPS"] (default "A") --zone-id string Zone ID ``` diff --git a/docs/stackit_dns_zone_create.md b/docs/stackit_dns_zone_create.md index 08f4f99d5..c261fa689 100644 --- a/docs/stackit_dns_zone_create.md +++ b/docs/stackit_dns_zone_create.md @@ -36,7 +36,7 @@ stackit dns zone create [flags] --primary strings Primary name server for secondary zone --refresh-time int32 Refresh time --retry-time int32 Retry time - --type string Zone type, one of: ["primary" "secondary" "unknown_default_open_api"] + --type string Zone type, one of: ["primary" "secondary"] ``` ### Options inherited from parent commands diff --git a/internal/cmd/dns/record-set/create/create.go b/internal/cmd/dns/record-set/create/create.go index fa63bdb9a..d3a86eb4e 100644 --- a/internal/cmd/dns/record-set/create/create.go +++ b/internal/cmd/dns/record-set/create/create.go @@ -4,8 +4,11 @@ import ( "context" "fmt" + sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api/wait" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/types" "github.com/spf13/cobra" @@ -107,17 +110,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } func configureFlags(cmd *cobra.Command) { - var typeFlagOptions []string - for _, val := range dns.AllowedCreateRecordSetPayloadTypeEnumValues { - typeFlagOptions = append(typeFlagOptions, string(val)) - } - cmd.Flags().Var(flags.UUIDFlag(), zoneIdFlag, "Zone ID") cmd.Flags().String(commentFlag, "", "User comment") cmd.Flags().String(nameFlag, "", "Name of the record, should be compliant with RFC1035, Section 2.3.4") cmd.Flags().Int32(ttlFlag, 0, "Time to live, if not provided defaults to the zone's default TTL") cmd.Flags().StringSlice(recordFlag, []string{}, "Records belonging to the record set") - cmd.Flags().Var(flags.EnumFlag(false, string(defaultType), typeFlagOptions...), typeFlag, fmt.Sprintf("Record type, one of %q", typeFlagOptions)) + cmd.Flags().Var(flags.EnumFlag(false, string(defaultType), sdkUtils.EnumSliceToStringSlice(dns.AllowedCreateRecordSetPayloadTypeEnumValues)...), typeFlag, fmt.Sprintf("Record type, one of %q", utils.FormatPossibleValues(sdkUtils.EnumSliceToStringSlice(dns.AllowedCreateRecordSetPayloadTypeEnumValues)...))) err := flags.MarkFlagsRequired(cmd, zoneIdFlag, nameFlag, recordFlag) cobra.CheckErr(err) diff --git a/internal/cmd/dns/zone/create/create.go b/internal/cmd/dns/zone/create/create.go index ffafca427..0770b4e82 100644 --- a/internal/cmd/dns/zone/create/create.go +++ b/internal/cmd/dns/zone/create/create.go @@ -4,7 +4,10 @@ import ( "context" "fmt" + sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/types" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -120,17 +123,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command { } func configureFlags(cmd *cobra.Command) { - var typeFlagOptions []string - for _, val := range dns.AllowedCreateZonePayloadTypeEnumValues { - typeFlagOptions = append(typeFlagOptions, string(val)) - } - cmd.Flags().String(nameFlag, "", "User given name of the zone") cmd.Flags().String(dnsNameFlag, "", "Fully qualified domain name of the DNS zone") cmd.Flags().Int32(defaultTTLFlag, 1000, "Default time to live") cmd.Flags().StringSlice(primaryFlag, []string{}, "Primary name server for secondary zone") cmd.Flags().String(aclFlag, "", "Access control list") - cmd.Flags().Var(flags.EnumFlag(false, "", append(typeFlagOptions, "")...), typeFlag, fmt.Sprintf("Zone type, one of: %q", typeFlagOptions)) + cmd.Flags().Var(flags.EnumFlag(false, "", append(sdkUtils.EnumSliceToStringSlice(dns.AllowedCreateZonePayloadTypeEnumValues), "")...), typeFlag, fmt.Sprintf("Zone type, one of: %q", utils.FormatPossibleValues(sdkUtils.EnumSliceToStringSlice(dns.AllowedCreateZonePayloadTypeEnumValues)...))) cmd.Flags().Int32(retryTimeFlag, 0, "Retry time") cmd.Flags().Int32(refreshTimeFlag, 0, "Refresh time") cmd.Flags().Int32(negativeCacheFlag, 0, "Negative cache")