Skip to content

Commit 63a507c

Browse files
committed
fix: update DNS client to v1api and adjust TTL types
1 parent 73e7f75 commit 63a507c

File tree

12 files changed

+144
-143
lines changed

12 files changed

+144
-143
lines changed

internal/repository/dns_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package repository
22

33
import (
44
stackitconfig "github.com/stackitcloud/stackit-sdk-go/core/config"
5-
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns"
5+
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api"
66
)
77

88
func newStackitDnsClient(

internal/repository/mock/rrset_repository.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/repository/mock/zone_repository.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/repository/rrset_repository.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77

88
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
9-
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns"
9+
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api"
1010
)
1111

1212
var (
@@ -62,7 +62,7 @@ func (r *rrSetRepository) FetchRRSetForZone(
6262
rrSetType string,
6363
) (*stackitdnsclient.RecordSet, error) {
6464
var pager int32 = 1
65-
listRequest := r.apiClient.ListRecordSets(ctx, r.projectId, r.zoneId).
65+
listRequest := r.apiClient.DefaultAPI.ListRecordSets(ctx, r.projectId, r.zoneId).
6666
Page(pager).PageSize(10000).
6767
ActiveEq(true).NameEq(rrSetName).TypeEq(rrSetType)
6868

@@ -71,11 +71,11 @@ func (r *rrSetRepository) FetchRRSetForZone(
7171
return nil, err
7272
}
7373

74-
if len(*rrSetResponse.RrSets) == 0 {
74+
if len(rrSetResponse.RrSets) == 0 {
7575
return nil, ErrRRSetNotFound
7676
}
7777

78-
return &(*rrSetResponse.RrSets)[0], nil
78+
return &rrSetResponse.RrSets[0], nil
7979
}
8080

8181
func (r *rrSetRepository) CreateRRSet(
@@ -84,21 +84,22 @@ func (r *rrSetRepository) CreateRRSet(
8484
) error {
8585
var records []stackitdnsclient.RecordPayload
8686
if rrSet.Records != nil {
87-
records = make([]stackitdnsclient.RecordPayload, len(*rrSet.Records))
88-
for i, record := range *rrSet.Records {
87+
records = make([]stackitdnsclient.RecordPayload, len(rrSet.Records))
88+
for i, record := range rrSet.Records {
8989
records[i] = stackitdnsclient.RecordPayload{
9090
Content: record.Content,
9191
}
9292
}
9393
}
94+
ttl := int32(rrSet.Ttl)
9495
payload := stackitdnsclient.CreateRecordSetPayload{
9596
Comment: rrSet.Comment,
9697
Name: rrSet.Name,
97-
Ttl: rrSet.Ttl,
98-
Type: stackitdnsclient.CreateRecordSetPayloadGetTypeAttributeType(rrSet.Type),
99-
Records: &records,
98+
Ttl: &ttl,
99+
Type: rrSet.Type,
100+
Records: records,
100101
}
101-
_, err := r.apiClient.CreateRecordSet(ctx, r.projectId, r.zoneId).CreateRecordSetPayload(payload).Execute()
102+
_, err := r.apiClient.DefaultAPI.CreateRecordSet(ctx, r.projectId, r.zoneId).CreateRecordSetPayload(payload).Execute()
102103
if err != nil {
103104
return err
104105
}
@@ -110,20 +111,21 @@ func (r *rrSetRepository) UpdateRRSet(
110111
ctx context.Context,
111112
rrSet stackitdnsclient.RecordSet,
112113
) error {
113-
records := make([]stackitdnsclient.RecordPayload, len(*rrSet.Records))
114-
for i, record := range *rrSet.Records {
114+
records := make([]stackitdnsclient.RecordPayload, len(rrSet.Records))
115+
for i, record := range rrSet.Records {
115116
records[i] = stackitdnsclient.RecordPayload{
116117
Content: record.Content,
117118
}
118119
}
120+
ttl := int32(rrSet.Ttl)
119121
payload := stackitdnsclient.PartialUpdateRecordSetPayload{
120122
Comment: rrSet.Comment,
121-
Name: rrSet.Name,
122-
Records: &records,
123-
Ttl: rrSet.Ttl,
123+
Name: &rrSet.Name,
124+
Records: records,
125+
Ttl: &ttl,
124126
}
125127

126-
_, err := r.apiClient.PartialUpdateRecordSet(ctx, r.projectId, r.zoneId, *rrSet.Id).
128+
_, err := r.apiClient.DefaultAPI.PartialUpdateRecordSet(ctx, r.projectId, r.zoneId, rrSet.Id).
127129
PartialUpdateRecordSetPayload(payload).Execute()
128130
if err != nil {
129131
return err
@@ -133,7 +135,7 @@ func (r *rrSetRepository) UpdateRRSet(
133135
}
134136

135137
func (r *rrSetRepository) DeleteRRSet(ctx context.Context, rrSetId string) error {
136-
_, err := r.apiClient.DeleteRecordSet(ctx, r.projectId, r.zoneId, rrSetId).Execute()
138+
_, err := r.apiClient.DefaultAPI.DeleteRecordSet(ctx, r.projectId, r.zoneId, rrSetId).Execute()
137139
if err != nil {
138140
if oapiError, ok := errors.AsType[*oapierror.GenericOpenAPIError](err); ok {
139141
if oapiError.StatusCode == 404 || oapiError.StatusCode == 400 {

internal/repository/rrset_repositry_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
"github.com/stackitcloud/stackit-cert-manager-webhook/internal/repository"
8-
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns"
8+
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api"
99
"github.com/stretchr/testify/require"
1010
)
1111

@@ -22,7 +22,7 @@ func TestRrSetRepository_FetchRRSetForZone(t *testing.T) {
2222
require.NoError(t, err)
2323
rrSet, err := rrSetRepository.FetchRRSetForZone(ctx, "test.com.", rrSetTypeTxt)
2424
require.NoError(t, err)
25-
require.Equal(t, *rrSet.Id, "1234")
25+
require.Equal(t, rrSet.Id, "1234")
2626
})
2727

2828
t.Run("FetchRRSetForZone failure", func(t *testing.T) {
@@ -78,10 +78,10 @@ func TestRrSetRepository_UpdateRRSet(t *testing.T) {
7878
ctx,
7979
stackitdnsclient.RecordSet{
8080
Comment: new("comment1"),
81-
Id: new("0000"),
82-
Name: new("test.com."),
83-
Ttl: new(int64(60)),
84-
Records: &[]stackitdnsclient.Record{{Content: new("content1")}},
81+
Id: "0000",
82+
Name: "test.com.",
83+
Ttl: int32(60),
84+
Records: []stackitdnsclient.Record{{Content: "content1"}},
8585
},
8686
)
8787
require.NoError(t, err)
@@ -95,10 +95,10 @@ func TestRrSetRepository_UpdateRRSet(t *testing.T) {
9595
ctx,
9696
stackitdnsclient.RecordSet{
9797
Comment: new("comment2"),
98-
Id: new("2222"),
99-
Name: new("test.com."),
100-
Ttl: new(int64(60)),
101-
Records: &[]stackitdnsclient.Record{{Content: new("content2")}},
98+
Id: "2222",
99+
Name: "test.com.",
100+
Ttl: int32(60),
101+
Records: []stackitdnsclient.Record{{Content: "content2"}},
102102
},
103103
)
104104
require.Error(t, err)

internal/repository/server_test.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http/httptest"
77
"testing"
88

9-
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns"
9+
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api"
1010
"github.com/stretchr/testify/assert"
1111
"k8s.io/utils/ptr"
1212
)
@@ -116,13 +116,13 @@ func getZonesResponseSuccess(t *testing.T, w http.ResponseWriter) {
116116
w.Header().Set("Content-Type", "application/json")
117117

118118
zones := stackitdnsclient.ListZonesResponse{
119-
ItemsPerPage: ptr.To(int64(10)),
119+
ItemsPerPage: int32(10),
120120
Message: ptr.To("success"),
121-
TotalItems: ptr.To(int64(1)),
122-
TotalPages: ptr.To(int64(1)),
123-
Zones: ptr.To([]stackitdnsclient.Zone{
124-
{Id: ptr.To("1234"), DnsName: ptr.To("test.com")},
125-
}),
121+
TotalItems: int32(1),
122+
TotalPages: int32(1),
123+
Zones: []stackitdnsclient.Zone{
124+
{Id: "1234", DnsName: "test.com"},
125+
},
126126
}
127127

128128
successResponseBytes, err := json.Marshal(zones)
@@ -138,11 +138,11 @@ func getZonesResponseNoZones(t *testing.T, w http.ResponseWriter) {
138138
w.Header().Set("Content-Type", "application/json")
139139

140140
zones := stackitdnsclient.ListZonesResponse{
141-
ItemsPerPage: ptr.To(int64(10)),
141+
ItemsPerPage: int32(10),
142142
Message: ptr.To("success"),
143-
TotalItems: ptr.To(int64(1)),
144-
TotalPages: ptr.To(int64(1)),
145-
Zones: ptr.To([]stackitdnsclient.Zone{}),
143+
TotalItems: int32(1),
144+
TotalPages: int32(1),
145+
Zones: []stackitdnsclient.Zone{},
146146
}
147147

148148
successResponseBytes, err := json.Marshal(zones)
@@ -165,21 +165,21 @@ func getRRSetResponseSuccess(t *testing.T, w http.ResponseWriter) {
165165
w.Header().Set("Content-Type", "application/json")
166166

167167
rrSets := stackitdnsclient.ListRecordSetsResponse{
168-
ItemsPerPage: ptr.To(int64(20)),
168+
ItemsPerPage: int32(20),
169169
Message: ptr.To("success"),
170-
RrSets: ptr.To([]stackitdnsclient.RecordSet{
170+
RrSets: []stackitdnsclient.RecordSet{
171171
{
172-
Name: ptr.To("test.com."),
173-
Type: stackitdnsclient.RecordSetGetTypeAttributeType(ptr.To("TXT")),
174-
Ttl: ptr.To(int64(300)),
175-
Records: ptr.To([]stackitdnsclient.Record{
176-
{Content: ptr.To("_acme-challenge.test.com")},
177-
}),
178-
Id: ptr.To("1234"),
172+
Name: "test.com.",
173+
Type: "TXT",
174+
Ttl: int32(300),
175+
Records: []stackitdnsclient.Record{
176+
{Content: "_acme-challenge.test.com"},
177+
},
178+
Id: "1234",
179179
},
180-
}),
181-
TotalItems: ptr.To(int64(2)),
182-
TotalPages: ptr.To(int64(1)),
180+
},
181+
TotalItems: int32(2),
182+
TotalPages: int32(1),
183183
}
184184

185185
successResponseBytes, err := json.Marshal(rrSets)
@@ -195,11 +195,11 @@ func getRRSetResponseNoRRSets(t *testing.T, w http.ResponseWriter) {
195195
w.Header().Set("Content-Type", "application/json")
196196

197197
rrSets := stackitdnsclient.ListRecordSetsResponse{
198-
ItemsPerPage: ptr.To(int64(20)),
198+
ItemsPerPage: int32(20),
199199
Message: ptr.To("success"),
200-
RrSets: ptr.To([]stackitdnsclient.RecordSet{}),
201-
TotalItems: ptr.To(int64(2)),
202-
TotalPages: ptr.To(int64(1)),
200+
RrSets: []stackitdnsclient.RecordSet{},
201+
TotalItems: int32(2),
202+
TotalPages: int32(1),
203203
}
204204

205205
successResponseBytes, err := json.Marshal(rrSets)
@@ -216,12 +216,12 @@ func postRRSetResponseSuccess(t *testing.T, w http.ResponseWriter) {
216216

217217
rrSets := stackitdnsclient.RecordSetResponse{
218218
Message: ptr.To("success"),
219-
Rrset: ptr.To(stackitdnsclient.RecordSet{
219+
Rrset: stackitdnsclient.RecordSet{
220220
Active: ptr.To(true),
221221
Comment: ptr.To("created by webhook"),
222-
Id: ptr.To("1234"),
223-
Name: ptr.To("test.com."),
224-
}),
222+
Id: "1234",
223+
Name: "test.com.",
224+
},
225225
}
226226

227227
successResponseBytes, err := json.Marshal(rrSets)

internal/repository/zone_repository.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"strings"
77

8-
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns"
8+
stackitdnsclient "github.com/stackitcloud/stackit-sdk-go/services/dns/v1api"
99
)
1010

1111
var ErrZoneNotFound = fmt.Errorf("zone not found")
@@ -49,14 +49,14 @@ func (z *zoneRepository) FetchZone(
4949
ctx context.Context,
5050
zoneDnsName string,
5151
) (*stackitdnsclient.Zone, error) {
52-
zoneResponse, err := z.apiClient.ListZones(ctx, z.projectId).ActiveEq(true).DnsNameEq(strings.ToLower(zoneDnsName)).Execute()
52+
zoneResponse, err := z.apiClient.DefaultAPI.ListZones(ctx, z.projectId).ActiveEq(true).DnsNameEq(strings.ToLower(zoneDnsName)).Execute()
5353
if err != nil {
5454
return nil, err
5555
}
5656

57-
if len(*zoneResponse.Zones) == 0 {
57+
if len(zoneResponse.Zones) == 0 {
5858
return nil, ErrZoneNotFound
5959
}
6060

61-
return &(*zoneResponse.Zones)[0], nil
61+
return &zoneResponse.Zones[0], nil
6262
}

internal/repository/zone_repository_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestZoneRepository_FetchZone(t *testing.T) {
5656
}
5757
} else {
5858
assert.NoError(t, err)
59-
assert.Equal(t, tc.expectedID, *zone.Id)
59+
assert.Equal(t, tc.expectedID, zone.Id)
6060
}
6161
})
6262
}

internal/resolver/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type StackitDnsProviderConfig struct {
2626
AuthTokenSecretNamespace string `json:"authTokenSecretNamespace"`
2727
ServiceAccountKeyPath string `json:"serviceAccountKeyPath"`
2828
ServiceAccountBaseUrl string `json:"serviceAccountBaseUrl"`
29-
AcmeTxtRecordTTL int64 `json:"acmeTxtRecordTTL"`
29+
AcmeTxtRecordTTL int32 `json:"acmeTxtRecordTTL"`
3030
}
3131

3232
func (d defaultConfigProvider) LoadConfig(cfgJSON *extapi.JSON) (StackitDnsProviderConfig, error) {

internal/resolver/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestLoadConfig(t *testing.T) {
7777
require.Equal(t, "https://dns.api.stackit.cloud", cfg.ApiBasePath)
7878
require.Equal(t, "stackit-cert-manager-webhook", cfg.AuthTokenSecretRef)
7979
require.Equal(t, "auth-token", cfg.AuthTokenSecretKey)
80-
require.Equal(t, int64(600), cfg.AcmeTxtRecordTTL)
80+
require.Equal(t, int32(600), cfg.AcmeTxtRecordTTL)
8181
})
8282

8383
t.Run("custom service account base url", func(t *testing.T) {

0 commit comments

Comments
 (0)