Skip to content

Commit

Permalink
Merge pull request #6 from liquidweb/DNSZone
Browse files Browse the repository at this point in the history
added DNSZone endpoints
  • Loading branch information
jakdept committed Sep 27, 2023
2 parents 0e6a50d + b0a9ef0 commit f94bc4b
Show file tree
Hide file tree
Showing 10 changed files with 622 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

.lwapi.toml
.envrc
4 changes: 3 additions & 1 deletion client/api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
lwApi "github.com/liquidweb/go-lwApi"
lwApi "github.com/liquidweb/liquidweb-go/lib/legacy"

"github.com/liquidweb/liquidweb-go/asset"
network "github.com/liquidweb/liquidweb-go/network"
Expand All @@ -12,6 +12,7 @@ import (
// API is the structure that houses all of our various API clients that interact with various Storm resources.
type API struct {
NetworkDNS network.DNSBackend
NetworkDNSZone network.DNSZoneBackend
NetworkLoadBalancer network.LoadBalancerBackend
NetworkVIP network.VIPBackend
NetworkZone network.ZoneBackend
Expand All @@ -38,6 +39,7 @@ func NewAPI(username string, password string, url string, timeout int) (*API, er
}

api := &API{
NetworkDNSZone: &network.DNSZoneClient{Backend: client.httpClient},
NetworkDNS: &network.DNSClient{Backend: client.httpClient},
NetworkLoadBalancer: &network.LoadBalancerClient{Backend: client.httpClient},
NetworkVIP: &network.VIPClient{Backend: client.httpClient},
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
lwApi "github.com/liquidweb/go-lwApi"
lwApi "github.com/liquidweb/liquidweb-go/lib/legacy"
)

// Client provides the HTTP backend.
Expand Down
95 changes: 95 additions & 0 deletions examples/dns_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package network

import (
"flag"
"log"
"os"
"strings"
"testing"

"github.com/liquidweb/liquidweb-go/client"
"github.com/liquidweb/liquidweb-go/network"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var liveTest = flag.Bool("live", false, "set true to run live test")
var testZone = flag.String("zone", "", "given zone for dns tests")

func TestLiveListRecords(t *testing.T) {
if !*liveTest {
t.Skip("skipping live test")
}
if strings.TrimSpace(*testZone) == "" {
t.Skip("skipping zone test without zone")
}

username, password := os.Getenv("LWAPI_USERNAME"), os.Getenv("LWAPI_PASSWORD")
url := "https://api.liquidweb.com"
timeout := 60

api, err := client.NewAPI(username, password, url, timeout)
require.NoError(t, err, "failed to create API")

reqParams := network.DNSRecordParams{
Zone: *testZone,
}

dnsRecords, err := api.NetworkDNS.List(&reqParams)
require.NoError(t, err, "got an error using parameters %#v", reqParams)
assert.NotZero(t, len(dnsRecords.Items))
records := []string{}
for _, each := range dnsRecords.Items {
records = append(records, (each.Name + " => " + each.RData))
}
log.Printf("all zones on zone %s:\n%s\n",
*testZone, strings.Join(records, "\n"))
}

func TestLiveZones(t *testing.T) {
if !*liveTest {
t.Skip("skipping live test")
}

username, password := os.Getenv("LWAPI_USERNAME"), os.Getenv("LWAPI_PASSWORD")
url := "https://api.liquidweb.com"
timeout := 60

api, err := client.NewAPI(username, password, url, timeout)
require.NoError(t, err, "failed to create API")

dnsZones, err := api.NetworkDNSZone.ListAll()
require.NoError(t, err, "got an error sting domains")
assert.NotZero(t, len(dnsZones.Items))
zones := []string{}
for _, each := range dnsZones.Items {
zones = append(zones, each.Name)
}
log.Printf("all zones on account:\n%s\n", strings.Join(zones, "\n"))
}

func TestLiveRecordsListAll(t *testing.T) {
if !*liveTest {
t.Skip("skipping live test")
}
if strings.TrimSpace(*testZone) == "" {
t.Skip("skipping zone test without zone")
}

username, password := os.Getenv("LWAPI_USERNAME"), os.Getenv("LWAPI_PASSWORD")
url := "https://api.liquidweb.com"
timeout := 60

api, err := client.NewAPI(username, password, url, timeout)
require.NoError(t, err, "failed to create API")

dnsRecords, err := api.NetworkDNS.ListAll(*testZone)
require.NoError(t, err, "got an error listing records")
assert.NotZero(t, len(dnsRecords.Items))
records := []string{}
for _, each := range dnsRecords.Items {
records = append(records, (each.Name + " => " + each.RData))
}
log.Printf("all zones on zone %s:\n%s\n",
*testZone, strings.Join(records, "\n"))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/liquidweb/liquidweb-go
go 1.12

require (
github.com/liquidweb/go-lwApi v0.0.5
github.com/liquidweb/liquidweb-cli v0.6.9
github.com/stretchr/testify v1.5.1
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/liquidweb/go-lwApi v0.0.0-20190605172801-52a4864d2738/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs=
github.com/liquidweb/go-lwApi v0.0.5 h1:CT4cdXzJXmo0bon298kS7NeSk+Gt8/UHpWBBol1NGCA=
github.com/liquidweb/go-lwApi v0.0.5/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs=
github.com/liquidweb/liquidweb-cli v0.6.9 h1:acbIvdRauiwbxIsOCEMXGwF75aSJDbDiyAWPjVnwoYM=
github.com/liquidweb/liquidweb-cli v0.6.9/go.mod h1:cE1uvQ+x24NGUL75D0QagOFCG8Wdvmwu8aL9TLmA/eQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand Down
Loading

0 comments on commit f94bc4b

Please sign in to comment.