goalteon

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 14 Imported by: 0

README

Goalteon

Goalteon is a golang client for Alteon made by Radware.

It handles by default concurrency call on Alteon.

Installation

run go get github.com/ArthurHlt/goalteon to install the package.

Usage

package main

import (
    "fmt"
    "github.com/ArthurHlt/goalteon"
)

func main() {
    client := goalteon.NewClient("https://alteon-ip", "username", "password", goalteaon.WithInsecureSkipVerify(true))
    
	// List all virtual server for example
	res, err := client.List(&beans.SlbNewCfgEnhVirtServerTable{}, nil)
    if err != nil {
        panic(err)
    }
	
	// translate to params list for ease usage
	// you can also use goalteaon.Translate to translate only one object
    resTr := goalteaon.TranslateList[*beans.SlbNewCfgEnhVirtServerTableParams](res)
    b, err := json.MarshalIndent(resTr, "", "  ")
    if err != nil {
        panic(err)
    }
    fmt.Println(string(b))
	
	// List all virtual server with only some properties
	res, err = client.List(&beans.SlbNewCfgEnhVirtServerTable{}, goalteaon.UrlParamsProps(nil, "VirtServerIpAddress", "VirtServerBwmContract"))
    if err != nil {
        panic(err)
    }
	fmt.Println(res)
	
	// Get one virtual server
	res, err = client.Get(&beans.SlbNewCfgEnhVirtServerTable{
        SlbNewCfgEnhVirtServerIndex: "foo",
    }, nil)
    if err != nil {
        panic(err)
    }
    resTrOne := goalteaon.Translate[*beans.SlbNewCfgEnhVirtServerTableParams](res)
	fmt.Println(resTrOne)
	
	// Create a virtual server
	// by default: one modifying request can be made at the same time with a mutex lock
	// it also revert all not saved change before applying changes
	// and finally apply, save and sync changes
    status, err := client.Create(&beans.SlbNewCfgEnhVirtServerTable{
        SlbNewCfgEnhVirtServerIndex: "foo",
        VirtServerIpAddress: "172.16.0.2",
    })
    if err != nil {
        panic(err)
    }
	fmt.Println(status)
	
	// Bulk changes example
	// It let you make multiple changes in one session and apply, save and sync all those changes
	statuses, err := client.Bulk([]*goalteaon.BulkItem{
        {
            Method: goalteaon.BulkMethodCreate,
            Bean: &beans.SlbNewCfgEnhVirtServerTable{
                SlbNewCfgEnhVirtServerIndex: "foo",
                Params:  				  &beans.SlbNewCfgEnhVirtServerTableParams{
                    VirtServerIpAddress:      "172.16.0.2",
                },
            },
        },
        {
            Method: goalteaon.BulkMethodCreate,
            Bean: &beans.SlbNewCfgEnhVirtServerTable{
                SlbNewCfgEnhVirtServerIndex: "foo2",
                Params:  				  &beans.SlbNewCfgEnhVirtServerTableParams{
                    VirtServerIpAddress:      "172.16.0.3",
                },
            },
        },
    })
	if err != nil {
        panic(err)
    }
	fmt.Println(statuses)
	
	// import/export
	
	// AppShape
    data, err := client.ExportAppShape(&goalteaon.ImpExpAppShapeParams{
        ID: "APM_script",
    })
    if err != nil {
        log.Println(err)
    }
    fmt.Println(string(data))

    _, err = client.ImportAppShape([]byte(`when CLIENT_ACCEPTED {
       TCP::collect
    }
    when CLIENT_DATA {
       TCP::payload replace 0 0 "PROXY TCP[IP::version] [IP::remote_addr] [IP::local_addr] [TCP::remote_port] [TCP::local_port]\r\n"
       TCP::release
    }
    -----END`),
        &goalteaon.ImpExpAppShapeParams{
            ID: "proxy_protocol",
        },
    )
    if err != nil {
        log.Println(err)
    }
	
	// Config
	data, err := client.ExportConfig(&goalteaon.ImpExpConfigParams{
        Pkey:       true,
        Passphrase: "radware",
    })
    if err != nil {
        log.Println(err)
    }
    fmt.Println(string(data))

    _, err = client.ImportConfig(data,
        &goalteaon.ImpExpConfigParams{
            Pkey:       true,
            Passphrase: "radware",
        },
    )
    if err != nil {
        log.Println(err)
    }
	
	// SSL
	data, err := client.ExportSsl(&goalteaon.ImpExpSslParams{
        ID: "WebManagementCert",
    })
    if err != nil {
        log.Println(err)
    }
    fmt.Println(string(data))

    _, err = client.ImportSsl(data,
        &goalteaon.ImpExpSslParams{
            ID: "WebManagementCert",
        },
    )
    if err != nil {
        log.Println(err)
    }
}

