Skip to content

Commit

Permalink
added health, active-partition and gslb endpoints. tests, linter, mak…
Browse files Browse the repository at this point in the history
…efile
  • Loading branch information
m-terra committed Aug 27, 2022
1 parent 740db7d commit 3d777a9
Show file tree
Hide file tree
Showing 34 changed files with 1,664 additions and 702 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*

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

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

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
41 changes: 41 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
run:
timeout: 1m
linters:
enable:
- asciicheck
- deadcode
- depguard
- dogsled
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- govet
- importas
- ineffassign
- megacheck
- misspell
- nakedret
- nolintlint
- revive
- staticcheck
- typecheck
- unconvert
- unused
- varcheck
disable:
# https://github.com/golangci/golangci-lint/issues/2649
- structcheck
linters-settings:
gosec:
# Exclude generated files
exclude-generated: true
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
106 changes: 106 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.0.1

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif

# DEFAULT_CHANNEL defines the default channel used in the bundle.
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
#
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# six-group.com/acos-client-go-bundle:$VERSION and six-group.com/acos-client-go-catalog:$VERSION.
IMAGE_TAG_BASE ?= six-group.com/acos-client-go

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

test: golint test-ci
test-ci: unit-test

golint: colanci-lint-bin ## Run go golangci-lint against code.
$(GOLANGCI_LINT) run --timeout 5m0s

unit-test: mocks
go test -v ./... --vet=off

# Generate mocks
mocks: mockgen
$(MOCKGEN) -source utils/http.go -destination pkg/mocks/utils/mock.go HttpClient

GOLANGCI_LINT = ./bin/golangci-lint
colanci-lint-bin: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected])

MOCKGEN = ./bin/mockgen
mockgen: ## Download mockgen locally if necessary.
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/[email protected])

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
}
endef

13 changes: 7 additions & 6 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package main

import (
"github.com/ureuzy/acos-client-go/pkg/axapi/slb/virtualserver"
"github.com/ureuzy/acos-client-go/pkg/axapi/slb/virtualserverport"
"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/client"
)

func main() {

config := client.Config{Host: "", User: "", Pass: "", Debug: false}
c, err := client.New(config, client.InsecureSkipVerify(true))
if err != nil {
Expand All @@ -20,16 +19,18 @@ func main() {
ip := "192.168.0.10"

virtualServer, err := c.Slb.VirtualServer.Create(&virtualserver.Body{
Object: virtualserver.Object{Name: name, IPAddress: ip}})
Object: virtualserver.Object{Name: name, IPAddress: ip},
})
if err != nil {
log.Fatal(err)
}

_, err = c.Slb.VirtualServerPort.CreateList(virtualServer.Name, &virtualserverport.ListBody{
_, err = c.Slb.VirtualServerPort.CreateList(&virtualserverport.ListBody{
ListObjects: virtualserverport.ListObjects{
virtualserverport.Object{PortNumber: 80, Protocol: "http"},
virtualserverport.Object{PortNumber: 443, Protocol: "https"},
}})
},
}, virtualServer.Name)
if err != nil {
log.Fatal(err)
}
Expand Down
14 changes: 13 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
module github.com/ureuzy/acos-client-go

go 1.17
go 1.18

require (
github.com/golang/mock v1.6.0
github.com/onsi/gomega v1.20.0
)

require (
github.com/google/go-cmp v0.5.8 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
39 changes: 39 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY=
github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q=
github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
40 changes: 40 additions & 0 deletions pkg/axapi/activepartition/partition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package activepartition

import (
"github.com/ureuzy/acos-client-go/pkg/axapi/errors"
"github.com/ureuzy/acos-client-go/utils"
)

// Docs: https://acos.docs.a10networks.com/axapi/521p2/axapiv3/active_partition.html

type operator struct {
utils.HTTPClient
basePath string
}

type Operator interface {
Set(object Partition) error
}

func New(c utils.HTTPClient) Operator {
const path = "active-partition"
return &operator{HTTPClient: c, basePath: path}
}

func (o *operator) Set(object Partition) error {
err := errors.EmptyStringError(object.CurrentPartitionName)
if err != nil {
return err
}

res, err := o.POST(o.basePath, object)
if err != nil {
return err
}

if res.HasError() {
return errors.Handle(res)
}

return nil
}
6 changes: 6 additions & 0 deletions pkg/axapi/activepartition/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package activepartition

type Partition struct {
CurrentPartitionName string `json:"curr_part_name"`
Shared bool `json:"shared"`
}
18 changes: 10 additions & 8 deletions pkg/axapi/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ import (
)

type operator struct {
utils.HttpClient
utils.HTTPClient
basePath string
}

type Operator interface {
Request(req *Request) (*AuthResponse, error)
Request(req *Request) (*Body, error)
}

func New(c utils.HttpClient) Operator {
return &operator{c}
func New(c utils.HTTPClient) Operator {
const path = "auth"
return &operator{HTTPClient: c, basePath: path}
}

func (o *operator) Request(req *Request) (*AuthResponse, error) {
res, err := o.POST("/auth", req)
func (o *operator) Request(req *Request) (*Body, error) {
res, err := o.POST(o.basePath, req)
if err != nil {
return nil, err
}

var response Response
if err = res.UnmarshalJson(&response); err != nil {
if err = res.UnmarshalJSON(&response); err != nil {
return nil, err
}

return response.AuthResponse, nil
return response.Body, nil
}
4 changes: 2 additions & 2 deletions pkg/axapi/auth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ type Credentials struct {
}

type Response struct {
*AuthResponse `json:"authresponse"`
*Body `json:"authresponse"`
}

type AuthResponse struct {
type Body struct {
Signature string `json:"signature"`
Description string `json:"description"`
}
2 changes: 1 addition & 1 deletion pkg/axapi/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func EmptyStringError(s string) error {

func Handle(response *utils.Response) error {
var errResponse ResponseBody
if err := response.UnmarshalJson(&errResponse); err != nil {
if err := response.UnmarshalJSON(&errResponse); err != nil {
return err
}
return &errResponse
Expand Down
Loading

0 comments on commit 3d777a9

Please sign in to comment.