diff --git a/bigip.go b/bigip.go index 7bf958e..4953180 100644 --- a/bigip.go +++ b/bigip.go @@ -145,6 +145,12 @@ func NewTokenSession(host, user, passwd, loginProviderName string, configOptions // APICall is used to query the BIG-IP web API. func (b *BigIP) APICall(options *APIRequest) ([]byte, error) { var req *http.Request + if Debug { + fmt.Println() + fmt.Println("API CALL DEBUG Transport:", b.Transport) + fmt.Println("API CALL DEBUG ConfigOptions:", b.ConfigOptions) + fmt.Println() + } client := &http.Client{ Transport: b.Transport, Timeout: b.ConfigOptions.APICallTimeout, @@ -170,6 +176,14 @@ func (b *BigIP) APICall(options *APIRequest) ([]byte, error) { req.Header.Set("Content-Type", options.ContentType) } + if Debug { + fmt.Println() + fmt.Println("DEBUG URL:", url) + fmt.Println("DEBUG BODY:", options.Body) + fmt.Println("DEBUG CONTENT TYPE:", options.ContentType) + fmt.Println() + } + res, err := client.Do(req) if err != nil { return nil, err @@ -213,11 +227,22 @@ func (b *BigIP) delete(path ...string) error { } func (b *BigIP) post(body interface{}, path ...string) error { + if Debug { + fmt.Printf("About to marshal this struct: %+v \r\n", body) + } marshalJSON, err := jsonMarshal(body) if err != nil { return err } + if Debug { + fmt.Println() + fmt.Println("Request JSON Debug:") + fmt.Println() + fmt.Println(string(marshalJSON)) + fmt.Println() + } + req := &APIRequest{ Method: "post", URL: b.iControlPath(path), @@ -256,17 +281,33 @@ func (b *BigIP) getForEntity(e interface{}, path ...string) (error, bool) { ContentType: "application/json", } + if Debug { + fmt.Println() + fmt.Printf("REQUEST DEBUG: %+v \r\n", req) + fmt.Println() + } + resp, err := b.APICall(req) + // fmt.Println("DEBUG:" + string(resp)) if err != nil { var reqError RequestError json.Unmarshal(resp, &reqError) if reqError.Code == 404 { - return nil, false + return errors.New("Server returned a 404 for: " + req.URL), false } return err, false } + if Debug { + fmt.Println() + fmt.Println("RESPONSE STRING DEBUG:", string(resp)) + fmt.Println() + } + err = json.Unmarshal(resp, e) + if Debug { + fmt.Printf("RESPONSE STRUCT DEBUG: %+v \r\n", e) + } if err != nil { return err, false } @@ -302,6 +343,9 @@ func jsonMarshal(t interface{}) ([]byte, error) { buffer := &bytes.Buffer{} encoder := json.NewEncoder(buffer) encoder.SetEscapeHTML(false) + if Debug { + fmt.Printf("About to encode %+v \r\n", t) + } err := encoder.Encode(t) return buffer.Bytes(), err } diff --git a/certificate.go b/certificate.go new file mode 100644 index 0000000..0770a46 --- /dev/null +++ b/certificate.go @@ -0,0 +1,35 @@ +package bigip + +type SSLCertificateInfo struct { + FileName string `json:"file_name"` + IsBundled bool `json:"is_bundled"` + Certificate struct { + CertInfo struct { + ID string `json:"id"` + Email interface{} `json:"email"` + } `json:"cert_info"` + ExpirationString string `json:"expiration_string"` + CertType string `json:"cert_type"` + KeyType string `json:"key_type"` + Version int `json:"version"` + ExpirationDate int `json:"expiration_date"` + SerialNumber interface{} `json:"serial_number"` + BitLength int `json:"bit_length"` + Issuer struct { + DivisionName string `json:"division_name"` + StateName string `json:"state_name"` + LocalityName string `json:"locality_name"` + OrganizationName string `json:"organization_name"` + CountryName string `json:"country_name"` + CommonName string `json:"common_name"` + } `json:"issuer"` + Subject struct { + DivisionName string `json:"division_name"` + StateName string `json:"state_name"` + LocalityName string `json:"locality_name"` + OrganizationName string `json:"organization_name"` + CountryName string `json:"country_name"` + CommonName string `json:"common_name"` + } `json:"subject"` + } `json:"certificate"` +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..8060804 --- /dev/null +++ b/config.go @@ -0,0 +1,4 @@ +package bigip + +// Debug indicates that the program should print verbose debug information +var Debug = false diff --git a/const.go b/const.go new file mode 100644 index 0000000..4120ae3 --- /dev/null +++ b/const.go @@ -0,0 +1,34 @@ +package bigip + +const ( + uriLtm = "ltm" + uriNode = "node" + uriPool = "pool" + uriPoolMember = "members" + uriProfile = "profile" + uriServerSSL = "server-ssl" + uriClientSSL = "client-ssl" + uriProfileHttp = "http" + uriPersistences = "persistences" + uriPersistenceCookie = "cookie" + uriPersistenceSourceAddr = "source-addr" + uriPersistenceHash = "hash" + uriProfileTCP = "tcp" + uriProfileFTP = "ftp" + uriProfileUDP = "udp" + uriProfileFastL4 = "fastl4" + uriOneConnect = "one-connect" + uriVirtual = "virtual" + uriVirtualAddress = "virtual-address" + uriSnatPool = "snatpool" + uriMonitor = "monitor" + uriIRule = "rule" + uriPolicy = "policy" + uriDatagroup = "data-group" + uriInternal = "internal" + ENABLED = "enable" + DISABLED = "disable" + CONTEXT_SERVER = "serverside" + CONTEXT_CLIENT = "clientside" + CONTEXT_ALL = "all" +) diff --git a/dataGroup.go b/dataGroup.go new file mode 100644 index 0000000..ebaaac3 --- /dev/null +++ b/dataGroup.go @@ -0,0 +1,55 @@ +package bigip + +import "encoding/json" + +// DataGroups contains a list of data groups on the BIG-IP system. +type DataGroups struct { + SelfLink string `json:"selfLink,omitempty"` + Kind string `json:"kind,omitempty"` + DataGroups []DataGroup `json:"items,omitempty"` +} + +// DataGroups contains information about each data group. +type DataGroup struct { + Kind string `json:"kind,omitempty"` + Name string `json:"name"` + FullPath string `json:"fullPath,omitempty"` + Partition string `json:"tmPartition,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + Type string `json:"type,omitempty"` + Records []DataGroupRecord `json:"records"` +} + +type DataGroupRecord struct { + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + SubPath string `json:"subPath,omitempty"` + Data string `json:"data"` +} + +type dataGroupDTO struct { + Kind string `json:"kind,omitempty"` + Name string `json:"name,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Partition string `json:"tmPartition,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + Type string `json:"type,omitempty"` + Records []DataGroupRecord `json:"records,omitempty"` +} + +func (p *DataGroup) MarshalJSON() ([]byte, error) { + var dto dataGroupDTO + marshal(&dto, p) + return json.Marshal(dto) +} + +func (p *DataGroup) UnmarshalJSON(b []byte) error { + var dto dataGroupDTO + err := json.Unmarshal(b, &dto) + if err != nil { + return err + } + return marshal(p, &dto) +} diff --git a/httpProfile.go b/httpProfile.go new file mode 100644 index 0000000..cfa5bdc --- /dev/null +++ b/httpProfile.go @@ -0,0 +1,97 @@ +package bigip + +type HttpProfiles struct { + HttpProfiles []HttpProfile `json:"items"` +} + +type HttpProfile struct { + Kind string `json:"kind,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + AcceptXff string `json:"acceptXff,omitempty"` + Enforcement struct { + ExcessClientHeaders string `json:"excessClientHeaders,omitempty"` + ExcessServerHeaders string `json:"excessServerHeaders,omitempty"` + MaxHeaderCount int `json:"maxHeaderCount,omitempty"` + MaxHeaderSize int `json:"maxHeaderSize,omitempty"` + MaxRequests int `json:"maxRequests,omitempty"` + OversizeClientHeaders string `json:"oversizeClientHeaders,omitempty"` + OversizeServerHeaders string `json:"oversizeServerHeaders,omitempty"` + Pipeline string `json:"pipeline,omitempty"` + TruncatedRedirects string `json:"truncatedRedirects,omitempty"` + UnknownMethod string `json:"unknownMethod,omitempty"` + } `json:"enforcement,omitempty"` + ExplicitProxy struct { + DefaultConnectHandling string `json:"defaultConnectHandling,omitempty"` + } `json:"explicitProxy,omitempty"` + InsertXforwardedFor string `json:"insertXforwardedFor,omitempty"` + LwsWidth int `json:"lwsWidth,omitempty"` + OneconnectTransformations string `json:"oneconnectTransformations,omitempty"` + ProxyType string `json:"proxyType,omitempty"` + RequestChunking string `json:"requestChunking,omitempty"` + ResponseChunking string `json:"responseChunking,omitempty"` + ServerAgentName string `json:"serverAgentName,omitempty"` + Sflow struct { + PollInterval int `json:"pollInterval,omitempty"` + PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"` + SamplingRate int `json:"samplingRate,omitempty"` + SamplingRateGlobal string `json:"samplingRateGlobal,omitempty"` + } `json:"sflow,omitempty"` + ViaRequest string `json:"viaRequest,omitempty"` + ViaResponse string `json:"viaResponse,omitempty"` +} + +// HttpProfiles returns a list of http profiles. +func (b *BigIP) HttpProfiles() (*HttpProfiles, error) { + var httpProfiles HttpProfiles + err, _ := b.getForEntity(&httpProfiles, uriLtm, uriProfile, uriProfileHttp) + if err != nil { + return nil, err + } + + return &httpProfiles, nil +} + +// GetHttpProfile gets a http profile by name. Returns nil if the http profile does not exist +func (b *BigIP) GetHttpProfile(name string) (*HttpProfile, error) { + var httpProfile HttpProfile + err, ok := b.getForEntity(&httpProfile, uriLtm, uriProfile, uriProfileHttp, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &httpProfile, nil +} + +// CreateHttpProfile creates a new http profile on the BIG-IP system. +func (b *BigIP) CreateHttpProfile(name string, parent string) error { + config := &HttpProfile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriProfileHttp) +} + +// AddHttpProfile adds a new http profile on the BIG-IP system. +func (b *BigIP) AddHttpProfile(config *HttpProfile) error { + return b.post(config, uriLtm, uriProfile, uriProfileHttp) +} + +// DeleteHttpProfile removes a http profile. +func (b *BigIP) DeleteHttpProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriProfileHttp, name) +} + +// ModifyHttpProfile allows you to change any attribute of a http profile. +// Fields that can be modified are referenced in the HttpProfile struct. +func (b *BigIP) ModifyHttpProfile(name string, config *HttpProfile) error { + return b.put(config, uriLtm, uriProfile, uriProfileHttp, name) +} diff --git a/iRule.go b/iRule.go new file mode 100644 index 0000000..7c02b78 --- /dev/null +++ b/iRule.go @@ -0,0 +1,56 @@ +package bigip + +// IRules returns a list of irules +func (b *BigIP) IRules() (*IRules, error) { + var rules IRules + err, _ := b.getForEntity(&rules, uriLtm, uriIRule) + if err != nil { + return nil, err + } + + return &rules, nil +} + +// IRule returns information about the given iRule. +func (b *BigIP) IRule(name string) (*IRule, error) { + var rule IRule + err, ok := b.getForEntity(&rule, uriLtm, uriIRule, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + return &rule, nil +} + +// CreateIRule creates a new iRule on the system. +func (b *BigIP) CreateIRule(name, rule string) error { + irule := &IRule{ + Name: name, + Rule: rule, + } + return b.post(irule, uriLtm, uriIRule) +} + +// DeleteIRule removes an iRule from the system. +func (b *BigIP) DeleteIRule(name string) error { + return b.delete(uriLtm, uriIRule, name) +} + +// ModifyIRule updates the given iRule with any changed values. +func (b *BigIP) ModifyIRule(name string, irule *IRule) error { + irule.Name = name + return b.put(irule, uriLtm, uriIRule, name) +} + +type IRules struct { + IRules []IRule `json:"items"` +} + +type IRule struct { + Name string `json:"name,omitempty"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Rule string `json:"apiAnonymous,omitempty"` +} diff --git a/ltm.go b/ltm.go index fdd1acd..598bf85 100644 --- a/ltm.go +++ b/ltm.go @@ -2,200 +2,12 @@ package bigip import ( "encoding/json" + "errors" "fmt" + "strconv" "strings" ) -// ServerSSLProfiles -// Documentation: https://devcentral.f5.com/wiki/iControlREST.APIRef_tm_ltm_profile_server-ssl.ashx - -// ServerSSLProfiles contains a list of every server-ssl profile on the BIG-IP system. -type ServerSSLProfiles struct { - ServerSSLProfiles []ServerSSLProfile `json:"items"` -} - -// ServerSSLProfile contains information about each server-ssl profile. You can use all -// of these fields when modifying a server-ssl profile. -type ServerSSLProfile struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Generation int `json:"generation,omitempty"` - AlertTimeout string `json:"alertTimeout,omitempty"` - Authenticate string `json:"authenticate,omitempty"` - AuthenticateDepth int `json:"authenticateDepth,omitempty"` - CaFile string `json:"caFile,omitempty"` - CacheSize int `json:"cacheSize,omitempty"` - CacheTimeout int `json:"cacheTimeout,omitempty"` - Cert string `json:"cert,omitempty"` - Chain string `json:"chain,omitempty"` - Ciphers string `json:"ciphers,omitempty"` - DefaultsFrom string `json:"defaultsFrom,omitempty"` - ExpireCertResponseControl string `json:"expireCertResponseControl,omitempty"` - GenericAlert string `json:"genericAlert,omitempty"` - HandshakeTimeout string `json:"handshakeTimeout,omitempty"` - Key string `json:"key,omitempty"` - ModSslMethods string `json:"modSslMethods,omitempty"` - Mode string `json:"mode,omitempty"` - TmOptions []string `json:"tmOptions,omitempty"` - Passphrase string `json:"passphrase,omitempty"` - PeerCertMode string `json:"peerCertMode,omitempty"` - ProxySsl string `json:"proxySsl,omitempty"` - RenegotiatePeriod string `json:"renegotiatePeriod,omitempty"` - RenegotiateSize string `json:"renegotiateSize,omitempty"` - Renegotiation string `json:"renegotiation,omitempty"` - RetainCertificate string `json:"retainCertificate,omitempty"` - SecureRenegotiation string `json:"secureRenegotiation,omitempty"` - ServerName string `json:"serverName,omitempty"` - SessionMirroring string `json:"sessionMirroring,omitempty"` - SessionTicket string `json:"sessionTicket,omitempty"` - SniDefault string `json:"sniDefault,omitempty"` - SniRequire string `json:"sniRequire,omitempty"` - SslForwardProxy string `json:"sslForwardProxy,omitempty"` - SslForwardProxyBypass string `json:"sslForwardProxyBypass,omitempty"` - SslSignHash string `json:"sslSignHash,omitempty"` - StrictResume string `json:"strictResume,omitempty"` - UncleanShutdown string `json:"uncleanShutdown,omitempty"` - UntrustedCertResponseControl string `json:"untrustedCertResponseControl,omitempty"` -} - -// ClientSSLProfiles -// Documentation: https://devcentral.f5.com/wiki/iControlREST.APIRef_tm_ltm_profile_client-ssl.ashx - -// ClientSSLProfiles contains a list of every client-ssl profile on the BIG-IP system. -type ClientSSLProfiles struct { - ClientSSLProfiles []ClientSSLProfile `json:"items"` -} - -// ClientSSLProfile contains information about each client-ssl profile. You can use all -// of these fields when modifying a client-ssl profile. -type ClientSSLProfile struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Generation int `json:"generation,omitempty"` - AlertTimeout string `json:"alertTimeout,omitempty"` - AllowNonSsl string `json:"allowNonSsl,omitempty"` - Authenticate string `json:"authenticate,omitempty"` - AuthenticateDepth int `json:"authenticateDepth,omitempty"` - CaFile string `json:"caFile,omitempty"` - CacheSize int `json:"cacheSize,omitempty"` - CacheTimeout int `json:"cacheTimeout,omitempty"` - Cert string `json:"cert,omitempty"` - CertKeyChain []struct { - Name string `json:"name,omitempty"` - Cert string `json:"cert,omitempty"` - Chain string `json:"chain,omitempty"` - Key string `json:"key,omitempty"` - Passphrase string `json:"passphrase,omitempty"` - } `json:"certKeyChain,omitempty"` - CertExtensionIncludes []string `json:"certExtensionIncludes,omitempty"` - CertLifespan int `json:"certLifespan,omitempty"` - CertLookupByIpaddrPort string `json:"certLookupByIpaddrPort,omitempty"` - Chain string `json:"chain,omitempty"` - Ciphers string `json:"ciphers,omitempty"` - ClientCertCa string `json:"clientCertCa,omitempty"` - CrlFile string `json:"crlFile,omitempty"` - DefaultsFrom string `json:"defaultsFrom,omitempty"` - ForwardProxyBypassDefaultAction string `json:"forwardProxyBypassDefaultAction,omitempty"` - GenericAlert string `json:"genericAlert,omitempty"` - HandshakeTimeout string `json:"handshakeTimeout,omitempty"` - InheritCertkeychain string `json:"inheritCertkeychain,omitempty"` - Key string `json:"key,omitempty"` - ModSslMethods string `json:"modSslMethods,omitempty"` - Mode string `json:"mode,omitempty"` - TmOptions []string `json:"tmOptions,omitempty"` - Passphrase string `json:"passphrase,omitempty"` - PeerCertMode string `json:"peerCertMode,omitempty"` - ProxyCaCert string `json:"proxyCaCert,omitempty"` - ProxyCaKey string `json:"proxyCaKey,omitempty"` - ProxyCaPassphrase string `json:"proxyCaPassphrase,omitempty"` - ProxySsl string `json:"proxySsl,omitempty"` - ProxySslPassthrough string `json:"proxySslPassthrough,omitempty"` - RenegotiatePeriod string `json:"renegotiatePeriod,omitempty"` - RenegotiateSize string `json:"renegotiateSize,omitempty"` - Renegotiation string `json:"renegotiation,omitempty"` - RetainCertificate string `json:"retainCertificate,omitempty"` - SecureRenegotiation string `json:"secureRenegotiation,omitempty"` - ServerName string `json:"serverName,omitempty"` - SessionMirroring string `json:"sessionMirroring,omitempty"` - SessionTicket string `json:"sessionTicket,omitempty"` - SniDefault string `json:"sniDefault,omitempty"` - SniRequire string `json:"sniRequire,omitempty"` - SslForwardProxy string `json:"sslForwardProxy,omitempty"` - SslForwardProxyBypass string `json:"sslForwardProxyBypass,omitempty"` - SslSignHash string `json:"sslSignHash,omitempty"` - StrictResume string `json:"strictResume,omitempty"` - UncleanShutdown string `json:"uncleanShutdown,omitempty"` -} - -// Nodes contains a list of every node on the BIG-IP system. -type Nodes struct { - Nodes []Node `json:"items"` -} - -// Node contains information about each individual node. You can use all -// of these fields when modifying a node. -type Node struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Generation int `json:"generation,omitempty"` - Address string `json:"address,omitempty"` - ConnectionLimit int `json:"connectionLimit,omitempty"` - DynamicRatio int `json:"dynamicRatio,omitempty"` - Logging string `json:"logging,omitempty"` - Monitor string `json:"monitor,omitempty"` - RateLimit string `json:"rateLimit,omitempty"` - Ratio int `json:"ratio,omitempty"` - Session string `json:"session,omitempty"` - State string `json:"state,omitempty"` -} - -// DataGroups contains a list of data groups on the BIG-IP system. -type DataGroups struct { - DataGroups []DataGroup `json:"items"` -} - -// DataGroups contains information about each data group. -type DataGroup struct { - Name string - Partition string - FullPath string - Generation int - Type string - Records []DataGroupRecord -} - -type DataGroupRecord struct { - Name string `json:"name,omitempty"` - Data string `json:"data,omitempty"` -} - -type dataGroupDTO struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Generation int `json:"generation,omitempty"` - Type string `json:"type,omitempty"` - Records []DataGroupRecord `json:"records,omitempty"` -} - -func (p *DataGroup) MarshalJSON() ([]byte, error) { - var dto dataGroupDTO - marshal(&dto, p) - return json.Marshal(dto) -} - -func (p *DataGroup) UnmarshalJSON(b []byte) error { - var dto dataGroupDTO - err := json.Unmarshal(b, &dto) - if err != nil { - return err - } - return marshal(p, &dto) -} - // SnatPools contains a list of every snatpool on the BIG-IP system. type SnatPools struct { SnatPools []SnatPool `json:"items"` @@ -216,69 +28,6 @@ type Pools struct { Pools []Pool `json:"items"` } -// Pool contains information about each pool. You can use all of these -// fields when modifying a pool. -type Pool struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Generation int `json:"generation,omitempty"` - AllowNAT string `json:"allowNat,omitempty"` - AllowSNAT string `json:"allowSnat,omitempty"` - IgnorePersistedWeight string `json:"ignorePersistedWeight,omitempty"` - IPTOSToClient string `json:"ipTosToClient,omitempty"` - IPTOSToServer string `json:"ipTosToServer,omitempty"` - LinkQoSToClient string `json:"linkQosToClient,omitempty"` - LinkQoSToServer string `json:"linkQosToServer,omitempty"` - LoadBalancingMode string `json:"loadBalancingMode,omitempty"` - MinActiveMembers int `json:"minActiveMembers,omitempty"` - MinUpMembers int `json:"minUpMembers,omitempty"` - MinUpMembersAction string `json:"minUpMembersAction,omitempty"` - MinUpMembersChecking string `json:"minUpMembersChecking,omitempty"` - Monitor string `json:"monitor,omitempty"` - QueueDepthLimit int `json:"queueDepthLimit,omitempty"` - QueueOnConnectionLimit string `json:"queueOnConnectionLimit,omitempty"` - QueueTimeLimit int `json:"queueTimeLimit,omitempty"` - ReselectTries int `json:"reselectTries,omitempty"` - ServiceDownAction string `json:"serviceDownAction,omitempty"` - SlowRampTime int `json:"slowRampTime,omitempty"` -} - -// Pool Members contains a list of pool members within a pool on the BIG-IP system. -type PoolMembers struct { - PoolMembers []PoolMember `json:"items"` -} - -// poolMember is used only when adding members to a pool. -type poolMember struct { - Name string `json:"name"` -} - -// poolMembers is used only when modifying members on a pool. -type poolMembers struct { - Members []PoolMember `json:"members"` -} - -// Pool Member contains information about each individual member in a pool. You can use all -// of these fields when modifying a pool member. -type PoolMember struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Generation int `json:"generation,omitempty"` - Address string `json:"address,omitempty"` - ConnectionLimit int `json:"connectionLimit,omitempty"` - DynamicRatio int `json:"dynamicRatio,omitempty"` - InheritProfile string `json:"inheritProfile,omitempty"` - Logging string `json:"logging,omitempty"` - Monitor string `json:"monitor,omitempty"` - PriorityGroup int `json:"priorityGroup,omitempty"` - RateLimit string `json:"rateLimit,omitempty"` - Ratio int `json:"ratio,omitempty"` - Session string `json:"session,omitempty"` - State string `json:"state,omitempty"` -} - // VirtualServers contains a list of all virtual servers on the BIG-IP system. type VirtualServers struct { VirtualServers []VirtualServer `json:"items"` @@ -718,26 +467,27 @@ type Monitors struct { // Monitor contains information about each individual monitor. type Monitor struct { - Name string - Partition string - FullPath string - Generation int - ParentMonitor string - Description string - Destination string - Interval int - IPDSCP int - ManualResume bool - Password string - ReceiveString string - ReceiveDisable string - Reverse bool - SendString string - TimeUntilUp int - Timeout int - Transparent bool - UpInterval int - Username string + Name string `json:"name"` + Type string `json:"-,omitempty"` + Partition string `json:"tmPartition,omitempty"` + FullPath string `json:"-,omitempty"` + Generation int `json:"generation,omitempty"` + ParentMonitor string `json:"defaultsFrom,omitempty"` + Description string `json:"description,omitempty"` + Destination string `json:"destination,omitempty"` + Interval int `json:"interval,omitempty"` + IPDSCP int `json:"-,omitempty"` + ManualResume bool `json:"manualResumej,omitempty"` + Password string `json:"password,omitempty"` + ReceiveString string `json:"-,omitempty"` + ReceiveDisable string `json:"-,omitempty"` + // Reverse string `json:"-,omitempty"` + SendString string `json:"-,omitempty"` + TimeUntilUp int `json:"timeUntilUp,omitempty"` + Timeout int `json:"timeout,omitempty"` + // Transparent bool `json:"-,omitempty"` + UpInterval int `json:"upInterval,omitempty"` + Username string `json:"-,omitempty"` } type monitorDTO struct { @@ -789,43 +539,10 @@ type Profile struct { Name string `json:"name,omitempty"` FullPath string `json:"fullPath,omitempty"` Partition string `json:"partition,omitempty"` + Type string `json:"-"` Context string `json:"context,omitempty"` } -type IRules struct { - IRules []IRule `json:"items"` -} - -type IRule struct { - Name string `json:"name,omitempty"` - Partition string `json:"partition,omitempty"` - FullPath string `json:"fullPath,omitempty"` - Rule string `json:"apiAnonymous,omitempty"` -} - -const ( - uriLtm = "ltm" - uriNode = "node" - uriPool = "pool" - uriPoolMember = "members" - uriProfile = "profile" - uriServerSSL = "server-ssl" - uriClientSSL = "client-ssl" - uriVirtual = "virtual" - uriVirtualAddress = "virtual-address" - uriSnatPool = "snatpool" - uriMonitor = "monitor" - uriIRule = "rule" - uriPolicy = "policy" - uriDatagroup = "data-group" - uriInternal = "internal" - ENABLED = "enable" - DISABLED = "disable" - CONTEXT_SERVER = "serverside" - CONTEXT_CLIENT = "clientside" - CONTEXT_ALL = "all" -) - var cidr = map[string]string{ "0": "0.0.0.0", "1": "128.0.0.0", @@ -914,108 +631,6 @@ func (b *BigIP) ModifySnatPool(name string, config *SnatPool) error { return b.put(config, uriLtm, uriSnatPool, name) } -// ServerSSLProfiles returns a list of server-ssl profiles. -func (b *BigIP) ServerSSLProfiles() (*ServerSSLProfiles, error) { - var serverSSLProfiles ServerSSLProfiles - err, _ := b.getForEntity(&serverSSLProfiles, uriLtm, uriProfile, uriServerSSL) - if err != nil { - return nil, err - } - - return &serverSSLProfiles, nil -} - -// GetServerSSLProfile gets a server-ssl profile by name. Returns nil if the server-ssl profile does not exist -func (b *BigIP) GetServerSSLProfile(name string) (*ServerSSLProfile, error) { - var serverSSLProfile ServerSSLProfile - err, ok := b.getForEntity(&serverSSLProfile, uriLtm, uriProfile, uriServerSSL, name) - if err != nil { - return nil, err - } - if !ok { - return nil, nil - } - - return &serverSSLProfile, nil -} - -// CreateServerSSLProfile creates a new server-ssl profile on the BIG-IP system. -func (b *BigIP) CreateServerSSLProfile(name string, parent string) error { - config := &ServerSSLProfile{ - Name: name, - DefaultsFrom: parent, - } - - return b.post(config, uriLtm, uriProfile, uriServerSSL) -} - -// AddServerSSLProfile adds a new server-ssl profile on the BIG-IP system. -func (b *BigIP) AddServerSSLProfile(config *ServerSSLProfile) error { - return b.post(config, uriLtm, uriProfile, uriServerSSL) -} - -// DeleteServerSSLProfile removes a server-ssl profile. -func (b *BigIP) DeleteServerSSLProfile(name string) error { - return b.delete(uriLtm, uriProfile, uriServerSSL, name) -} - -// ModifyServerSSLProfile allows you to change any attribute of a sever-ssl profile. -// Fields that can be modified are referenced in the VirtualServer struct. -func (b *BigIP) ModifyServerSSLProfile(name string, config *ServerSSLProfile) error { - return b.put(config, uriLtm, uriProfile, uriServerSSL, name) -} - -// ClientSSLProfiles returns a list of client-ssl profiles. -func (b *BigIP) ClientSSLProfiles() (*ClientSSLProfiles, error) { - var clientSSLProfiles ClientSSLProfiles - err, _ := b.getForEntity(&clientSSLProfiles, uriLtm, uriProfile, uriClientSSL) - if err != nil { - return nil, err - } - - return &clientSSLProfiles, nil -} - -// GetClientSSLProfile gets a client-ssl profile by name. Returns nil if the client-ssl profile does not exist -func (b *BigIP) GetClientSSLProfile(name string) (*ClientSSLProfile, error) { - var clientSSLProfile ClientSSLProfile - err, ok := b.getForEntity(&clientSSLProfile, uriLtm, uriProfile, uriClientSSL, name) - if err != nil { - return nil, err - } - if !ok { - return nil, nil - } - - return &clientSSLProfile, nil -} - -// CreateClientSSLProfile creates a new client-ssl profile on the BIG-IP system. -func (b *BigIP) CreateClientSSLProfile(name string, parent string) error { - config := &ClientSSLProfile{ - Name: name, - DefaultsFrom: parent, - } - - return b.post(config, uriLtm, uriProfile, uriClientSSL) -} - -// AddClientSSLProfile adds a new client-ssl profile on the BIG-IP system. -func (b *BigIP) AddClientSSLProfile(config *ClientSSLProfile) error { - return b.post(config, uriLtm, uriProfile, uriClientSSL) -} - -// DeleteClientSSLProfile removes a client-ssl profile. -func (b *BigIP) DeleteClientSSLProfile(name string) error { - return b.delete(uriLtm, uriProfile, uriClientSSL, name) -} - -// ModifyClientSSLProfile allows you to change any attribute of a client-ssl profile. -// Fields that can be modified are referenced in the ClientSSLProfile struct. -func (b *BigIP) ModifyClientSSLProfile(name string, config *ClientSSLProfile) error { - return b.put(config, uriLtm, uriProfile, uriClientSSL, name) -} - // Nodes returns a list of nodes. func (b *BigIP) Nodes() (*Nodes, error) { var nodes Nodes @@ -1109,161 +724,27 @@ func (b *BigIP) ModifyInternalDataGroupRecords(name string, records *[]DataGroup return b.put(config, uriLtm, uriDatagroup, uriInternal, name) } -// Get the internal data group records for a named internal data group -func (b *BigIP) GetInternalDataGroupRecords(name string) (*[]DataGroupRecord, error) { - var dataGroupRecords []DataGroupRecord - err, _ := b.getForEntity(&dataGroupRecords, uriLtm, uriDatagroup, uriInternal, name) - if err != nil { - return nil, err - } - - return &dataGroupRecords, nil -} - -// Pools returns a list of pools. -func (b *BigIP) Pools() (*Pools, error) { - var pools Pools - err, _ := b.getForEntity(&pools, uriLtm, uriPool) +// GestInternalDataGroup Gets the internal data group records for a named internal data group +func (b *BigIP) GetInternalDataGroup(name string) (*DataGroup, error) { + var dataGroup DataGroup + err, _ := b.getForEntity(&dataGroup, uriLtm, uriDatagroup, uriInternal, name) if err != nil { return nil, err } - return &pools, nil + return &dataGroup, nil } -// PoolMembers returns a list of pool members for the given pool. -func (b *BigIP) PoolMembers(name string) (*PoolMembers, error) { - var poolMembers PoolMembers - err, _ := b.getForEntity(&poolMembers, uriLtm, uriPool, name, uriPoolMember) - if err != nil { - return nil, err - } - - return &poolMembers, nil -} - -// AddPoolMember adds a node/member to the given pool. must be in the form -// of :, i.e.: "web-server1:443". -func (b *BigIP) AddPoolMember(pool, member string) error { - config := &poolMember{ - Name: member, - } - - return b.post(config, uriLtm, uriPool, pool, uriPoolMember) -} - -// GetPoolMember returns the details of a member in the specified pool. -func (b *BigIP) GetPoolMember(pool string, member string) (*PoolMember, error) { - var poolMember PoolMember - err, ok := b.getForEntity(&poolMember, uriLtm, uriPool, pool, uriPoolMember, member) - - if err != nil { - return nil, err - } - if !ok { - return nil, nil - } - - return &poolMember, nil -} - -// CreatePoolMember creates a pool member for the specified pool. -func (b *BigIP) CreatePoolMember(pool string, config *PoolMember) error { - return b.post(config, uriLtm, uriPool, pool, uriPoolMember) -} - -// ModifyPoolMember will update the configuration of a particular pool member. -func (b *BigIP) ModifyPoolMember(pool string, config *PoolMember) error { - member := config.FullPath - // These fields are not used when modifying a pool member; so omit them. - config.Name = "" - config.Partition = "" - config.FullPath = "" - - // This cannot be modified for an existing pool member. - config.Address = "" - - return b.put(config, uriLtm, uriPool, pool, uriPoolMember, member) -} - -// UpdatePoolMembers does a replace-all-with for the members of a pool. -func (b *BigIP) UpdatePoolMembers(pool string, pm *[]PoolMember) error { - config := &poolMembers{ - Members: *pm, - } - return b.put(config, uriLtm, uriPool, pool) -} - -// RemovePoolMember removes a pool member from the specified pool. -func (b *BigIP) RemovePoolMember(pool string, config *PoolMember) error { - member := config.FullPath - return b.delete(uriLtm, uriPool, pool, uriPoolMember, member) -} - -// DeletePoolMember removes a member from the given pool. must be in the form -// of :, i.e.: "web-server1:443". -func (b *BigIP) DeletePoolMember(pool string, member string) error { - return b.delete(uriLtm, uriPool, pool, uriPoolMember, member) -} - -// PoolMemberStatus changes the status of a pool member. can be either -// "enable" or "disable". must be in the form of :, -// i.e.: "web-server1:443". -func (b *BigIP) PoolMemberStatus(pool string, member string, state string) error { - config := &Node{} - - switch state { - case "enable": - // config.State = "unchecked" - config.Session = "user-enabled" - case "disable": - // config.State = "unchecked" - config.Session = "user-disabled" - // case "offline": - // config.State = "user-down" - // config.Session = "user-disabled" - } - - return b.put(config, uriLtm, uriPool, pool, uriPoolMember, member) -} - -// CreatePool adds a new pool to the BIG-IP system by name. -func (b *BigIP) CreatePool(name string) error { - config := &Pool{ - Name: name, - } - - return b.post(config, uriLtm, uriPool) -} - -// AddPool creates a new pool on the BIG-IP system. -func (b *BigIP) AddPool(config *Pool) error { - return b.post(config, uriLtm, uriPool) -} - -// Get a Pool by name. Returns nil if the Pool does not exist -func (b *BigIP) GetPool(name string) (*Pool, error) { - var pool Pool - err, ok := b.getForEntity(&pool, uriLtm, uriPool, name) +// GetInternalDataGroupRecords gets the internal data group recors for a internal +// data group name +func (b *BigIP) GetInternalDataGroupRecords(name string) (*[]DataGroupRecord, error) { + var dataGroupRecords []DataGroupRecord + err, _ := b.getForEntity(&dataGroupRecords, uriLtm, uriDatagroup, uriInternal, name) if err != nil { return nil, err } - if !ok { - return nil, nil - } - - return &pool, nil -} -// DeletePool removes a pool. -func (b *BigIP) DeletePool(name string) error { - return b.delete(uriLtm, uriPool, name) -} - -// ModifyPool allows you to change any attribute of a pool. Fields that -// can be modified are referenced in the Pool struct. -func (b *BigIP) ModifyPool(name string, config *Pool) error { - return b.put(config, uriLtm, uriPool, name) + return &dataGroupRecords, nil } // VirtualServers returns a list of virtual servers. @@ -1310,7 +791,7 @@ func (b *BigIP) GetVirtualServer(name string) (*VirtualServer, error) { return nil, err } if !ok { - return nil, nil + return nil, errors.New("Unable to find virtual server by name: " + name) } profiles, err := b.VirtualServerProfiles(name) @@ -1343,6 +824,10 @@ func (b *BigIP) ModifyVirtualServer(name string, config *VirtualServer) error { func (b *BigIP) VirtualServerProfiles(vs string) (*Profiles, error) { var p Profiles err, ok := b.getForEntity(&p, uriLtm, uriVirtual, vs, "profiles") + // fmt.Println() + // fmt.Println("Profiles from entity:") + // fmt.Printf("%+v", p) + // fmt.Println() if err != nil { return nil, err } @@ -1403,7 +888,7 @@ func (b *BigIP) DeleteVirtualAddress(vaddr string) error { // Monitors returns a list of all HTTP, HTTPS, Gateway ICMP, ICMP, and TCP monitors. func (b *BigIP) Monitors() ([]Monitor, error) { var monitors []Monitor - monitorUris := []string{"http", "https", "icmp", "gateway-icmp", "tcp"} + monitorUris := [...]string{"http", "https", "tcp", "udp", "icmp", "external", "tcp-echo", "tcp-half-open", "virtual-location", "scripted", "mysql", "mssql", "diameter", "ftp", "pop3", "smtp"} for _, name := range monitorUris { var m Monitors @@ -1419,35 +904,54 @@ func (b *BigIP) Monitors() ([]Monitor, error) { return monitors, nil } -// CreateMonitor adds a new monitor to the BIG-IP system. must be one of "http", "https", -// "icmp", "gateway icmp", or "tcp". -func (b *BigIP) CreateMonitor(name, parent string, interval, timeout int, send, receive string) error { - config := &Monitor{ +// CreateMonitor adds a new monitor to the BIG-IP system. +func (b *BigIP) CreateMonitor(name, monitorType, parentMonitor string, interval, timeout int, send, receive string) error { + config := Monitor{ Name: name, - ParentMonitor: parent, + ParentMonitor: parentMonitor, + Type: monitorType, Interval: interval, Timeout: timeout, SendString: send, ReceiveString: receive, } + // config.TimeUntilUp = 4 + // config.ReceiveDisable = "true" + // config.Destination = "4.4.4.4:25" + // config.Password = "pass" + // config.ReceiveDisable = "true" + // config.UpInterval = 3 + // config.IPDSCP = 3 + // config.Partition = "Common" + // config.Username = "user" + // config.FullPath = "/Common/name" + // config.Generation = 3 + if Debug { + fmt.Printf("Translated monitor struct: %+v \r\n", config) + } return b.AddMonitor(config) } -// Create a monitor by supplying a config -func (b *BigIP) AddMonitor(config *Monitor) error { - if strings.Contains(config.ParentMonitor, "gateway") { - config.ParentMonitor = "gateway_icmp" - } - - return b.post(config, uriLtm, uriMonitor, config.ParentMonitor) +// AddMonitor creates a monitor by supplying a config +func (b *BigIP) AddMonitor(config Monitor) error { + // if strings.Contains(config.ParentMonitor, "gateway") { + // config.ParentMonitor = "gateway_icmp" + // } + return b.post(config, uriLtm, uriMonitor, config.Type) } // GetVirtualServer retrieves a monitor by name. Returns nil if the monitor does not exist -func (b *BigIP) GetMonitor(name string, parent string) (*Monitor, error) { +func (b *BigIP) GetMonitor(name string, monitorType string) (*Monitor, error) { + // Add a verification that type is an accepted monitor type - var monitor Monitor - err, ok := b.getForEntity(&monitor, uriLtm, uriMonitor, parent, name) + var monitor monitorDTO + err, ok := b.getForEntity(&monitor, uriLtm, uriMonitor, monitorType, name) + // if Debug { + // fmt.Println() + // fmt.Println("DEBUG getForEntity:", &monitor, uriLtm, uriMonitor, monitorType, name) + // fmt.Println() + // } if err != nil { return nil, err } @@ -1455,7 +959,42 @@ func (b *BigIP) GetMonitor(name string, parent string) (*Monitor, error) { return nil, nil } - return &monitor, nil + // translate monitorDTO response to monitor + var m Monitor + m.Name = monitor.Name + m.Type = monitorType + m.Description = monitor.Description + m.Destination = monitor.Destination + res, err := strconv.ParseBool(monitor.ManualResume) + if err != nil { + res = false + } + m.ManualResume = res + m.ParentMonitor = monitor.ParentMonitor + m.Partition = monitor.Partition + m.Generation = monitor.Generation + m.Interval = monitor.Interval + m.Password = monitor.Password + m.Timeout = monitor.Timeout + m.TimeUntilUp = monitor.TimeUntilUp + m.ReceiveString = monitor.ReceiveString + m.ReceiveDisable = monitor.ReceiveDisable + m.FullPath = monitor.FullPath + // rev, err := strconv.ParseBool(monitor.Reverse) + // if err != nil { + // rev = false + // } + // m.Reverse = rev + m.IPDSCP = monitor.IPDSCP + // trans, err := strconv.ParseBool(monitor.Transparent) + // if err != nil { + // trans = false + // } + // m.Transparent = trans + m.UpInterval = monitor.UpInterval + m.Username = monitor.Username + + return &m, nil } // DeleteMonitor removes a monitor. @@ -1483,50 +1022,6 @@ func (b *BigIP) AddMonitorToPool(monitor, pool string) error { return b.put(config, uriLtm, uriPool, pool) } -// IRules returns a list of irules -func (b *BigIP) IRules() (*IRules, error) { - var rules IRules - err, _ := b.getForEntity(&rules, uriLtm, uriIRule) - if err != nil { - return nil, err - } - - return &rules, nil -} - -// IRule returns information about the given iRule. -func (b *BigIP) IRule(name string) (*IRule, error) { - var rule IRule - err, ok := b.getForEntity(&rule, uriLtm, uriIRule, name) - if err != nil { - return nil, err - } - if !ok { - return nil, nil - } - return &rule, nil -} - -// CreateIRule creates a new iRule on the system. -func (b *BigIP) CreateIRule(name, rule string) error { - irule := &IRule{ - Name: name, - Rule: rule, - } - return b.post(irule, uriLtm, uriIRule) -} - -// DeleteIRule removes an iRule from the system. -func (b *BigIP) DeleteIRule(name string) error { - return b.delete(uriLtm, uriIRule, name) -} - -// ModifyIRule updates the given iRule with any changed values. -func (b *BigIP) ModifyIRule(name string, irule *IRule) error { - irule.Name = name - return b.put(irule, uriLtm, uriIRule, name) -} - func (b *BigIP) Policies() (*Policies, error) { var p Policies err, _ := b.getForEntity(&p, uriLtm, uriPolicy) diff --git a/node.go b/node.go new file mode 100644 index 0000000..745e0d7 --- /dev/null +++ b/node.go @@ -0,0 +1,24 @@ +package bigip + +// Nodes contains a list of every node on the BIG-IP system. +type Nodes struct { + Nodes []Node `json:"items"` +} + +// Node contains information about each individual node. You can use all +// of these fields when modifying a node. +type Node struct { + Name string `json:"name,omitempty"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + Address string `json:"address,omitempty"` + ConnectionLimit int `json:"connectionLimit,omitempty"` + DynamicRatio int `json:"dynamicRatio,omitempty"` + Logging string `json:"logging,omitempty"` + Monitor string `json:"monitor,omitempty"` + RateLimit string `json:"rateLimit,omitempty"` + Ratio int `json:"ratio,omitempty"` + Session string `json:"session,omitempty"` + State string `json:"state,omitempty"` +} diff --git a/oneConnectProfile.go b/oneConnectProfile.go new file mode 100644 index 0000000..5bf2dd6 --- /dev/null +++ b/oneConnectProfile.go @@ -0,0 +1,78 @@ +package bigip + +// OneConnectProfiles +// Documentation: https://devcentral.f5.com/wiki/iControlREST.APIRef_tm_ltm_profile_oneConnect.ashx + +// OneConnectProfiles contains a list of every oneConnect profile on the BIG-IP system. +type OneConnectProfiles struct { + OneConnectProfiles []OneConnectProfile `json:"items"` +} + +// OneConnectProfile contains information about each oneConnect profile. You can use all +// of these fields when modifying a oneConnect profile. +type OneConnectProfile struct { + Kind string `json:"kind,omitempty"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + IdleTimeoutOverride string `json:"idleTimeoutOverride,omitempty"` + MaxAge int `json:"maxAge,omitempty"` + MaxReuse int `json:"maxReuse,omitempty"` + MaxSize int `json:"maxSize,omitempty"` + SharePools string `json:"sharePools,omitempty"` + SourceMask string `json:"sourceMask,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` +} + +// OneConnectProfiles returns a list of oneConnect profiles. +func (b *BigIP) OneConnectProfiles() (*OneConnectProfiles, error) { + var oneConnectProfiles OneConnectProfiles + err, _ := b.getForEntity(&oneConnectProfiles, uriLtm, uriProfile, uriOneConnect) + if err != nil { + return nil, err + } + + return &oneConnectProfiles, nil +} + +// GetOneConnectProfile gets a oneConnect profile by name. Returns nil if the oneConnect profile does not exist +func (b *BigIP) GetOneConnectProfile(name string) (*OneConnectProfile, error) { + var oneConnectProfile OneConnectProfile + err, ok := b.getForEntity(&oneConnectProfile, uriLtm, uriProfile, uriOneConnect, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &oneConnectProfile, nil +} + +// CreateOneConnectProfile creates a new oneConnect profile on the BIG-IP system. +func (b *BigIP) CreateOneConnectProfile(name string, parent string) error { + config := &OneConnectProfile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriOneConnect) +} + +// AddOneConnectProfile adds a new oneConnect profile on the BIG-IP system. +func (b *BigIP) AddOneConnectProfile(config *OneConnectProfile) error { + return b.post(config, uriLtm, uriProfile, uriOneConnect) +} + +// DeleteOneConnectProfile removes a oneConnect profile. +func (b *BigIP) DeleteOneConnectProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriOneConnect, name) +} + +// ModifyOneConnectProfile allows you to change any attribute of a sever-oneConnect profile. +// Fields that can be modified are referenced in the VirtualClient struct. +func (b *BigIP) ModifyOneConnectProfile(name string, config *OneConnectProfile) error { + return b.put(config, uriLtm, uriProfile, uriOneConnect, name) +} diff --git a/persistenceCookie.go b/persistenceCookie.go new file mode 100644 index 0000000..209c4b8 --- /dev/null +++ b/persistenceCookie.go @@ -0,0 +1,85 @@ +package bigip + +type PersistenceCookies struct { + PersistenceCookie []PersistenceCookie `json:"items,omitempty"` +} + +type PersistenceCookie struct { + Name string `json:"name"` + DefaultsFrom string `json:"defaultsFrom"` + Kind string `json:"kind,omitempty"` + Mode string `json:"mode,omitempty"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + AlwaysSend string `json:"alwaysSend,omitempty"` + Description string `json:"description,omitempty"` + AppService string `json:"appService,omitempty"` + CookieEncryption string `json:"cookieEncryption,omitempty"` + CookieEncryptionPassphrase string `json:"cookieEncryptionPassphrase,omitempty"` + CookieName string `json:"cookieName,omitempty"` + Expiration string `json:"expiration,omitempty"` + HashLength int `json:"hashLength,omitempty"` + HashOffset int `json:"hashOffset,omitempty"` + MatchAcrossPools string `json:"matchAcrossPools,omitempty"` + MatchAcrossServices string `json:"matchAcrossServices,omitempty"` + MatchAcrossVirtuals string `json:"matchAcrossVirtuals,omitempty"` + Method string `json:"method,omitempty"` + Mirror string `json:"mirror,omitempty"` + Secure string `json:"secure,omitempty"` + TMPartition string `json:"tmPartition,omitempty"` + OverrideConnectionLimit string `json:"overrideConnectionLimit,omitempty"` + Timeout string `json:"timeout,omitempty"` +} + +// PersistenceCookie returns a list of oersistence profiles. +func (b *BigIP) PersistenceCookie() (*PersistenceCookie, error) { + var persistenceProfiles PersistenceCookie + err, _ := b.getForEntity(&persistenceProfiles, uriLtm, uriPersistences) + if err != nil { + return nil, err + } + + return &persistenceProfiles, nil +} + +// GetPersistenceCookie gets a persistence profile by name. Returns nil if the persistence profile does not exist +func (b *BigIP) GetPersistenceCookie(name string) (*PersistenceCookie, error) { + var persistenceProfile PersistenceCookie + err, ok := b.getForEntity(&persistenceProfile, uriLtm, uriProfile, uriPersistenceCookie, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &persistenceProfile, nil +} + +// CreatePersistenceCookie creates a new persistence profile on the BIG-IP system. +func (b *BigIP) CreatePersistenceCookie(name string, parent string) error { + config := &PersistenceCookie{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriPersistenceCookie) +} + +// AddPersistenceCookie adds a new persistence profile on the BIG-IP system. +func (b *BigIP) AddPersistenceCookie(config *PersistenceCookie) error { + return b.post(config, uriLtm, uriProfile, uriPersistenceCookie) +} + +// DeletePersistenceCookie removes a persistence profile. +func (b *BigIP) DeletePersistenceCookie(name string) error { + return b.delete(uriLtm, uriProfile, uriPersistenceCookie, name) +} + +// ModifyPersistenceCookie allows you to change any attribute of a persistence profile. +// Fields that can be modified are referenced in the PersistenceCookie struct. +func (b *BigIP) ModifyPersistenceCookie(name string, config *PersistenceCookie) error { + return b.put(config, uriLtm, uriProfile, uriPersistenceCookie, name) +} diff --git a/persistenceHash.go b/persistenceHash.go new file mode 100644 index 0000000..e3e1dc7 --- /dev/null +++ b/persistenceHash.go @@ -0,0 +1,83 @@ +package bigip + +type PersistenceHashes struct { + PersistenceHash []PersistenceHash `json:"items,omitempty"` +} + +type PersistenceHash struct { + Kind string `json:"kind,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + HashAlgorithm string `json:"hashAlgorithm,omitempty"` + HashBufferLimit int `json:"hashBufferLimit,omitempty"` + HashLength int `json:"hashLength,omitempty"` + HashOffset int `json:"hashOffset,omitempty"` + MatchAcrossPools string `json:"matchAcrossPools,omitempty"` + MatchAcrossServices string `json:"matchAcrossServices,omitempty"` + MatchAcrossVirtuals string `json:"matchAcrossVirtuals,omitempty"` + AppService string `json:"appService,omitempty"` + Description string `json:"description,omitempty"` + HashEndPattern string `json:"hashEndPattern,omitempty"` + HashStartPattern string `json:"hashStartPattern,omitempty"` + Mode string `json:"mode,omitempty"` + Rule string `json:"rule,omitempty"` + TMPartition string `json:"tmPartition,omitempty"` + Mirror string `json:"mirror,omitempty"` + OverrideConnectionLimit string `json:"overrideConnectionLimit,omitempty"` + Timeout string `json:"timeout,omitempty"` +} + +// PersistenceHash returns a list of oersistence profiles. +func (b *BigIP) PersistenceHash() (*PersistenceHash, error) { + var persistenceProfiles PersistenceHash + err, _ := b.getForEntity(&persistenceProfiles, uriLtm, uriPersistences) + if err != nil { + return nil, err + } + + return &persistenceProfiles, nil +} + +// GetPersistenceHash gets a persistence profile by name. Returns nil if the persistence profile does not exist +func (b *BigIP) GetPersistenceHash(name string) (*PersistenceHash, error) { + var persistenceProfile PersistenceHash + err, ok := b.getForEntity(&persistenceProfile, uriLtm, uriProfile, uriPersistenceHash, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &persistenceProfile, nil +} + +// CreatePersistenceHash creates a new persistence profile on the BIG-IP system. +func (b *BigIP) CreatePersistenceHash(name string, parent string) error { + config := &PersistenceHash{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriPersistenceHash) +} + +// AddPersistenceHash adds a new persistence profile on the BIG-IP system. +func (b *BigIP) AddPersistenceHash(config *PersistenceHash) error { + return b.post(config, uriLtm, uriProfile, uriPersistenceHash) +} + +// DeletePersistenceHash removes a persistence profile. +func (b *BigIP) DeletePersistenceHash(name string) error { + return b.delete(uriLtm, uriProfile, uriPersistenceHash, name) +} + +// ModifyPersistenceHash allows you to change any attribute of a persistence profile. +// Fields that can be modified are referenced in the PersistenceHash struct. +func (b *BigIP) ModifyPersistenceHash(name string, config *PersistenceHash) error { + return b.put(config, uriLtm, uriProfile, uriPersistenceHash, name) +} diff --git a/persistenceSourceAddr.go b/persistenceSourceAddr.go new file mode 100644 index 0000000..f55dca0 --- /dev/null +++ b/persistenceSourceAddr.go @@ -0,0 +1,74 @@ +package bigip + +type PersistenceSourceAddres struct { + PersistenceSourceAddr []PersistenceSourceAddr `json:"items,omitempty"` +} + +type PersistenceSourceAddr struct { + Name string `json:"name"` + DefaultsFrom string `json:"defaultsFrom"` + Kind string `json:"kind,omitempty"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + HashAlgorithm string `json:"hashAlgorithm,omitempty"` + MapProxies string `json:"mapProxies,omitempty"` + MatchAcrossPools string `json:"matchAcrossPools,omitempty"` + MatchAcrossServices string `json:"matchAcrossServices,omitempty"` + MatchAcrossVirtuals string `json:"matchAcrossVirtuals,omitempty"` + Mirror string `json:"mirror,omitempty"` + OverrideConnectionLimit string `json:"overrideConnectionLimit,omitempty"` + Timeout string `json:"timeout,omitempty"` +} + +// PersistenceSourceAddr returns a list of oersistence profiles. +func (b *BigIP) PersistenceSourceAddr() (*PersistenceSourceAddr, error) { + var persistenceProfiles PersistenceSourceAddr + err, _ := b.getForEntity(&persistenceProfiles, uriLtm, uriPersistences) + if err != nil { + return nil, err + } + + return &persistenceProfiles, nil +} + +// GetPersistenceSourceAddr gets a persistence profile by name. Returns nil if the persistence profile does not exist +func (b *BigIP) GetPersistenceSourceAddr(name string) (*PersistenceSourceAddr, error) { + var persistenceProfile PersistenceSourceAddr + err, ok := b.getForEntity(&persistenceProfile, uriLtm, uriProfile, uriPersistenceSourceAddr, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &persistenceProfile, nil +} + +// CreatePersistenceSourceAddr creates a new persistence profile on the BIG-IP system. +func (b *BigIP) CreatePersistenceSourceAddr(name string, parent string) error { + config := &PersistenceSourceAddr{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriPersistenceSourceAddr) +} + +// AddPersistenceSourceAddr adds a new persistence profile on the BIG-IP system. +func (b *BigIP) AddPersistenceSourceAddr(config *PersistenceSourceAddr) error { + return b.post(config, uriLtm, uriProfile, uriPersistenceSourceAddr) +} + +// DeletePersistenceSourceAddr removes a persistence profile. +func (b *BigIP) DeletePersistenceSourceAddr(name string) error { + return b.delete(uriLtm, uriProfile, uriPersistenceSourceAddr, name) +} + +// ModifyPersistenceSourceAddr allows you to change any attribute of a persistence profile. +// Fields that can be modified are referenced in the PersistenceSourceAddr struct. +func (b *BigIP) ModifyPersistenceSourceAddr(name string, config *PersistenceSourceAddr) error { + return b.put(config, uriLtm, uriProfile, uriPersistenceSourceAddr, name) +} diff --git a/pool.go b/pool.go new file mode 100644 index 0000000..06b8804 --- /dev/null +++ b/pool.go @@ -0,0 +1,216 @@ +package bigip + +import "strings" + +// Pool contains information about each pool. You can use all of these +// fields when modifying a pool. +type Pool struct { + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + AllowNAT string `json:"allowNat,omitempty"` + AllowSNAT string `json:"allowSnat,omitempty"` + IgnorePersistedWeight string `json:"ignorePersistedWeight,omitempty"` + IPTOSToClient string `json:"ipTosToClient,omitempty"` + IPTOSToServer string `json:"ipTosToServer,omitempty"` + LinkQoSToClient string `json:"linkQosToClient,omitempty"` + LinkQoSToServer string `json:"linkQosToServer,omitempty"` + LoadBalancingMode string `json:"loadBalancingMode,omitempty"` + MinActiveMembers int `json:"minActiveMembers,omitempty"` + MinUpMembers int `json:"minUpMembers,omitempty"` + MinUpMembersAction string `json:"minUpMembersAction,omitempty"` + MinUpMembersChecking string `json:"minUpMembersChecking,omitempty"` + Monitor string `json:"monitor,omitempty"` + QueueDepthLimit int `json:"queueDepthLimit,omitempty"` + QueueOnConnectionLimit string `json:"queueOnConnectionLimit,omitempty"` + QueueTimeLimit int `json:"queueTimeLimit,omitempty"` + ReselectTries int `json:"reselectTries,omitempty"` + ServiceDownAction string `json:"serviceDownAction,omitempty"` + SlowRampTime int `json:"slowRampTime,omitempty"` +} + +// Pool Members contains a list of pool members within a pool on the BIG-IP system. +type PoolMembers struct { + PoolMembers []PoolMember `json:"items"` +} + +// poolMember is used only when adding members to a pool. +type poolMember struct { + Name string `json:"name"` +} + +// poolMembers is used only when modifying members on a pool. +type poolMembers struct { + Members []PoolMember `json:"members"` +} + +// Pool Member contains information about each individual member in a pool. You can use all +// of these fields when modifying a pool member. +type PoolMember struct { + Name string `json:"name,omitempty"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + Address string `json:"address,omitempty"` + ConnectionLimit int `json:"connectionLimit,omitempty"` + DynamicRatio int `json:"dynamicRatio,omitempty"` + InheritProfile string `json:"inheritProfile,omitempty"` + Logging string `json:"logging,omitempty"` + Monitor string `json:"monitor,omitempty"` + PriorityGroup int `json:"priorityGroup,omitempty"` + RateLimit string `json:"rateLimit,omitempty"` + Ratio int `json:"ratio,omitempty"` + Session string `json:"session,omitempty"` + State string `json:"state,omitempty"` +} + +// PoolMembers returns a list of pool members for the given pool. +func (b *BigIP) PoolMembers(name string) (*PoolMembers, error) { + var poolMembers PoolMembers + err, _ := b.getForEntity(&poolMembers, uriLtm, uriPool, name, uriPoolMember) + if err != nil { + return nil, err + } + + return &poolMembers, nil +} + +// AddPoolMember adds a node/member to the given pool. must be in the form +// of :, i.e.: "web-server1:443". +func (b *BigIP) AddPoolMember(pool, member string) error { + config := &poolMember{ + Name: member, + } + + return b.post(config, uriLtm, uriPool, pool, uriPoolMember) +} + +// GetPoolMember returns the details of a member in the specified pool. +func (b *BigIP) GetPoolMember(pool string, member string) (*PoolMember, error) { + var poolMember PoolMember + err, ok := b.getForEntity(&poolMember, uriLtm, uriPool, pool, uriPoolMember, member) + + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &poolMember, nil +} + +// CreatePoolMember creates a pool member for the specified pool. +func (b *BigIP) CreatePoolMember(pool string, config *PoolMember) error { + return b.post(config, uriLtm, uriPool, pool, uriPoolMember) +} + +// ModifyPoolMember will update the configuration of a particular pool member. +func (b *BigIP) ModifyPoolMember(pool string, config *PoolMember) error { + member := config.FullPath + // These fields are not used when modifying a pool member; so omit them. + config.Name = "" + config.Partition = "" + config.FullPath = "" + + // This cannot be modified for an existing pool member. + config.Address = "" + + return b.put(config, uriLtm, uriPool, pool, uriPoolMember, member) +} + +// UpdatePoolMembers does a replace-all-with for the members of a pool. +func (b *BigIP) UpdatePoolMembers(pool string, pm *[]PoolMember) error { + config := &poolMembers{ + Members: *pm, + } + return b.put(config, uriLtm, uriPool, pool) +} + +// RemovePoolMember removes a pool member from the specified pool. +func (b *BigIP) RemovePoolMember(pool string, config *PoolMember) error { + member := config.FullPath + return b.delete(uriLtm, uriPool, pool, uriPoolMember, member) +} + +// DeletePoolMember removes a member from the given pool. must be in the form +// of :, i.e.: "web-server1:443". +func (b *BigIP) DeletePoolMember(pool string, member string) error { + return b.delete(uriLtm, uriPool, pool, uriPoolMember, member) +} + +// PoolMemberStatus changes the status of a pool member. can be either +// "enable" or "disable". must be in the form of :, +// i.e.: "web-server1:443". +func (b *BigIP) PoolMemberStatus(pool string, member string, state string) error { + config := &Node{} + + switch state { + case "enable": + // config.State = "unchecked" + config.Session = "user-enabled" + case "disable": + // config.State = "unchecked" + config.Session = "user-disabled" + // case "offline": + // config.State = "user-down" + // config.Session = "user-disabled" + } + + return b.put(config, uriLtm, uriPool, pool, uriPoolMember, member) +} + +// CreatePool adds a new pool to the BIG-IP system by name. +func (b *BigIP) CreatePool(name string) error { + config := &Pool{ + Name: name, + } + + return b.post(config, uriLtm, uriPool) +} + +// AddPool creates a new pool on the BIG-IP system. +func (b *BigIP) AddPool(config *Pool) error { + return b.post(config, uriLtm, uriPool) +} + +// Get a Pool by name. Returns nil if the Pool does not exist +func (b *BigIP) GetPool(name string) (*Pool, error) { + var pool Pool + err, ok := b.getForEntity(&pool, uriLtm, uriPool, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + pool.Name = strings.Replace(pool.Name, "/Common/", "", -1) + pool.Name = strings.Replace(pool.Name, "/Common", "", -1) + pool.Name = strings.Replace(pool.Name, "~Common~", "", -1) + + return &pool, nil +} + +// DeletePool removes a pool. +func (b *BigIP) DeletePool(name string) error { + return b.delete(uriLtm, uriPool, name) +} + +// ModifyPool allows you to change any attribute of a pool. Fields that +// can be modified are referenced in the Pool struct. +func (b *BigIP) ModifyPool(name string, config *Pool) error { + return b.put(config, uriLtm, uriPool, name) +} + +// Pools returns a list of pools. +func (b *BigIP) Pools() (*Pools, error) { + var pools Pools + err, _ := b.getForEntity(&pools, uriLtm, uriPool) + if err != nil { + return nil, err + } + + return &pools, nil +} diff --git a/profileClientSSL.go b/profileClientSSL.go new file mode 100644 index 0000000..3ea0220 --- /dev/null +++ b/profileClientSSL.go @@ -0,0 +1,122 @@ +package bigip + +// ClientSSLProfiles +// Documentation: https://devcentral.f5.com/wiki/iControlREST.APIRef_tm_ltm_profile_client-ssl.ashx + +// ClientSSLProfiles contains a list of every client-ssl profile on the BIG-IP system. +type ClientSSLProfiles struct { + ClientSSLProfiles []ClientSSLProfile `json:"items"` +} + +// ClientSSLProfile contains information about each client-ssl profile. You can use all +// of these fields when modifying a client-ssl profile. +type ClientSSLProfile struct { + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + AlertTimeout string `json:"alertTimeout,omitempty"` + AllowNonSsl string `json:"allowNonSsl,omitempty"` + Authenticate string `json:"authenticate,omitempty"` + AuthenticateDepth int `json:"authenticateDepth,omitempty"` + CaFile string `json:"caFile,omitempty"` + CacheSize int `json:"cacheSize,omitempty"` + CacheTimeout int `json:"cacheTimeout,omitempty"` + Cert string `json:"cert,omitempty"` + CertKeyChain []struct { + Name string `json:"name,omitempty"` + Cert string `json:"cert,omitempty"` + Chain string `json:"chain,omitempty"` + Key string `json:"key,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + } `json:"certKeyChain,omitempty"` + CertExtensionIncludes []string `json:"certExtensionIncludes,omitempty"` + CertLifespan int `json:"certLifespan,omitempty"` + CertLookupByIpaddrPort string `json:"certLookupByIpaddrPort,omitempty"` + Chain string `json:"chain,omitempty"` + Ciphers string `json:"ciphers,omitempty"` + ClientCertCa string `json:"clientCertCa,omitempty"` + CrlFile string `json:"crlFile,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` + ForwardProxyBypassDefaultAction string `json:"forwardProxyBypassDefaultAction,omitempty"` + GenericAlert string `json:"genericAlert,omitempty"` + HandshakeTimeout string `json:"handshakeTimeout,omitempty"` + InheritCertkeychain string `json:"inheritCertkeychain,omitempty"` + Key string `json:"key,omitempty"` + ModSslMethods string `json:"modSslMethods,omitempty"` + Mode string `json:"mode,omitempty"` + TmOptions []string `json:"tmOptions,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + PeerCertMode string `json:"peerCertMode,omitempty"` + ProxyCaCert string `json:"proxyCaCert,omitempty"` + ProxyCaKey string `json:"proxyCaKey,omitempty"` + ProxyCaPassphrase string `json:"proxyCaPassphrase,omitempty"` + ProxySsl string `json:"proxySsl,omitempty"` + ProxySslPassthrough string `json:"proxySslPassthrough,omitempty"` + RenegotiatePeriod string `json:"renegotiatePeriod,omitempty"` + RenegotiateSize string `json:"renegotiateSize,omitempty"` + Renegotiation string `json:"renegotiation,omitempty"` + RetainCertificate string `json:"retainCertificate,omitempty"` + SecureRenegotiation string `json:"secureRenegotiation,omitempty"` + ServerName string `json:"serverName,omitempty"` + SessionMirroring string `json:"sessionMirroring,omitempty"` + SessionTicket string `json:"sessionTicket,omitempty"` + SniDefault string `json:"sniDefault,omitempty"` + SniRequire string `json:"sniRequire,omitempty"` + SslForwardProxy string `json:"sslForwardProxy,omitempty"` + SslForwardProxyBypass string `json:"sslForwardProxyBypass,omitempty"` + SslSignHash string `json:"sslSignHash,omitempty"` + StrictResume string `json:"strictResume,omitempty"` + UncleanShutdown string `json:"uncleanShutdown,omitempty"` +} + +// ClientSSLProfiles returns a list of client-ssl profiles. +func (b *BigIP) ClientSSLProfiles() (*ClientSSLProfiles, error) { + var clientSSLProfiles ClientSSLProfiles + err, _ := b.getForEntity(&clientSSLProfiles, uriLtm, uriProfile, uriClientSSL) + if err != nil { + return nil, err + } + + return &clientSSLProfiles, nil +} + +// GetClientSSLProfile gets a client-ssl profile by name. Returns nil if the client-ssl profile does not exist +func (b *BigIP) GetClientSSLProfile(name string) (*ClientSSLProfile, error) { + var clientSSLProfile ClientSSLProfile + err, ok := b.getForEntity(&clientSSLProfile, uriLtm, uriProfile, uriClientSSL, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &clientSSLProfile, nil +} + +// CreateClientSSLProfile creates a new client-ssl profile on the BIG-IP system. +func (b *BigIP) CreateClientSSLProfile(name string, parent string) error { + config := &ClientSSLProfile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriClientSSL) +} + +// AddClientSSLProfile adds a new client-ssl profile on the BIG-IP system. +func (b *BigIP) AddClientSSLProfile(config *ClientSSLProfile) error { + return b.post(config, uriLtm, uriProfile, uriClientSSL) +} + +// DeleteClientSSLProfile removes a client-ssl profile. +func (b *BigIP) DeleteClientSSLProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriClientSSL, name) +} + +// ModifyClientSSLProfile allows you to change any attribute of a sever-ssl profile. +// Fields that can be modified are referenced in the VirtualClient struct. +func (b *BigIP) ModifyClientSSLProfile(name string, config *ClientSSLProfile) error { + return b.put(config, uriLtm, uriProfile, uriClientSSL, name) +} diff --git a/profileFTP.go b/profileFTP.go new file mode 100644 index 0000000..7800e6f --- /dev/null +++ b/profileFTP.go @@ -0,0 +1,69 @@ +package bigip + +// FTPProfile represents a FTP Profile configuration +type FTPProfile struct { + Kind string `json:"kind"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + InheritParentProfile string `json:"inheritParentProfile,omitempty"` + Port int `json:"port,omitempty"` + Security string `json:"security,omitempty"` + TranslateExtended string `json:"translateExtended,omitempty"` + DefaultsFrom string `json:defaultsFrom` +} + +// FTPProfiles is an array of FTPProfile structs +type FTPProfiles []FTPProfile + +// FTPProfiles returns a list of FTP profiles. +func (b *BigIP) FTPProfiles() (*FTPProfiles, error) { + var serverFTPProfiles FTPProfiles + err, _ := b.getForEntity(&serverFTPProfiles, uriLtm, uriProfile, uriProfileFTP) + if err != nil { + return nil, err + } + + return &serverFTPProfiles, nil +} + +// GetFTPProfile gets a FTP profile by name. Returns nil if the FTP profile does not exist +func (b *BigIP) GetFTPProfile(name string) (*FTPProfile, error) { + var serverFTPProfile FTPProfile + err, ok := b.getForEntity(&serverFTPProfile, uriLtm, uriProfile, uriProfileFTP, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &serverFTPProfile, nil +} + +// CreateFTPProfile creates a new FTP profile on the BIG-IP system. +func (b *BigIP) CreateFTPProfile(name string) error { + config := &FTPProfile{ + Name: name, + } + + return b.post(config, uriLtm, uriProfile, uriProfileFTP) +} + +// AddFTPProfile adds a new FTP profile on the BIG-IP system. +func (b *BigIP) AddFTPProfile(config *FTPProfile) error { + return b.post(config, uriLtm, uriProfile, uriProfileFTP) +} + +// DeleteFTPProfile removes a FTP profile. +func (b *BigIP) DeleteFTPProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriProfileFTP, name) +} + +// ModifyFTPProfile allows you to change any attribute of a FTP profile. +// Fields that can be modified are referenced in the VirtualServer struct. +func (b *BigIP) ModifyFTPProfile(name string, config *FTPProfile) error { + return b.put(config, uriLtm, uriProfile, uriProfileFTP, name) +} diff --git a/profileFastL4.go b/profileFastL4.go new file mode 100644 index 0000000..666b7e7 --- /dev/null +++ b/profileFastL4.go @@ -0,0 +1,99 @@ +package bigip + +// FastL4Profile is a representation of a fastL4Profile configuration +type FastL4Profile struct { + Kind string `json:"kind,omitempty"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + HardwareSynCookie string `json:"hardwareSynCookie,omitempty"` + IdleTimeout string `json:"idleTimeout,omitempty"` + IPTosToClient string `json:"ipTosToClient,omitempty"` + IPTosToServer string `json:"ipTosToServer,omitempty"` + KeepAliveInterval string `json:"keepAliveInterval,omitempty"` + LinkQosToClient string `json:"linkQosToClient,omitempty"` + LinkQosToServer string `json:"linkQosToServer,omitempty"` + LooseClose string `json:"looseClose,omitempty"` + LooseInitialization string `json:"looseInitialization,omitempty"` + MssOverride int `json:"mssOverride,omitempty"` + PriorityToClient string `json:"priorityToClient,omitempty"` + PriorityToServer string `json:"priorityToServer,omitempty"` + PvaAcceleration string `json:"pvaAcceleration,omitempty"` + PvaDynamicClientPackets int `json:"pvaDynamicClientPackets,omitempty"` + PvaDynamicServerPackets int `json:"pvaDynamicServerPackets,omitempty"` + PvaFlowAging string `json:"pvaFlowAging,omitempty"` + PvaFlowEvict string `json:"pvaFlowEvict,omitempty"` + PvaOffloadDynamic string `json:"pvaOffloadDynamic,omitempty"` + PvaOffloadState string `json:"pvaOffloadState,omitempty"` + ReassembleFragments string `json:"reassembleFragments,omitempty"` + ReceiveWindowSize int `json:"receiveWindowSize,omitempty"` + ResetOnTimeout string `json:"resetOnTimeout,omitempty"` + RttFromClient string `json:"rttFromClient,omitempty"` + RttFromServer string `json:"rttFromServer,omitempty"` + ServerSack string `json:"serverSack,omitempty"` + ServerTimestamp string `json:"serverTimestamp,omitempty"` + SoftwareSynCookie string `json:"softwareSynCookie,omitempty"` + TCPCloseTimeout string `json:"tcpCloseTimeout,omitempty"` + TCPGenerateIsn string `json:"tcpGenerateIsn,omitempty"` + TCPHandshakeTimeout string `json:"tcpHandshakeTimeout,omitempty"` + TCPStripSack string `json:"tcpStripSack,omitempty"` + TCPTimestampMode string `json:"tcpTimestampMode,omitempty"` + TCPWscaleMode string `json:"tcpWscaleMode,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` +} + +// FastL4Profiles is an array of FastL4Profile structs +type FastL4Profiles []FastL4Profile + +// FastL4Profiles returns a list of fastL4 profiles. +func (b *BigIP) FastL4Profiles() (*FastL4Profiles, error) { + var serverFastL4Profiles FastL4Profiles + err, _ := b.getForEntity(&serverFastL4Profiles, uriLtm, uriProfile, uriProfileFastL4) + if err != nil { + return nil, err + } + + return &serverFastL4Profiles, nil +} + +// GetFastL4Profile gets a fastL4 profile by name. Returns nil if the fastL4 profile does not exist +func (b *BigIP) GetFastL4Profile(name string) (*FastL4Profile, error) { + var serverFastL4Profile FastL4Profile + err, ok := b.getForEntity(&serverFastL4Profile, uriLtm, uriProfile, uriProfileFastL4, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &serverFastL4Profile, nil +} + +// CreateFastL4Profile creates a new fastL4 profile on the BIG-IP system. +func (b *BigIP) CreateFastL4Profile(name string, parent string) error { + config := &FastL4Profile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriProfileFastL4) +} + +// AddFastL4Profile adds a new fastL4 profile on the BIG-IP system. +func (b *BigIP) AddFastL4Profile(config *FastL4Profile) error { + return b.post(config, uriLtm, uriProfile, uriProfileFastL4) +} + +// DeleteFastL4Profile removes a fastL4 profile. +func (b *BigIP) DeleteFastL4Profile(name string) error { + return b.delete(uriLtm, uriProfile, uriProfileFastL4, name) +} + +// ModifyFastL4Profile allows you to change any attribute of a fastL4 profile. +// Fields that can be modified are referenced in the VirtualServer struct. +func (b *BigIP) ModifyFastL4Profile(name string, config *FastL4Profile) error { + return b.put(config, uriLtm, uriProfile, uriProfileFastL4, name) +} diff --git a/profileTCP.go b/profileTCP.go new file mode 100644 index 0000000..794a3ba --- /dev/null +++ b/profileTCP.go @@ -0,0 +1,123 @@ +package bigip + +// TCPProfile represents a TCP Profile configuration +type TCPProfile struct { + Kind string `json:"kind,omitempty"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + Abc string `json:"abc,omitempty"` + AckOnPush string `json:"ackOnPush,omitempty"` + CloseWaitTimeout int `json:"closeWaitTimeout,omitempty"` + CmetricsCache string `json:"cmetricsCache,omitempty"` + CongestionControl string `json:"congestionControl,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` + DeferredAccept string `json:"deferredAccept,omitempty"` + DelayWindowControl string `json:"delayWindowControl,omitempty"` + DelayedAcks string `json:"delayedAcks,omitempty"` + Dsack string `json:"dsack,omitempty"` + Ecn string `json:"ecn,omitempty"` + FinWaitTimeout int `json:"finWaitTimeout,omitempty"` + HardwareSynCookie string `json:"hardwareSynCookie,omitempty"` + IdleTimeout int `json:"idleTimeout,omitempty"` + InitCwnd int `json:"initCwnd,omitempty"` + InitRwnd int `json:"initRwnd,omitempty"` + IPTosToClient string `json:"ipTosToClient,omitempty"` + KeepAliveInterval int `json:"keepAliveInterval,omitempty"` + LimitedTransmit string `json:"limitedTransmit,omitempty"` + LinkQosToClient string `json:"linkQosToClient,omitempty"` + MaxRetrans int `json:"maxRetrans,omitempty"` + MaxSegmentSize int `json:"maxSegmentSize,omitempty"` + Md5Signature string `json:"md5Signature,omitempty"` + MinimumRto int `json:"minimumRto,omitempty"` + Mptcp string `json:"mptcp,omitempty"` + MptcpCsum string `json:"mptcpCsum,omitempty"` + MptcpCsumVerify string `json:"mptcpCsumVerify,omitempty"` + MptcpDebug string `json:"mptcpDebug,omitempty"` + MptcpFallback string `json:"mptcpFallback,omitempty"` + MptcpFastjoin string `json:"mptcpFastjoin,omitempty"` + MptcpJoinMax int `json:"mptcpJoinMax,omitempty"` + MptcpMakeafterbreak string `json:"mptcpMakeafterbreak,omitempty"` + MptcpNojoindssack string `json:"mptcpNojoindssack,omitempty"` + MptcpRtomax int `json:"mptcpRtomax,omitempty"` + MptcpRxmitmin int `json:"mptcpRxmitmin,omitempty"` + MptcpSubflowmax int `json:"mptcpSubflowmax,omitempty"` + MptcpTimeout int `json:"mptcpTimeout,omitempty"` + Nagle string `json:"nagle,omitempty"` + PktLossIgnoreBurst int `json:"pktLossIgnoreBurst,omitempty"` + PktLossIgnoreRate int `json:"pktLossIgnoreRate,omitempty"` + ProxyBufferHigh int `json:"proxyBufferHigh,omitempty"` + ProxyBufferLow int `json:"proxyBufferLow,omitempty"` + ProxyMss string `json:"proxyMss,omitempty"` + ProxyOptions string `json:"proxyOptions,omitempty"` + RatePace string `json:"ratePace,omitempty"` + ReceiveWindowSize int `json:"receiveWindowSize,omitempty"` + ResetOnTimeout string `json:"resetOnTimeout,omitempty"` + SelectiveAcks string `json:"selectiveAcks,omitempty"` + SelectiveNack string `json:"selectiveNack,omitempty"` + SendBufferSize int `json:"sendBufferSize,omitempty"` + SlowStart string `json:"slowStart,omitempty"` + SynMaxRetrans int `json:"synMaxRetrans,omitempty"` + SynRtoBase int `json:"synRtoBase,omitempty"` + TimeWaitRecycle string `json:"timeWaitRecycle,omitempty"` + TimeWaitTimeout int `json:"timeWaitTimeout,omitempty"` + Timestamps string `json:"timestamps,omitempty"` + VerifiedAccept string `json:"verifiedAccept,omitempty"` + ZeroWindowTimeout int `json:"zeroWindowTimeout,omitempty"` +} + +// TCPProfiles is an array of TCPProfile structs +type TCPProfiles []TCPProfile + +// TCPProfiles returns a list of tcp profiles. +func (b *BigIP) TCPProfiles() (*TCPProfiles, error) { + var serverTCPProfiles TCPProfiles + err, _ := b.getForEntity(&serverTCPProfiles, uriLtm, uriProfile, uriProfileTCP) + if err != nil { + return nil, err + } + + return &serverTCPProfiles, nil +} + +// GetTCPProfile gets a tcp profile by name. Returns nil if the tcp profile does not exist +func (b *BigIP) GetTCPProfile(name string) (*TCPProfile, error) { + var serverTCPProfile TCPProfile + err, ok := b.getForEntity(&serverTCPProfile, uriLtm, uriProfile, uriProfileTCP, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &serverTCPProfile, nil +} + +// CreateTCPProfile creates a new tcp profile on the BIG-IP system. +func (b *BigIP) CreateTCPProfile(name string, parent string) error { + config := &TCPProfile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriProfileTCP) +} + +// AddTCPProfile adds a new tcp profile on the BIG-IP system. +func (b *BigIP) AddTCPProfile(config *TCPProfile) error { + return b.post(config, uriLtm, uriProfile, uriProfileTCP) +} + +// DeleteTCPProfile removes a tcp profile. +func (b *BigIP) DeleteTCPProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriProfileTCP, name) +} + +// ModifyTCPProfile allows you to change any attribute of a tcp profile. +// Fields that can be modified are referenced in the VirtualServer struct. +func (b *BigIP) ModifyTCPProfile(name string, config *TCPProfile) error { + return b.put(config, uriLtm, uriProfile, uriProfileTCP, name) +} diff --git a/profileUDP.go b/profileUDP.go new file mode 100644 index 0000000..bdf75ce --- /dev/null +++ b/profileUDP.go @@ -0,0 +1,73 @@ +package bigip + +// UDPProfile represents a UDP Profile configuration +type UDPProfile struct { + Kind string `json:"kind,omitempty"` + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + SelfLink string `json:"selfLink,omitempty"` + AllowNoPayload string `json:"allowNoPayload,omitempty"` + DatagramLoadBalancing string `json:"datagramLoadBalancing,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` + IdleTimeout string `json:"idleTimeout,omitempty"` + IPTosToClient string `json:"ipTosToClient,omitempty"` + LinkQosToClient string `json:"linkQosToClient,omitempty"` + NoChecksum string `json:"noChecksum,omitempty"` + ProxyMss string `json:"proxyMss,omitempty"` +} + +// UDPProfiles is an array of UDPProfile structs +type UDPProfiles []UDPProfile + +// UDPProfiles returns a list of udp profiles. +func (b *BigIP) UDPProfiles() (*UDPProfiles, error) { + var serverUDPProfiles UDPProfiles + err, _ := b.getForEntity(&serverUDPProfiles, uriLtm, uriProfile, uriProfileUDP) + if err != nil { + return nil, err + } + + return &serverUDPProfiles, nil +} + +// GetUDPProfile gets a udp profile by name. Returns nil if the udp profile does not exist +func (b *BigIP) GetUDPProfile(name string) (*UDPProfile, error) { + var serverUDPProfile UDPProfile + err, ok := b.getForEntity(&serverUDPProfile, uriLtm, uriProfile, uriProfileUDP, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &serverUDPProfile, nil +} + +// CreateUDPProfile creates a new udp profile on the BIG-IP system. +func (b *BigIP) CreateUDPProfile(name string, parent string) error { + config := &UDPProfile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriProfileUDP) +} + +// AddUDPProfile adds a new udp profile on the BIG-IP system. +func (b *BigIP) AddUDPProfile(config *UDPProfile) error { + return b.post(config, uriLtm, uriProfile, uriProfileUDP) +} + +// DeleteUDPProfile removes a udp profile. +func (b *BigIP) DeleteUDPProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriProfileUDP, name) +} + +// ModifyUDPProfile allows you to change any attribute of a udp profile. +// Fields that can be modified are referenced in the VirtualServer struct. +func (b *BigIP) ModifyUDPProfile(name string, config *UDPProfile) error { + return b.put(config, uriLtm, uriProfile, uriProfileUDP, name) +} diff --git a/serverSSLProfile.go b/serverSSLProfile.go new file mode 100644 index 0000000..bc39f5a --- /dev/null +++ b/serverSSLProfile.go @@ -0,0 +1,105 @@ +package bigip + +// ServerSSLProfiles +// Documentation: https://devcentral.f5.com/wiki/iControlREST.APIRef_tm_ltm_profile_server-ssl.ashx + +// ServerSSLProfiles contains a list of every server-ssl profile on the BIG-IP system. +type ServerSSLProfiles struct { + ServerSSLProfiles []ServerSSLProfile `json:"items"` +} + +// ServerSSLProfile contains information about each server-ssl profile. You can use all +// of these fields when modifying a server-ssl profile. +type ServerSSLProfile struct { + Name string `json:"name"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + Generation int `json:"generation,omitempty"` + AlertTimeout string `json:"alertTimeout,omitempty"` + Authenticate string `json:"authenticate,omitempty"` + AuthenticateDepth int `json:"authenticateDepth,omitempty"` + CaFile string `json:"caFile,omitempty"` + CacheSize int `json:"cacheSize,omitempty"` + CacheTimeout int `json:"cacheTimeout,omitempty"` + Cert string `json:"cert,omitempty"` + Chain string `json:"chain,omitempty"` + Ciphers string `json:"ciphers,omitempty"` + DefaultsFrom string `json:"defaultsFrom"` + ExpireCertResponseControl string `json:"expireCertResponseControl,omitempty"` + GenericAlert string `json:"genericAlert,omitempty"` + HandshakeTimeout string `json:"handshakeTimeout,omitempty"` + Key string `json:"key,omitempty"` + ModSslMethods string `json:"modSslMethods,omitempty"` + Mode string `json:"mode,omitempty"` + TmOptions []string `json:"tmOptions,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + PeerCertMode string `json:"peerCertMode,omitempty"` + ProxySsl string `json:"proxySsl,omitempty"` + RenegotiatePeriod string `json:"renegotiatePeriod,omitempty"` + RenegotiateSize string `json:"renegotiateSize,omitempty"` + Renegotiation string `json:"renegotiation,omitempty"` + RetainCertificate string `json:"retainCertificate,omitempty"` + SecureRenegotiation string `json:"secureRenegotiation,omitempty"` + ServerName string `json:"serverName,omitempty"` + SessionMirroring string `json:"sessionMirroring,omitempty"` + SessionTicket string `json:"sessionTicket,omitempty"` + SniDefault string `json:"sniDefault,omitempty"` + SniRequire string `json:"sniRequire,omitempty"` + SslForwardProxy string `json:"sslForwardProxy,omitempty"` + SslForwardProxyBypass string `json:"sslForwardProxyBypass,omitempty"` + SslSignHash string `json:"sslSignHash,omitempty"` + StrictResume string `json:"strictResume,omitempty"` + UncleanShutdown string `json:"uncleanShutdown,omitempty"` + UntrustedCertResponseControl string `json:"untrustedCertResponseControl,omitempty"` +} + +// ServerSSLProfiles returns a list of server-ssl profiles. +func (b *BigIP) ServerSSLProfiles() (*ServerSSLProfiles, error) { + var serverSSLProfiles ServerSSLProfiles + err, _ := b.getForEntity(&serverSSLProfiles, uriLtm, uriProfile, uriServerSSL) + if err != nil { + return nil, err + } + + return &serverSSLProfiles, nil +} + +// GetServerSSLProfile gets a server-ssl profile by name. Returns nil if the server-ssl profile does not exist +func (b *BigIP) GetServerSSLProfile(name string) (*ServerSSLProfile, error) { + var serverSSLProfile ServerSSLProfile + err, ok := b.getForEntity(&serverSSLProfile, uriLtm, uriProfile, uriServerSSL, name) + if err != nil { + return nil, err + } + if !ok { + return nil, nil + } + + return &serverSSLProfile, nil +} + +// CreateServerSSLProfile creates a new server-ssl profile on the BIG-IP system. +func (b *BigIP) CreateServerSSLProfile(name string, parent string) error { + config := &ServerSSLProfile{ + Name: name, + DefaultsFrom: parent, + } + + return b.post(config, uriLtm, uriProfile, uriServerSSL) +} + +// AddServerSSLProfile adds a new server-ssl profile on the BIG-IP system. +func (b *BigIP) AddServerSSLProfile(config *ServerSSLProfile) error { + return b.post(config, uriLtm, uriProfile, uriServerSSL) +} + +// DeleteServerSSLProfile removes a server-ssl profile. +func (b *BigIP) DeleteServerSSLProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriServerSSL, name) +} + +// ModifyServerSSLProfile allows you to change any attribute of a sever-ssl profile. +// Fields that can be modified are referenced in the VirtualServer struct. +func (b *BigIP) ModifyServerSSLProfile(name string, config *ServerSSLProfile) error { + return b.put(config, uriLtm, uriProfile, uriServerSSL, name) +}