Advanced usage

package main

import (
	"github.com/ArthurHlt/goalteon"
	"sync"
)

// CustomLocker is dummy locker for show how to make a custom locker
// *sync.Mutex is already a valid Locker and by default goalteon use *sync.Mutex as locker
type CustomLocker struct {
	mutex *sync.Mutex
}

func (c *CustomLocker) Lock() {
	c.mutex.Lock()
}

func (c *CustomLocker) Unlock() {
	c.mutex.Unlock()
}

func main() {
	client := goalteon.NewClient(
		"https://alteon-ip", "username", "password",goalteaon.WithInsecureSkipVerify(true),
		// disable lock between change request
		goalteaon.WithNoLock(),
		// disable auto apply save sync after a change(s) bean made by create/update/delete/bulk
		goalteaon.WithNoAutoApplySaveSync(),
	)

	clientWithCustomLocker := goalteon.NewClient(
            "https://alteon-ip", "username", "password",
            goalteaon.WithInsecureSkipVerify(true),
            goalteaon.WithLocker(&CustomLocker{
                mutex: &sync.Mutex{},
            }),
	)
}

Generate beans

Run:

cd generator && ./generate.sh

Documentation

Index

Constants

View Source
const (
	UrlParamsKeyProp       = "prop"
	UrlParamsKeyProps      = "props"
	UrlParamsKeyOffset     = "offset"
	UrlParamsKeyCount      = "count"
	UrlParamsKeyAction     = "action"
	UrlParamsKeyFilter     = "filter"
	UrlParamsKeyFilterType = "filtertype"
)
View Source
const (
	DefaultCount = 1024
)

Variables

This section is empty.

Functions

func Translate

func Translate[T beans.BeanType](params beans.BeanType) T

func TranslateList

func TranslateList[T beans.BeanType](params []beans.BeanType) []T

func UnmarshalListResponse

func UnmarshalListResponse(resp *http.Response, bean beans.Bean) ([]beans.BeanType, error)

func UnmarshalResponse

func UnmarshalResponse(resp *http.Response, params beans.BeanType) error

func UrlParamsAction

func UrlParamsAction(prev url.Values, action string) url.Values

func UrlParamsCount

func UrlParamsCount(prev url.Values, count int) url.Values

func UrlParamsFilters

func UrlParamsFilters(prev url.Values, filterType FilterType, filters ...Filter) url.Values

func UrlParamsOffset

func UrlParamsOffset(prev url.Values, offset int) url.Values

func UrlParamsProps

func UrlParamsProps(prev url.Values, props ...string) url.Values

func WithInsecureSkipVerify

func WithInsecureSkipVerify(insecureSkipVerify bool) clientOpt

func WithLocker

func WithLocker(locker sync.Locker) clientOpt

func WithNoAutoApplySaveSync

func WithNoAutoApplySaveSync() clientOpt

func WithNoLock

func WithNoLock() clientOpt

Types

type AgApplyConfig

