Skip to content

Commit

Permalink
Merge pull request #8 from m-terra/feature/gslb-subresource-operators
Browse files Browse the repository at this point in the history
Feature/gslb subresource operators
  • Loading branch information
ureuzy authored Oct 3, 2022
2 parents dd9eea9 + 20905ee commit adfa2ff
Show file tree
Hide file tree
Showing 35 changed files with 876 additions and 585 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mocks: mockgen

GOLANGCI_LINT = ./bin/golangci-lint
lint-bin: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2)
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.2)

MOCKGEN = ./bin/mockgen
mockgen: ## Download mockgen locally if necessary.
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"

"github.com/ureuzy/acos-client-go/pkg/axapi/slb/virtualserver"
"github.com/ureuzy/acos-client-go/pkg/axapi/slb/virtualserverport"
"github.com/ureuzy/acos-client-go/pkg/axapi/slb/virtualserver/virtualserverport"
"github.com/ureuzy/acos-client-go/pkg/client"
)

Expand Down
1 change: 1 addition & 0 deletions pkg/axapi/activepartition/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

// Docs: https://acos.docs.a10networks.com/axapi/521p2/axapiv3/active_partition.html
// URI: /axapi/v3/active-partition

type operator struct {
utils.HTTPClient
Expand Down
10 changes: 10 additions & 0 deletions pkg/axapi/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package errors

import (
"errors"
"fmt"
"strings"

"github.com/ureuzy/acos-client-go/utils"
)
Expand Down Expand Up @@ -32,6 +34,14 @@ func (r *ResponseBody) Unwrap() error {
return r
}

func ArgsMismatchError(pathf string, vals []string) error {
cnt := strings.Count(pathf, "%")
if cnt != len(vals) {
return fmt.Errorf("wrong number of arguments: required: %d actual %d", cnt, len(vals))
}
return nil
}

func EmptyStringError(s string) error {
if s == "" {
return errors.New("identifier must be specified")
Expand Down
22 changes: 14 additions & 8 deletions pkg/axapi/gslb/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@ import (
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/policy"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/serviceip"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/site"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/site/siteipserver"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/zone"
"github.com/ureuzy/acos-client-go/pkg/axapi/gslb/zone/zoneservice"
"github.com/ureuzy/acos-client-go/pkg/rest"
"github.com/ureuzy/acos-client-go/utils"
)

const path = "gslb"

type Operator struct {
Policy rest.Operator[policy.Body, policy.ListBody]
ServiceIP rest.Operator[serviceip.Body, serviceip.ListBody]
Site rest.Operator[site.Body, site.ListBody]
Zone rest.Operator[zone.Body, zone.ListBody]
Policy rest.Operator[policy.Body, policy.ListBody]
ServiceIP rest.Operator[serviceip.Body, serviceip.ListBody]
Site rest.Operator[site.Body, site.ListBody]
SiteIPServer rest.Operator[siteipserver.Body, siteipserver.ListBody]
Zone rest.Operator[zone.Body, zone.ListBody]
ZoneService rest.Operator[zoneservice.Body, zoneservice.ListBody]
}

func New(c utils.HTTPClient) *Operator {
return &Operator{
Policy: policy.New(c, path),
ServiceIP: serviceip.New(c, path),
Site: site.New(c, path),
Zone: zone.New(c, path),
Policy: policy.New(c, path),
ServiceIP: serviceip.New(c, path),
Site: site.New(c, path),
SiteIPServer: siteipserver.New(c, path),
Zone: zone.New(c, path),
ZoneService: zoneservice.New(c, path),
}
}
73 changes: 31 additions & 42 deletions pkg/axapi/gslb/gslb_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package gslb_test

import (
"io"
"net/http"
"strings"
"testing"

"github.com/golang/mock/gomock"
. "github.com/onsi/gomega"
"github.com/ureuzy/acos-client-go/pkg/client"
"github.com/ureuzy/acos-client-go/pkg/mocks"
"github.com/ureuzy/acos-client-go/utils"
"github.com/ureuzy/acos-client-go/utils/testutils"
)

var cfg = client.Config{Host: "host", User: "user", Pass: "pwd", Debug: false}
Expand All @@ -22,16 +19,7 @@ func TestGetPolicy(t *testing.T) {
httpc := mocks.NewMockHTTPClient(mockCtrl)
c := mocks.GetMockClient(httpc, cfg)

body := io.NopCloser(strings.NewReader("{}"))

resp := &utils.Response{
Response: &http.Response{
StatusCode: http.StatusOK,
Body: body,
},
}

httpc.EXPECT().GET("gslb/policy/mypolicy").Return(resp, nil)
httpc.EXPECT().GET("gslb/policy/mypolicy").Return(testutils.ResponseOK(), nil)

res, err := c.Gslb.Policy.Get("mypolicy")
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -45,16 +33,7 @@ func TestGetServiceIP(t *testing.T) {
httpc := mocks.NewMockHTTPClient(mockCtrl)
c := mocks.GetMockClient(httpc, cfg)

body := io.NopCloser(strings.NewReader("{}"))

resp := &utils.Response{
Response: &http.Response{
StatusCode: http.StatusOK,
Body: body,
},
}

httpc.EXPECT().GET("gslb/service-ip/myip").Return(resp, nil)
httpc.EXPECT().GET("gslb/service-ip/myip").Return(testutils.ResponseOK(), nil)

res, err := c.Gslb.ServiceIP.Get("myip")
Ω(err).ShouldNot(HaveOccurred())
Expand All @@ -68,18 +47,23 @@ func TestGetSite(t *testing.T) {
httpc := mocks.NewMockHTTPClient(mockCtrl)
c := mocks.GetMockClient(httpc, cfg)

body := io.NopCloser(strings.NewReader("{}"))
httpc.EXPECT().GET("gslb/site/mysite").Return(testutils.ResponseOK(), nil)

resp := &utils.Response{
Response: &http.Response{
StatusCode: http.StatusOK,
Body: body,
},
}
res, err := c.Gslb.Site.Get("mysite")
Ω(err).ShouldNot(HaveOccurred())
Ω(res).ShouldNot(BeNil())
}

httpc.EXPECT().GET("gslb/site/mysite").Return(resp, nil)
func TestGetSiteIPServer(t *testing.T) {
RegisterTestingT(t)

res, err := c.Gslb.Site.Get("mysite")
mockCtrl := gomock.NewController(t)
httpc := mocks.NewMockHTTPClient(mockCtrl)
c := mocks.GetMockClient(httpc, cfg)

httpc.EXPECT().GET("gslb/site/mysite/ip-server/myserver").Return(testutils.ResponseOK(), nil)

res, err := c.Gslb.SiteIPServer.Get("mysite", "myserver")
Ω(err).ShouldNot(HaveOccurred())
Ω(res).ShouldNot(BeNil())
}
Expand All @@ -91,18 +75,23 @@ func TestGetZone(t *testing.T) {
httpc := mocks.NewMockHTTPClient(mockCtrl)
c := mocks.GetMockClient(httpc, cfg)

body := io.NopCloser(strings.NewReader("{}"))
httpc.EXPECT().GET("gslb/zone/myzone").Return(testutils.ResponseOK(), nil)

resp := &utils.Response{
Response: &http.Response{
StatusCode: http.StatusOK,
Body: body,
},
}
res, err := c.Gslb.Zone.Get("myzone")
Ω(err).ShouldNot(HaveOccurred())
Ω(res).ShouldNot(BeNil())
}

httpc.EXPECT().GET("gslb/zone/myzone").Return(resp, nil)
func TestGetZoneService(t *testing.T) {
RegisterTestingT(t)

res, err := c.Gslb.Zone.Get("myzone")
mockCtrl := gomock.NewController(t)
httpc := mocks.NewMockHTTPClient(mockCtrl)
c := mocks.GetMockClient(httpc, cfg)

httpc.EXPECT().GET("gslb/zone/myzone/service/myport+myservice").Return(testutils.ResponseOK(), nil)

res, err := c.Gslb.ZoneService.Get("myzone", "myport+myservice")
Ω(err).ShouldNot(HaveOccurred())
Ω(res).ShouldNot(BeNil())
}
84 changes: 1 addition & 83 deletions pkg/axapi/gslb/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package policy
import (
"fmt"

"github.com/ureuzy/acos-client-go/pkg/axapi/shared"
"github.com/ureuzy/acos-client-go/pkg/rest"
"github.com/ureuzy/acos-client-go/utils"
)

// Docs: https://acos.docs.a10networks.com/axapi/521p2/axapiv3/gslb_policy.html
// URI: /axapi/v3/gslb/policy/{name}

func New(c utils.HTTPClient, basePath string) rest.Operator[Body, ListBody] {
const path = "policy"
Expand All @@ -24,85 +24,3 @@ type Body struct {
}

type ListObjects []Object

// Object Docs: https://acos.docs.a10networks.com/axapi/521p2/axapiv3/gslb_policy.html#policy-attributes

type Object struct {
shared.AxaBase `json:",inline"`
Name string `json:"name,omitempty"`
HealthCheck shared.Boolean `json:"health-check,omitempty"`
HealthCheckPreferenceEnable shared.Boolean `json:"health-check-preference-enable,omitempty"`
HealthPreferenceTop int `json:"health-preference-top,omitempty"`
AmountFirst shared.Boolean `json:"amount-first,omitempty"`
WeightedIPEnable shared.Boolean `json:"weighted-ip-enable,omitempty"`
WeightedIPTotalHits shared.Boolean `json:"weighted-ip-total-hits,omitempty"`
WeightedSiteEnable shared.Boolean `json:"weighted-site-enable,omitempty"`
WeightedSiteTotalHits shared.Boolean `json:"weighted-site-total-hits,omitempty"`
WeightedAlias shared.Boolean `json:"weighted-alias,omitempty"`
ActiveServersEnable shared.Boolean `json:"active-servers-enable,omitempty"`
ActiveServersFailBreak shared.Boolean `json:"active-servers-fail-break,omitempty"`
BwCostEnable shared.Boolean `json:"bw-cost-enable,omitempty"`
BwCostFailBreak shared.Boolean `json:"bw-cost-fail-break,omitempty"`
Geographic shared.Boolean `json:"geographic,omitempty"`
NumSessionEnable shared.Boolean `json:"num-session-enable,omitempty"`
NumSessionTolerance int `json:"num-session-tolerance,omitempty"`
AdminPreference shared.Boolean `json:"admin-preference,omitempty"`
AliasAdminPreference shared.Boolean `json:"alias-admin-preference,omitempty"`
LeastResponse shared.Boolean `json:"least-response,omitempty"`
AdminIPEnable shared.Boolean `json:"admin-ip-enable,omitempty"`
AdminIPTopOnly shared.Boolean `json:"admin-ip-top-only,omitempty"`
OrderedIPTopOnly shared.Boolean `json:"ordered-ip-top-only,omitempty"`
RoundRobin shared.Boolean `json:"round-robin,omitempty"`
MetricForceCheck shared.Boolean `json:"metric-force-check,omitempty"`
IPList string `json:"ip-list,omitempty"`
MetricOrder shared.Boolean `json:"metric-order,omitempty"`
MetricType shared.Boolean `json:"metric-type,omitempty"` // "enum":[ "health-check", "weighted-ip", "weighted-site", "capacity", "active-servers", "active-rdt", "geographic", "connection-load", "num-session", "admin-preference", "bw-cost", "least-response", "admin-ip"]
Capacity Capacity `json:"capacity,omitempty"`
ConnectionLoad ConnectionLoad `json:"connection-load,omitempty"`
DNS DNS `json:"dns,omitempty"`
GeoLocationList []GeoLocation `json:"geo-location-list,omitempty"`
GeoLocationMatch GeoLocationMatch `json:"geo-location-match,omitempty"`
ActiveRdt ActiveRdt `json:"active-rdt,omitempty"`
AutoMap AutoMap `json:"auto-map,omitempty"`
EDNS EDNS `json:"edns,omitempty"`
}

type Capacity struct {
shared.AxaBase `json:",inline"`
// TODO
}

type ConnectionLoad struct {
shared.AxaBase `json:",inline"`
// TODO
}

type DNS struct {
shared.AxaBase `json:",inline"`
// TODO
}

type GeoLocation struct {
shared.AxaBase `json:",inline"`
// TODO
}

type GeoLocationMatch struct {
shared.AxaBase `json:",inline"`
// TODO
}

type ActiveRdt struct {
shared.AxaBase `json:",inline"`
// TODO
}

type AutoMap struct {
shared.AxaBase `json:",inline"`
// TODO
}

type EDNS struct {
shared.AxaBase `json:",inline"`
// TODO
}
85 changes: 85 additions & 0 deletions pkg/axapi/gslb/policy/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package policy

import "github.com/ureuzy/acos-client-go/pkg/axapi/shared"

// Object Docs: https://acos.docs.a10networks.com/axapi/521p2/axapiv3/gslb_policy.html#policy-attributes

type Object struct {
shared.AxaBase `json:",inline"`
Name string `json:"name,omitempty"`
HealthCheck shared.Boolean `json:"health-check,omitempty"`
HealthCheckPreferenceEnable shared.Boolean `json:"health-check-preference-enable,omitempty"`
HealthPreferenceTop int `json:"health-preference-top,omitempty"`
AmountFirst shared.Boolean `json:"amount-first,omitempty"`
WeightedIPEnable shared.Boolean `json:"weighted-ip-enable,omitempty"`
WeightedIPTotalHits shared.Boolean `json:"weighted-ip-total-hits,omitempty"`
WeightedSiteEnable shared.Boolean `json:"weighted-site-enable,omitempty"`
WeightedSiteTotalHits shared.Boolean `json:"weighted-site-total-hits,omitempty"`
WeightedAlias shared.Boolean `json:"weighted-alias,omitempty"`
ActiveServersEnable shared.Boolean `json:"active-servers-enable,omitempty"`
ActiveServersFailBreak shared.Boolean `json:"active-servers-fail-break,omitempty"`
BwCostEnable shared.Boolean `json:"bw-cost-enable,omitempty"`
BwCostFailBreak shared.Boolean `json:"bw-cost-fail-break,omitempty"`
Geographic shared.Boolean `json:"geographic,omitempty"`
NumSessionEnable shared.Boolean `json:"num-session-enable,omitempty"`
NumSessionTolerance int `json:"num-session-tolerance,omitempty"`
AdminPreference shared.Boolean `json:"admin-preference,omitempty"`
AliasAdminPreference shared.Boolean `json:"alias-admin-preference,omitempty"`
LeastResponse shared.Boolean `json:"least-response,omitempty"`
AdminIPEnable shared.Boolean `json:"admin-ip-enable,omitempty"`
AdminIPTopOnly shared.Boolean `json:"admin-ip-top-only,omitempty"`
OrderedIPTopOnly shared.Boolean `json:"ordered-ip-top-only,omitempty"`
RoundRobin shared.Boolean `json:"round-robin,omitempty"`
MetricForceCheck shared.Boolean `json:"metric-force-check,omitempty"`
IPList string `json:"ip-list,omitempty"`
MetricOrder shared.Boolean `json:"metric-order,omitempty"`
MetricType shared.Boolean `json:"metric-type,omitempty"` // "enum":[ "health-check", "weighted-ip", "weighted-site", "capacity", "active-servers", "active-rdt", "geographic", "connection-load", "num-session", "admin-preference", "bw-cost", "least-response", "admin-ip"]
Capacity Capacity `json:"capacity,omitempty"`
ConnectionLoad ConnectionLoad `json:"connection-load,omitempty"`
DNS DNS `json:"dns,omitempty"`
GeoLocationList []GeoLocation `json:"geo-location-list,omitempty"`
GeoLocationMatch GeoLocationMatch `json:"geo-location-match,omitempty"`
ActiveRdt ActiveRdt `json:"active-rdt,omitempty"`
AutoMap AutoMap `json:"auto-map,omitempty"`
EDNS EDNS `json:"edns,omitempty"`
}

type Capacity struct {
shared.AxaBase `json:",inline"`
// TODO
}

type ConnectionLoad struct {
shared.AxaBase `json:",inline"`
// TODO
}

type DNS struct {
shared.AxaBase `json:",inline"`
// TODO
}

type GeoLocation struct {
shared.AxaBase `json:",inline"`
// TODO
}

type GeoLocationMatch struct {
shared.AxaBase `json:",inline"`
// TODO
}

type ActiveRdt struct {
shared.AxaBase `json:",inline"`
// TODO
}

type AutoMap struct {
shared.AxaBase `json:",inline"`
// TODO
}

type EDNS struct {
shared.AxaBase `json:",inline"`
// TODO
}
Loading

0 comments on commit adfa2ff

Please sign in to comment.