goalteon

package module
v0.13.10 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 16 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 (
    "encoding/json"
    "fmt"
    "log"
    
    "github.com/ArthurHlt/goalteon"
    "github.com/ArthurHlt/goalteon/beans"
    
)

func main() {
    client := goalteon.NewClient("https://alteon-ip", "username", "password", goalteon.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 goalteon.Translate to translate only one object
    resTr := goalteon.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{}, goalteon.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 := goalteon.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([]*goalteon.BulkItem{
        {
            Method: goalteon.BulkMethodCreate,
            Bean: &beans.SlbNewCfgEnhVirtServerTable{
                SlbNewCfgEnhVirtServerIndex: "foo",
                Params:                    &beans.SlbNewCfgEnhVirtServerTableParams{
                    VirtServerIpAddress:      "172.16.0.2",
                },
            },
        },
        {
            Method: goalteon.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(&goalteon.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`),
        &goalteon.ImpExpAppShapeParams{
            ID: "proxy_protocol",
        },
    )
    if err != nil {
        log.Println(err)
    }
    
    // Config
    data, err := client.ExportConfig(&goalteon.ImpExpConfigParams{
        Pkey:       true,
        Passphrase: "radware",
    })
    if err != nil {
        log.Println(err)
    }
    fmt.Println(string(data))

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

    _, err = client.ImportSsl(data,
        &goalteon.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", goalteon.WithInsecureSkipVerify(true),
		// disable lock between change request
		goalteon.WithNoLock(),
		// disable auto apply save sync after a change(s) bean made by create/update/delete/bulk
		goalteon.WithNoAutoApplySaveSync(),
	)

	clientWithCustomLocker := goalteon.NewClient(
            "https://alteon-ip", "username", "password",
            goalteon.WithInsecureSkipVerify(true),
            goalteon.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 = 9000
)

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
	IgnoreErrors bool
}

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) ExportHcExtScript added in v0.6.0

func (c *Client) ExportHcExtScript(params *ImpExpHcExtScriptParams) ([]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) ImportAppShapeAsBulk added in v0.10.0

func (c *Client) ImportAppShapeAsBulk(data []byte, params *ImpExpAppShapeParams) (*BulkItem, error)

func (*Client) ImportConfig

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

func (*Client) ImportHcExtScript added in v0.6.0

func (c *Client) ImportHcExtScript(data []byte, params *ImpExpHcExtScriptParams) (*StatusResponse, error)

func (*Client) ImportHcExtScriptAsBulk added in v0.10.0

func (c *Client) ImportHcExtScriptAsBulk(data []byte, params *ImpExpHcExtScriptParams) (*BulkItem, error)

func (*Client) ImportSsl

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

func (*Client) ImportSslAsBulk added in v0.10.0

func (c *Client) ImportSslAsBulk(data []byte, params *ImpExpSslParams) (*BulkItem, error)

func (*Client) IsApplyPending added in v0.8.0

func (c *Client) IsApplyPending() (bool, 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) SetDebug added in v0.5.0

func (c *Client) SetDebug(debug bool)

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 ImpExpHcExtScriptParams added in v0.6.0

type ImpExpHcExtScriptParams struct {
	ID      string
	Name    string
	Disable bool
}

func (*ImpExpHcExtScriptParams) Values added in v0.6.0

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

type ImpExpSslParams

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

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 {
	NoApplyPending        bool
	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 {
	StatusCode int    `json:"-"`
	Status     string `json:"status"`
	Message    string `json:"message"`
	TestErr    string `json:"testErr"`
}

func UnmarshalStatus

func UnmarshalStatus(statusCode int, 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