type AgApplyConfig int
const (
	AgApplyConfigApply      AgApplyConfig = 1
	AgApplyConfigIdle       AgApplyConfig = 2
	AgApplyConfigInProgress AgApplyConfig = 3
	AgApplyConfigComplete   AgApplyConfig = 4
	AgApplyConfigFailed     AgApplyConfig = 5
)

type AgSaveConfig

type AgSaveConfig int
const (
	AgSaveConfigSave         AgSaveConfig = 1
	AgSaveConfigIdle         AgSaveConfig = 2
	AgSaveConfigInProgress   AgSaveConfig = 3
	AgSaveConfigComplete     AgSaveConfig = 4
	AgSaveConfigFailed       AgSaveConfig = 5
	AgSaveConfigSaveNoBackup AgSaveConfig = 6
)

type AgSyncStatus

type AgSyncStatus int
const (
	AgSyncStatusIdle       AgSyncStatus = 0
	AgSyncStatusInProgress AgSyncStatus = 1
	AgSyncStatusSuccess    AgSyncStatus = 2
	AgSyncStatusFailure    AgSyncStatus = 3
)

type BulkItem

type BulkItem struct {
	Method    BulkMethod
	Bean      beans.Bean
	UrlParams url.Values
}

func NewBulkItem

func NewBulkItem(method BulkMethod, bean beans.Bean, urlParams url.Values) *BulkItem

type BulkMethod

type BulkMethod uint
const (
	BulkMethodPost BulkMethod = iota
	BulkMethodCreate
	BulkMethodPut
	BulkMethodUpdate
	BulkMethodDelete
)

func (BulkMethod) ToHttpMethod

func (m BulkMethod) ToHttpMethod() string

type Client

type Client struct {
	Target string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(target, user, password string, opts ...clientOpt) *Client

func (*Client) Apply

func (c *Client) Apply() (*StatusResponse, error)

func (*Client) ApplySaveSync

func (c *Client) ApplySaveSync() (st *StatusGlobal, err error)

func (*Client) Bulk

func (c *Client) Bulk(items []*BulkItem) ([]*StatusResponse, error)

func (*Client) Create

func (c *Client) Create(bean beans.Bean, urlParams url.Values) (*StatusResponse, error)

func (*Client) Delete

func (c *Client) Delete(bean beans.Bean, urlParams url.Values) (*StatusResponse, error)

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) ExportAppShape

func (c *Client) ExportAppShape(params *ImpExpAppShapeParams) ([]byte, error)

func (*Client) ExportConfig

func (c *Client) ExportConfig(params *ImpExpConfigParams) ([]byte, error)

func (*Client) ExportSsl

func (c *Client) ExportSsl(params *ImpExpSslParams) ([]byte, error)

func (*Client) Get

func (c *Client) Get(bean beans.Bean, urlParams url.Values) (beans.BeanType, error)

func (*Client) ImportAppShape

func (c *Client) ImportAppShape(data []byte, params *ImpExpAppShapeParams) (*StatusResponse, error)

func (*Client) ImportConfig

func (c *Client) ImportConfig(data []byte, params *ImpExpConfigParams) (*StatusResponse, error)

func (*Client) ImportSsl

func (c *Client) ImportSsl(data []byte, params *ImpExpSslParams) (*StatusResponse, error)

func (*Client) List

func (c *Client) List(bean beans.Bean, urlParams url.Values) ([]beans.BeanType, error)

func (*Client) Logout

func (c *Client) Logout() error

func (*Client) NewRequest

func (c *Client) NewRequest(method string, bean beans.Bean, urlParams url.Values) (*http.Request, error)

func (*Client) Post

func (c *Client) Post(bean beans.Bean, urlParams url.Values) (*StatusResponse, error)

func (*Client) Put

func (c *Client) Put(bean beans.Bean, urlParams url.Values) (*StatusResponse, error)

func (*Client) Revert

