Skip to content

Commit

Permalink
chore: fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
linxside committed Nov 5, 2023
1 parent 7ab6ec0 commit 4da56e6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 50 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nameserver-systems/pdns-distribute

go 1.19
go 1.21

require (
github.com/google/uuid v1.3.1
Expand Down
25 changes: 1 addition & 24 deletions internal/app/pdns-zone-provider/powerdns/powerdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,9 @@ func getZoneDataFromPowerDNS(zoneid string, conf *config.ServiceConfiguration, w
powerdnsdnstcpcalltotal.Inc()
powerdnsaxfrquery.Inc()

/* Use always AXFR for quering zones instead of api. Because LUA Records are not recognized by libs and pdns can interpret format
if strings.Contains(zonefile, "CLASS1") {
//CLASS1 is used by miek/dns due to not recognize LUA records
zonefile, err = getZoneDataFromPowerDNSAPI(zoneid, conf)
if err != nil {
powerdnsapierrtotal.Inc()
return
}
powerdnsapicalltotal.Inc()
}
*/

return zonefile, nil
}

func getZoneDataFromPowerDNSAPI(zoneid string, conf *config.ServiceConfiguration) (string, error) { //nolint:unused,deadcode
// does not work for dnssec signed zones
// used for zones contain LUA records
serverid := conf.PowerDNSServerID
apitoken := conf.PowerDNSAPIToken
zoneDataFileURL := conf.PowerDNSURL + "/api/v1/servers/" + serverid + "/zones/" + zoneid + "/export"

return httputils.ExecutePowerDNSRequest(http.MethodGet, zoneDataFileURL, apitoken, nil)
}

func getZoneMetadataFromPowerDNS(zonename string, conf *config.ServiceConfiguration) (dnssec, presigned bool, err error) {
zonedata, requesterr := getZoneDetailsPerPowerdnsAPI(conf, zonename)
if requesterr != nil {
Expand All @@ -161,7 +138,7 @@ func getZoneMetadataFromPowerDNS(zonename string, conf *config.ServiceConfigurat
func getZoneDetailsPerPowerdnsAPI(conf *config.ServiceConfiguration, zonename string) (modelpowerdns.Zone, error) {
serverid := conf.PowerDNSServerID
apitoken := conf.PowerDNSAPIToken
zoneDataFileURL := conf.PowerDNSURL + "/api/v1/servers/" + serverid + "/zones/" + zonename
zoneDataFileURL := conf.PowerDNSURL + powerdnsutils.PowerDNSServerBaseURL + serverid + powerdnsutils.PowerDNSZoneURLPath + zonename

detailresponse, httperr := httputils.ExecutePowerDNSRequest(http.MethodGet, zoneDataFileURL, apitoken, nil)
if httperr != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/eventutils/eventutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func PublishDeleteZoneEvent(ms *microservice.Microservice, topic string, zoneid
}

ms.MessageBroker.Publish(topic, payload)
logger.DebugLog("[Delete Zone Event] triggered for zone: " + zoneid + " on topic: " + topic)
logger.DebugLog("[Delete Zone Event] triggered for zone: " + zoneid + " on topic: " + topic) //nolint:goconst
}

func PublishChangeZoneEvent(ms *microservice.Microservice, topic string, zoneid string) {
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/powerdnsutils/contants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package powerdnsutils

const (
PowerDNSServerBaseURL = "/api/v1/servers/"
PowerDNSZoneURLPath = "/zones/"
)
18 changes: 9 additions & 9 deletions internal/pkg/powerdnsutils/powerdnsutils_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TransferPowerDNSDNSSECZonesIntoZoneStateMap(actualzones []modelpowerdns.Zon
func GetZoneList(con modelpowerdns.PDNSconnectionobject, zoneid string, dnssecinfo bool) (string, error) {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones?rrsets=false&dnssec=" +
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + "/zones?rrsets=false&dnssec=" +
strconv.FormatBool(dnssecinfo)

if zoneid != "" {
Expand All @@ -55,7 +55,7 @@ func GetZoneList(con modelpowerdns.PDNSconnectionobject, zoneid string, dnssecin
func DoesZoneExist(con modelpowerdns.PDNSconnectionobject, zoneID string) (bool, error) {
serverID := con.ServerID
apiToken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverID + "/zones?zone=" + zoneID
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverID + "/zones?zone=" + zoneID

response, requesterr := httputils.ExecutePowerDNSRequest(http.MethodGet, zoneDataFileURL, apiToken, nil)
if requesterr != nil {
Expand All @@ -79,7 +79,7 @@ func DoesZoneExist(con modelpowerdns.PDNSconnectionobject, zoneID string) (bool,
func DeleteZone(con modelpowerdns.PDNSconnectionobject, zoneid string) error {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones/" + zoneid
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + PowerDNSZoneURLPath + zoneid

_, delerr := httputils.ExecutePowerDNSRequest(http.MethodDelete, zoneDataFileURL, apitoken, nil)
if delerr != nil {
Expand All @@ -92,7 +92,7 @@ func DeleteZone(con modelpowerdns.PDNSconnectionobject, zoneid string) error {
func CreateZone(con modelpowerdns.PDNSconnectionobject, storepayload []byte) error {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones?rrsets=false"
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + "/zones?rrsets=false"

// T8D8
_, storeerr := httputils.ExecutePowerDNSRequest(http.MethodPost, zoneDataFileURL, apitoken,
Expand All @@ -107,7 +107,7 @@ func CreateZone(con modelpowerdns.PDNSconnectionobject, storepayload []byte) err
func ClearCache(zoneid string, con modelpowerdns.PDNSconnectionobject) {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/cache/flush?domain=" + zoneid
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + "/cache/flush?domain=" + zoneid

_, clearerr := httputils.ExecutePowerDNSRequest(http.MethodPut, zoneDataFileURL, apitoken, nil)
if clearerr != nil {
Expand All @@ -118,7 +118,7 @@ func ClearCache(zoneid string, con modelpowerdns.PDNSconnectionobject) {
func GetZoneMetaData(con modelpowerdns.PDNSconnectionobject, zoneid, metadatakind string) (string, error) {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones/" + zoneid + "/metadata/" + metadatakind
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + PowerDNSZoneURLPath + zoneid + "/metadata/" + metadatakind

resp, storeerr := httputils.ExecutePowerDNSRequest(http.MethodGet, zoneDataFileURL, apitoken, nil)
if storeerr != nil {
Expand All @@ -131,7 +131,7 @@ func GetZoneMetaData(con modelpowerdns.PDNSconnectionobject, zoneid, metadatakin
func RectifyZone(con modelpowerdns.PDNSconnectionobject, zoneid string) error {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones/" + zoneid + "/rectify"
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + PowerDNSZoneURLPath + zoneid + "/rectify"

_, storeerr := httputils.ExecutePowerDNSRequest(http.MethodPut, zoneDataFileURL, apitoken, nil)
if storeerr != nil {
Expand All @@ -144,7 +144,7 @@ func RectifyZone(con modelpowerdns.PDNSconnectionobject, zoneid string) error {
func AXFRRetrieve(con modelpowerdns.PDNSconnectionobject, zoneid string) error {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones/" + zoneid + "/axfr-retrieve"
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + PowerDNSZoneURLPath + zoneid + "/axfr-retrieve"

_, storeerr := httputils.ExecutePowerDNSRequest(http.MethodPut, zoneDataFileURL, apitoken, nil)
if storeerr != nil {
Expand All @@ -157,7 +157,7 @@ func AXFRRetrieve(con modelpowerdns.PDNSconnectionobject, zoneid string) error {
func SetZoneMetaData(con modelpowerdns.PDNSconnectionobject, zoneid string, storepayload []byte) error {
serverid := con.ServerID
apitoken := con.Apitoken
zoneDataFileURL := con.PowerDNSurl + "/api/v1/servers/" + serverid + "/zones/" + zoneid + "/metadata"
zoneDataFileURL := con.PowerDNSurl + PowerDNSServerBaseURL + serverid + PowerDNSZoneURLPath + zoneid + "/metadata"

_, storeerr := httputils.ExecutePowerDNSRequest(http.MethodPost, zoneDataFileURL, apitoken,
bytes.NewBuffer(storepayload))
Expand Down
5 changes: 3 additions & 2 deletions pkg/microservice/servicediscovery/servicediscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

consul "github.com/hashicorp/consul/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestServiceDiscovery_newClient(t *testing.T) {
Expand All @@ -21,7 +22,7 @@ func TestServiceDiscovery_newClient(t *testing.T) {

err := sd.newClient()

assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("fail_client_exists", func(t *testing.T) {
Expand All @@ -36,7 +37,7 @@ func TestServiceDiscovery_newClient(t *testing.T) {

err := sd.newClient()

assert.NoError(t, err)
require.NoError(t, err)
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/microservice/servicediscovery/serviceregistration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func TestServiceRegistration_generateServiceDiscoveryRegistration(t *testing.T)
require.NoError(t, err)
require.NotNil(t, actual)

assert.Equal(t, actual, api.AgentServiceRegistration{
assert.Equal(t, api.AgentServiceRegistration{
ID: "a1b2-c3d4-e5f6",
Name: "testservice",
Tags: []string{"test", "test2"},
Port: 4321,
Address: "test.local",
Meta: map[string]string{"test": "TEST"},
})
}, actual)
})

t.Run("fail", func(t *testing.T) {
Expand All @@ -55,7 +55,7 @@ func TestServiceRegistration_generateServiceDiscoveryRegistration(t *testing.T)
require.Error(t, err)
require.NotNil(t, actual)

assert.Equal(t, actual, api.AgentServiceRegistration{})
assert.Equal(t, api.AgentServiceRegistration{}, actual)
})
t.Run("port_parsing", func(t *testing.T) {
sr := ServiceRegistration{
Expand All @@ -74,7 +74,7 @@ func TestServiceRegistration_generateServiceDiscoveryRegistration(t *testing.T)
require.Error(t, err)
require.NotNil(t, actual)

assert.Equal(t, actual, api.AgentServiceRegistration{})
assert.Equal(t, api.AgentServiceRegistration{}, actual)
})
})
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/microservice/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ func Test_convertStringToInt(t *testing.T) {
t.Run("normal", func(t *testing.T) {
num, err := ConvertStringToInt("5")

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 5, num)
})

t.Run("negative", func(t *testing.T) {
num, err := ConvertStringToInt("-5")

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, -5, num)
})

t.Run("zero", func(t *testing.T) {
num, err := ConvertStringToInt("0")

assert.NoError(t, err)
require.NoError(t, err)
assert.Zero(t, num)
})
})
Expand All @@ -37,14 +37,14 @@ func Test_convertStringToInt(t *testing.T) {
t.Run("no_number", func(t *testing.T) {
num, err := ConvertStringToInt("abcd5")

assert.Error(t, err)
require.Error(t, err)
assert.Empty(t, num)
})

t.Run("empty", func(t *testing.T) {
num, err := ConvertStringToInt("")

assert.Error(t, err)
require.Error(t, err)
assert.Empty(t, num)
})
})
Expand Down Expand Up @@ -113,7 +113,7 @@ func Test_GenerateUUID(t *testing.T) {
t.Run("ok", func(t *testing.T) {
id, err := GenerateUUID()

assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, id)
assert.Len(t, id, 36)
})
Expand All @@ -139,14 +139,14 @@ func Test_EnsurePathExist(t *testing.T) {

err := EnsurePathExist(newTmpDir)

assert.NoError(t, err)
require.NoError(t, err)
assert.DirExists(t, newTmpDir)
})

t.Run("dir_exists", func(t *testing.T) {
err := EnsurePathExist(tmpDir)

assert.NoError(t, err)
require.NoError(t, err)
assert.DirExists(t, tmpDir)
})
})
Expand All @@ -155,7 +155,7 @@ func Test_EnsurePathExist(t *testing.T) {
t.Run("no_path_given", func(t *testing.T) {
err := EnsurePathExist("")

assert.EqualError(t, err, "mkdir : no such file or directory")
require.EqualError(t, err, "mkdir : no such file or directory")
})
})
}

0 comments on commit 4da56e6

Please sign in to comment.