func (c *Client) Revert() (*StatusResponse, error)

func (*Client) RevertAll

func (c *Client) RevertAll() (*StatusResponse, error)

func (*Client) Save

func (c *Client) Save() (*StatusResponse, error)

func (*Client) ShowDiff

func (c *Client) ShowDiff() (string, error)

func (*Client) ShowDiffFlash

func (c *Client) ShowDiffFlash() (string, error)

func (*Client) StatusGlobal

func (c *Client) StatusGlobal() (*StatusGlobal, error)

func (*Client) Sync

func (c *Client) Sync() (*StatusResponse, error)

func (*Client) Update

func (c *Client) Update(bean beans.Bean, urlParams url.Values) (*StatusResponse, error)

type ConfigRecoveryType

type ConfigRecoveryType string
const (
	ConfigRecoveryTypeAll    ConfigRecoveryType = "all"
	ConfigRecoveryTypeVAdmin ConfigRecoveryType = "vadmin"
)

type ConfigType

type ConfigType string
const (
	ConfigTypeAll  ConfigType = "all"
	ConfigTypeVADC ConfigType = "vadc"
	ConfigTypePADC ConfigType = "padc"
)

type Filter

type Filter struct {
	Key   string
	Value string
}

func (Filter) String

func (f Filter) String() string

type FilterType

type FilterType string
const (
	FilterTypeExact FilterType = "exact"
	FilterTypeAny   FilterType = "any"
)

type ImpExpAppShapeParams

type ImpExpAppShapeParams struct {
	ID      string
	Name    string
	Disable bool
}

func (*ImpExpAppShapeParams) Values

func (i *ImpExpAppShapeParams) Values() url.Values

type ImpExpConfigParams

type ImpExpConfigParams struct {
	Pkey               bool
	Passphrase         string
	ManSync            bool
	ConfigType         ConfigType
	VADCList           []string
	ConfigRecoveryType ConfigRecoveryType
	SrcType            SrcType
}

func (*ImpExpConfigParams) Values

func (i *ImpExpConfigParams) Values() url.Values

type ImpExpSslParams

type ImpExpSslParams struct {
	ID         string
	SslType    SslType
	Passphrase string
	SrcType    SrcType
}

func (*ImpExpSslParams) Values

func (i *ImpExpSslParams) Values() url.Values

type NoLocker

type NoLocker struct{}

func (*NoLocker) Lock

func (*NoLocker) Lock()

func (*NoLocker) Unlock

func (*NoLocker) Unlock()

type SrcType

type SrcType string
const (
	ConfigSrcTypeTxt  SrcType = "txt"
	ConfigSrcTypeFile SrcType = "file"
)

type SslType

type SslType string
const (
	SslTypePair SslType = "pair"
	SslTypeCert SslType = "cert"
	SslTypeKey  SslType = "key"
	SslTypeInCA SslType = "inca"
	SslTypeCLCA SslType = "clca"
)

type StatusGlobal

type StatusGlobal struct {
	AgSaveConfig          AgSaveConfig `mapstructure:"agSaveConfig"`
	AgSaveLastError       error
	AgApplyConfig         AgApplyConfig `mapstructure:"agApplyConfig"`
	AgApplyLastError      error
	AgSyncStatus          AgSyncStatus `mapstructure:"agSyncStatus"`
	AgLastSyncErrorReason string       `mapstructure:"agLastSyncErrorReason"`
	AgLastSyncError       error
}

type StatusResponse

type StatusResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
}

func UnmarshalStatus

func UnmarshalStatus(data []byte) (*StatusResponse, error)

func UnmarshalStatusResponse

func UnmarshalStatusResponse(resp *http.Response) (*StatusResponse, error)

func (*StatusResponse) Error

func (s *StatusResponse) Error() string

func (*StatusResponse) IsError

func (s *StatusResponse) IsError() bool

func (*StatusResponse) String

func (s *StatusResponse) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL