├── .gitignore ├── .travis.yml ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── README.md ├── bigip.go ├── bigip_test.go ├── cm.go ├── examples ├── go-bigip_example.go └── go-bigip_gtm_example.go ├── go.mod ├── go.sum ├── gtm.go ├── gtm_test.go ├── ltm.go ├── ltm_test.go ├── net.go ├── net_test.go ├── resource_builder └── struct_helper.xlsx ├── shared.go ├── shared_test.go ├── sys.go ├── sys_test.go └── vendor └── github.com ├── davecgh └── go-spew │ ├── LICENSE │ └── spew │ ├── bypass.go │ ├── bypasssafe.go │ ├── common.go │ ├── config.go │ ├── doc.go │ ├── dump.go │ ├── format.go │ └── spew.go ├── pmezard └── go-difflib │ ├── LICENSE │ └── difflib │ └── difflib.go ├── scottdware └── go-bigip │ ├── .gitignore │ ├── .travis.yml │ ├── Gopkg.lock │ ├── Gopkg.toml │ ├── LICENSE │ ├── README.md │ ├── bigip.go │ ├── cm.go │ ├── gtm.go │ ├── ltm.go │ ├── net.go │ ├── shared.go │ └── sys.go └── stretchr └── testify ├── LICENSE ├── assert ├── assertion_format.go ├── assertion_format.go.tmpl ├── assertion_forward.go ├── assertion_forward.go.tmpl ├── assertions.go ├── doc.go ├── errors.go ├── forward_assertions.go └── http_assertions.go ├── require ├── doc.go ├── forward_requirements.go ├── require.go ├── require.go.tmpl ├── require_forward.go ├── require_forward.go.tmpl └── requirements.go └── suite ├── doc.go ├── interfaces.go └── suite.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | 4 | debug.test -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.7 5 | - 1.8 6 | - 1.9 7 | - "1.10" 8 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" 6 | name = "github.com/davecgh/go-spew" 7 | packages = ["spew"] 8 | pruneopts = "UT" 9 | revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" 10 | version = "v1.1.1" 11 | 12 | [[projects]] 13 | digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" 14 | name = "github.com/pmezard/go-difflib" 15 | packages = ["difflib"] 16 | pruneopts = "UT" 17 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 18 | version = "v1.0.0" 19 | 20 | [[projects]] 21 | branch = "master" 22 | digest = "1:e65d90d60e7353c956a9bd4ffe47c066a12221c3421551d5aa1e1b82cf9ec53b" 23 | name = "github.com/scottdware/go-bigip" 24 | packages = ["."] 25 | pruneopts = "UT" 26 | revision = "cc89474e0b6606162f3d95798628f99d3825c9c1" 27 | 28 | [[projects]] 29 | digest = "1:5110e3d4f130772fd39e6ce8208ad1955b242ccfcc8ad9d158857250579c82f4" 30 | name = "github.com/stretchr/testify" 31 | packages = [ 32 | "assert", 33 | "require", 34 | "suite", 35 | ] 36 | pruneopts = "UT" 37 | revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" 38 | version = "v1.2.2" 39 | 40 | [solve-meta] 41 | analyzer-name = "dep" 42 | analyzer-version = 1 43 | input-imports = [ 44 | "github.com/scottdware/go-bigip", 45 | "github.com/stretchr/testify/assert", 46 | "github.com/stretchr/testify/require", 47 | "github.com/stretchr/testify/suite", 48 | ] 49 | solver-name = "gps-cdcl" 50 | solver-version = 1 51 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | name = "github.com/stretchr/testify" 30 | version = "1.2.2" 31 | 32 | [prune] 33 | go-tests = true 34 | unused-packages = true 35 | 36 | [[constraint]] 37 | branch = "master" 38 | name = "github.com/scottdware/go-bigip" 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Scott Ware 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## go-bigip 2 | [![GoDoc](https://godoc.org/github.com/scottdware/go-bigip?status.svg)](https://godoc.org/github.com/scottdware/go-bigip) [![Travis-CI](https://travis-ci.org/scottdware/go-bigip.svg?branch=master)](https://travis-ci.org/scottdware/go-bigip) 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/scottdware/go-bigip)](https://goreportcard.com/report/github.com/scottdware/go-bigip) 4 | [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/scottdware/go-bigip/master/LICENSE) 5 | 6 | A Go package that interacts with F5 BIG-IP systems using the REST API. 7 | 8 | Some of the tasks you can do are as follows: 9 | 10 | * Get a detailed list of all nodes, pools, vlans, routes, trunks, route domains, self IP's, virtual servers, monitors on the BIG-IP system. 11 | * Create/delete nodes, pools, vlans, routes, trunks, route domains, self IP's, virtual servers, monitors, etc. 12 | * Modify individual settings for all of the above. 13 | * Change the status of nodes and individual pool members (enable/disable). 14 | 15 | > **Note**: You must be on version 11.4+! For the features that deal with internal data groups, you must be running version 11.6+! 16 | 17 | ### Examples & Documentation 18 | Visit the [GoDoc][godoc-go-bigip] page for package documentation and examples. 19 | 20 | Here's a [blog post][blog] that goes a little more in-depth. 21 | 22 | ### Contributors 23 | A very special thanks to the following who have helped contribute to this software, especially: 24 | 25 | * [Kenneth Maglio](https://github.com/kenmaglio) 26 | * [Adam Burnett](https://github.com/aburnett) 27 | * [Michael D. Ivey](https://github.com/ivey) 28 | 29 | [godoc-go-bigip]: http://godoc.org/github.com/scottdware/go-bigip 30 | [license]: https://github.com/scottdware/go-bigip/blob/master/LICENSE 31 | [blog]: http://sdubs.org/go-big-ip-or-go-home/ 32 | -------------------------------------------------------------------------------- /bigip_test.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "strings" 7 | "testing" 8 | "text/template" 9 | "time" 10 | 11 | "github.com/stretchr/testify/assert" 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | func TestTokenSession(t *testing.T) { 16 | now := time.Now() 17 | timeout := 1200 18 | startTime, err := now.MarshalJSON() 19 | require.NoError(t, err) 20 | h := handler{ 21 | StartTime: string(startTime), 22 | Timeout: timeout, 23 | LastUpdate: now.Unix() * microToSeconds, 24 | Expiry: now.Add(time.Duration(timeout)*time.Second).Unix() * microToSeconds, 25 | } 26 | user := "user" 27 | password := "password" 28 | testServer := httptest.NewServer(&h) 29 | var b *BigIP 30 | t.Run("should login", func(t *testing.T) { 31 | b, err = NewTokenSession(testServer.URL, user, password, "tmos", nil) 32 | require.NoError(t, err) 33 | assert.Equal(t, 1, h.loginCounter) 34 | assert.Equal(t, 0, h.refreshCounter) 35 | assert.Equal(t, user, b.User) 36 | assert.Equal(t, password, b.Password) 37 | assert.True(t, b.TokenExpiry.Sub(now) > 1000*time.Second) 38 | }) 39 | 40 | t.Run("should refresh with unexpired token", func(t *testing.T) { 41 | now := time.Now() 42 | startTime, err := now.MarshalJSON() 43 | require.NoError(t, err) 44 | h.StartTime = string(startTime) 45 | h.Timeout = 3600 46 | h.LastUpdate = now.Unix() * microToSeconds 47 | h.Expiry = now.Add(time.Duration(h.Timeout)*time.Second).Unix() * microToSeconds 48 | expiryBefore := b.TokenExpiry 49 | err = b.RefreshTokenSession(time.Duration(h.Timeout) * time.Second) 50 | require.NoError(t, err) 51 | assert.Equal(t, 1, h.loginCounter) 52 | assert.Equal(t, 1, h.refreshCounter) 53 | assert.True(t, b.TokenExpiry.Sub(expiryBefore) > 0) 54 | }) 55 | 56 | t.Run("refresh should login with expired token", func(t *testing.T) { 57 | b.TokenExpiry = now.Add(-10000 * time.Second) // token is expred 58 | err = b.RefreshTokenSession(3600 * time.Second) 59 | require.NoError(t, err) 60 | assert.Equal(t, 2, h.loginCounter) 61 | assert.Equal(t, 1, h.refreshCounter) 62 | }) 63 | t.Run("should login if refresh failes", func(t *testing.T) { 64 | h.Timeout = 0 // force refresh error (see handler below) 65 | err = b.RefreshTokenSession(3600 * time.Second) 66 | require.NoError(t, err) 67 | assert.Equal(t, 3, h.loginCounter) 68 | assert.Equal(t, 2, h.refreshCounter) 69 | }) 70 | } 71 | 72 | type handler struct { 73 | StartTime string 74 | Timeout int 75 | LastUpdate int64 76 | Expiry int64 77 | loginCounter int 78 | refreshCounter int 79 | } 80 | 81 | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 82 | if r.Method == "POST" && r.URL.Path == "/mgmt/shared/authn/login" { 83 | h.loginCounter++ 84 | tmpl, err := template.New("response").Parse(loginResponseTmpl) 85 | if err != nil { 86 | http.Error(w, "failed to render template", http.StatusInternalServerError) 87 | return 88 | } 89 | tmpl.Execute(w, h) 90 | return 91 | } 92 | if r.Method == "PATCH" && strings.HasPrefix(r.URL.Path, "/mgmt/shared/authz/tokens/") { 93 | h.refreshCounter++ 94 | if h.Timeout <= 0 { 95 | http.Error(w, "internal server error", http.StatusInternalServerError) 96 | } 97 | tmpl, err := template.New("response").Parse(refreshResponse) 98 | if err != nil { 99 | http.Error(w, "failed to render template", http.StatusInternalServerError) 100 | return 101 | } 102 | tmpl.Execute(w, h) 103 | return 104 | } 105 | http.Error(w, "not found", http.StatusNotFound) 106 | } 107 | 108 | const loginResponseTmpl = `{ 109 | "username": "a-user", 110 | "loginReference": { 111 | "link": "https://localhost/mgmt/cm/system/authn/providers/tmos/1f44a60e-11a7-3c51-a49f-82983026b41b/login" 112 | }, 113 | "loginProviderName": "tmos", 114 | "token": { 115 | "token": "KZ44TOKEN7SNOTZNR7D7UP24SC", 116 | "name": "KZ44TOKEN7SNOTZNR7D7UP24SC", 117 | "userName": "a-user", 118 | "authProviderName": "tmos", 119 | "user": { 120 | "link": "https://localhost/mgmt/cm/system/authn/providers/tmos/1f44a60e-11a7-3c51-a49f-82983026b41b/users/40994460-44e3-3a09-8837-2189119665e5" 121 | }, 122 | "timeout": {{ .Timeout }}, 123 | "startTime": {{ .StartTime }}, 124 | "address": "192.168.1.2", 125 | "partition": "[All]", 126 | "generation": 1, 127 | "lastUpdateMicros": {{ .LastUpdate }}, 128 | "expirationMicros": {{ .Expiry }}, 129 | "kind": "shared:authz:tokens:authtokenitemstate", 130 | "selfLink": "https://localhost/mgmt/shared/authz/tokens/KZ44TOKEN7SNOTZNR7D7UP24SC" 131 | }, 132 | "generation": 0, 133 | "lastUpdateMicros": 0 134 | } 135 | ` 136 | 137 | const refreshResponse = `{ 138 | "token": "KZ44TOKEN7SNOTZNR7D7UP24SC", 139 | "name": "KZ44TOKEN7SNOTZNR7D7UP24SC", 140 | "userName": "a-user", 141 | "authProviderName": "tmos", 142 | "user": { 143 | "link": "https://localhost/mgmt/cm/system/authn/providers/tmos/1f44a60e-11a7-3c51-a49f-82983026b41b/users/40994460-44e3-3a09-8837-2189119665e5" 144 | }, 145 | "timeout": {{ .Timeout }}, 146 | "startTime": {{ .StartTime }}, 147 | "address": "192.168.1.2", 148 | "partition": "[All]", 149 | "generation": 2, 150 | "lastUpdateMicros": {{ .LastUpdate }}, 151 | "expirationMicros": {{ .Expiry }}, 152 | "kind": "shared:authz:tokens:authtokenitemstate", 153 | "selfLink": "https://localhost/mgmt/shared/authz/tokens/KZ44TOKEN7SNOTZNR7D7UP24SC" 154 | } 155 | ` 156 | -------------------------------------------------------------------------------- /cm.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | // Devices contains a list of every device on the BIG-IP system. 11 | type Devices struct { 12 | Devices []Device `json:"items"` 13 | } 14 | 15 | // UnicastAddress represent a device unicast address 16 | type UnicastAddress struct { 17 | EffectiveIP string `json:"effectiveIp,omitempty"` 18 | EffectivePort int `json:"effectivePort,omitempty"` 19 | IP string `json:"ip,omitempty"` 20 | Port int `json:"port,omitempty"` 21 | } 22 | 23 | // Device contains information about each individual device. 24 | type Device struct { 25 | Name string `json:"name,omitempty"` 26 | Partition string `json:"partition,omitempty"` 27 | FullPath string `json:"fullPath,omitempty"` 28 | Generation int `json:"generation,omitempty"` 29 | FailoverState string `json:"failoverState,omitempty"` 30 | Hostname string `json:"hostname,omitempty"` 31 | ManagementIp string `json:"managementIp,omitempty"` 32 | SelfDevice string `json:"selfDevice,omitempty"` 33 | ActiveModules []string `json:"activeModules,omitempty"` 34 | AppService string `json:"appService,omitempty"` 35 | BaseMac string `json:"baseMac,omitempty"` 36 | Build string `json:"build,omitempty"` 37 | Cert string `json:"cert,omitempty"` 38 | ChassisId string `json:"chassisId,omitempty"` 39 | ChassisType string `json:"chassisType,omitempty"` 40 | Comment string `json:"comment,omitempty"` 41 | ConfigSyncIP string `json:"configSyncIp,omitempty"` 42 | Contact string `json:"contact,omitempty"` 43 | Description string `json:"description,omitempty"` 44 | Edition string `json:"edition,omitempty"` 45 | HACapacity int `json:"haCapacity,omitempty"` 46 | InactiveModules []string `json:"inactiveModules,omitempty"` 47 | Key string `json:"key,omitempty"` 48 | Location string `json:"location,omitempty"` 49 | MarketingName string `json:"marketingName,omitempty"` 50 | MirrorIP string `json:"json:mirrorIp,omitempty"` 51 | MirrorSecondaryIP string `json:"mirrorSecondaryIp,omitempty"` 52 | MulticastInterface string `json:"multicastInterface,omitempty"` 53 | MulticastIP string `json:"multicastIp,omitempty"` 54 | MulticastPort int `json:"multicastPort,omitempty"` 55 | OptionalModules []string `json:"optionalModules,omitempty"` 56 | TMPartition string `json:"tmPartition,omitempty"` 57 | PlatformID string `json:"platformId,omitempty"` 58 | Product string `json:"product,omitempty"` 59 | TimeLimitedModules []string `json:"timeLimitedModules,omitempty"` 60 | Timezone string `json:"timeZone,omitempty"` 61 | UnicastAddress []UnicastAddress `json:"unicastAddress,omitempty"` 62 | Version string `json:"version"` 63 | } 64 | 65 | type ConfigSync struct { 66 | Command string `json:"command,omitempty"` 67 | UtilCmdArgs string `json:"utilCmdArgs,omitempty"` 68 | } 69 | 70 | const ( 71 | uriCm = "cm" 72 | uriDevice = "device" 73 | uriAutodeploy = "autodeploy" 74 | uriSoftwareImageUploads = "software-image-uploads" 75 | ) 76 | 77 | // Devices returns a list of devices. 78 | func (b *BigIP) Devices() (*Devices, error) { 79 | var devices Devices 80 | err, _ := b.getForEntity(&devices, uriCm, uriDevice) 81 | 82 | if err != nil { 83 | return nil, err 84 | } 85 | 86 | return &devices, nil 87 | } 88 | 89 | // GetCurrentDevice returns a current device. 90 | func (b *BigIP) GetCurrentDevice() (*Device, error) { 91 | devices, err := b.Devices() 92 | if err != nil { 93 | return nil, err 94 | } 95 | for _, d := range devices.Devices { 96 | // f5 api is returning bool value as string 97 | if d.SelfDevice == "true" { 98 | return &d, nil 99 | } 100 | } 101 | return nil, errors.New("could not find this device") 102 | } 103 | 104 | // ConfigSyncToGroup runs command config-sync to-group 105 | func (b *BigIP) ConfigSyncToGroup(name string) error { 106 | args := "config-sync to-group " + name 107 | config := &ConfigSync{ 108 | Command: "run", 109 | UtilCmdArgs: args, 110 | } 111 | return b.post(config, uriCm) 112 | } 113 | 114 | // Upload a software image 115 | func (b *BigIP) UploadSoftwareImage(f *os.File) (*Upload, error) { 116 | if !strings.HasSuffix(f.Name(), ".iso") { 117 | err := fmt.Errorf("File must have .iso extension") 118 | return nil, err 119 | } 120 | info, err := f.Stat() 121 | if err != nil { 122 | return nil, err 123 | } 124 | return b.Upload(f, info.Size(), uriCm, uriAutodeploy, uriSoftwareImageUploads, info.Name()) 125 | } 126 | -------------------------------------------------------------------------------- /examples/go-bigip_example.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "fmt" 5 | "github.com/scottdware/go-bigip" 6 | ) 7 | 8 | func main() { 9 | // Connect to the BIG-IP system. 10 | f5 := bigip.NewSession("ltm.company.com", "admin", "secret", nil) 11 | 12 | // Get a list of all VLAN's, and print their names to the console. 13 | vlans, err := f5.Vlans() 14 | if err != nil { 15 | fmt.Println(err) 16 | } 17 | 18 | for _, vlan := range vlans.Vlans { 19 | fmt.Println(vlan.Name) 20 | } 21 | 22 | // Create a VLAN 23 | f5.CreateVlan("vlan1138", 1138) 24 | f5.CreateVlan("vlan421", 421) 25 | 26 | // Add an untagged interface to a VLAN. 27 | f5.AddInterfaceToVlan("vlan1138", "1.2", false) 28 | 29 | // Delete a VLAN. 30 | f5.DeleteVlan("vlan1138") 31 | 32 | // Create a couple of nodes. 33 | f5.CreateNode("web-server-1", "192.168.1.50") 34 | f5.CreateNode("web-server-2", "192.168.1.51") 35 | f5.CreateNode("ssl-web-server-1", "10.2.2.50") 36 | f5.CreateNode("ssl-web-server-2", "10.2.2.51") 37 | 38 | // Create a pool, and add members to it. When adding a member, you must 39 | // specify the port in the format of :. 40 | f5.CreatePool("web_farm_80_pool") 41 | f5.AddPoolMember("web_farm_80_pool", "web-server-1:80") 42 | f5.AddPoolMember("web_farm_80_pool", "web-server-2:80") 43 | f5.CreatePool("ssl_443_pool") 44 | f5.AddPoolMember("ssl_443_pool", "ssl-web-server-1:443") 45 | f5.AddPoolMember("ssl_443_pool", "ssl-web-server-2:443") 46 | 47 | // Create a monitor, and assign it to a pool. 48 | f5.CreateMonitor("web_http_monitor", "http", 5, 16, "GET /\r\n", "200 OK", "http") 49 | f5.AddMonitorToPool("web_http_monitor", "web_farm_80_pool") 50 | 51 | // Create a virtual server, with the above pool. The third field is the subnet 52 | // mask, and that can either be in CIDR notation or decimal. For any/all destinations 53 | // and ports, use '0' for the mask and/or port. 54 | f5.CreateVirtualServer("web_farm_VS", "0.0.0.0", "0.0.0.0", "web_farm_80_pool", 80) 55 | f5.CreateVirtualServer("ssl_web_farm_VS", "10.1.1.0", "24", "ssl_443_pool", 443) 56 | 57 | // Remove a pool member. 58 | f5.DeletePoolMember("web_farm_80_pool", "web-server-2:80") 59 | 60 | // Create a trunk, with LACP enabled. 61 | f5.CreateTrunk("Aggregated", "1.2, 1.4, 1.6", true) 62 | 63 | // Disable a virtual address. 64 | f5.VirtualAddressStatus("web_farm_VS", "disable") 65 | 66 | // Disable a pool member. 67 | f5.PoolMemberStatus("ssl_443_pool", "ssl-web-server-1:443", "disable") 68 | 69 | // Create a self IP. 70 | f5.CreateSelfIP("vlan1138", "10.10.10.1/24", "vlan1138") 71 | f5.CreateSelfIP("vlan421", "10.10.20.1/25", "vlan421") 72 | 73 | // Add a static route. 74 | f5.CreateRoute("servers", "10.1.1.0/24", "10.50.1.5") 75 | 76 | // Create a route domain. 77 | f5.CreateRouteDomain("vlans", 10, true, "vlan1138, vlan421") 78 | } 79 | -------------------------------------------------------------------------------- /examples/go-bigip_gtm_example.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/scottdware/go-bigip" 7 | ) 8 | 9 | // Note: Had to call main something different as the package complained main was in LTM's example 10 | func mainGTM() { 11 | // Connect to the BIG-IP system. 12 | f5 := bigip.NewSession("gtm.company.com", "admin", "secret", nil) 13 | 14 | // Get a list of all WideIP's, and print their names to the console. 15 | result, err := f5.GetGTMWideIPs(bigip.ARecord) 16 | if err != nil { 17 | fmt.Println(err) 18 | } 19 | 20 | for _, wideip := range result.GTMWideIPs { 21 | fmt.Println(wideip.Name) 22 | } 23 | 24 | // Ordering here just makes things easier. 25 | // Since Pools can exist without any other reliance, we start there. 26 | poolConfig := &bigip.GTMAPool{ 27 | Name: "sample.company.com_pool", 28 | Partition: "Common", 29 | } 30 | f5.AddGTMAPool(poolConfig) 31 | 32 | // Create a WideIP Pool config using our Pool Config 33 | wipPoolConfig := bigip.GTMWideIPPool{ 34 | Name: poolConfig.Name, 35 | Partition: poolConfig.Partition, 36 | } 37 | 38 | // right now we only have a 1:1 mapping - but WideIPs can have multiple pools 39 | wipPools := &[]bigip.GTMWideIPPool{wipPoolConfig} 40 | 41 | wipConfig := &bigip.GTMWideIP{ 42 | Name: "sample.company.com", 43 | Partition: "Common", 44 | Pools: wipPools, 45 | } 46 | 47 | // Crate the new WideIP 48 | f5.AddGTMWideIP(wipConfig, bigip.ARecord) 49 | 50 | // Add Pools 51 | // This part is faked out - and you will have to provide some information to make this work. 52 | // Namely you have to know the LTM Server which was setup in the GTM (with VirtualServerDiscovery turned on) 53 | // And you will also need at least one virtual server by full path e.g. /partition/name 54 | 55 | fullPathAPool := fmt.Sprintf("/%s/%s", poolConfig.Partition, poolConfig.Name) 56 | virtualServerPath := "/Common/baseapp_80_vs" 57 | serverPath := "/Common/someltm" 58 | 59 | // Add the Virtual Server to the list of members for the pool 60 | f5.CreateGTMAPoolMember(fullPathAPool, serverPath, virtualServerPath) 61 | 62 | // Unwind all the work 63 | f5.DeleteGTMAPoolMember(fullPathAPool, serverPath, virtualServerPath) 64 | 65 | wipFullPath := fmt.Sprintf("/%s/%s", wipConfig.Partition, wipConfig.Name) 66 | f5.DeleteGTMWideIP(wipFullPath, bigip.ARecord) 67 | 68 | f5.DeleteGTMPool(fullPathAPool, bigip.ARecord) 69 | } 70 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/scottdware/go-bigip 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/davecgh/go-spew v1.1.1 // indirect 7 | github.com/pmezard/go-difflib v1.0.0 // indirect 8 | github.com/stretchr/testify v1.2.2 9 | ) 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= 6 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 7 | -------------------------------------------------------------------------------- /resource_builder/struct_helper.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottdware/go-bigip/deb9b0aff84a405abf9a3c384cb29e6dd1a5d02f/resource_builder/struct_helper.xlsx -------------------------------------------------------------------------------- /shared.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | const ( 12 | uriClientSSL = "client-ssl" 13 | uriDatagroup = "data-group" 14 | uriHttp = "http" 15 | uriHttpCompression = "http-compression" 16 | uriIRule = "rule" 17 | uriInternal = "internal" 18 | uriLtm = "ltm" 19 | uriMonitor = "monitor" 20 | uriNode = "node" 21 | uriOneConnect = "one-connect" 22 | uriPolicy = "policy" 23 | uriPool = "pool" 24 | uriPoolMember = "members" 25 | uriProfile = "profile" 26 | uriRules = "rules" 27 | uriServerSSL = "server-ssl" 28 | uriSnatPool = "snatpool" 29 | uriTcp = "tcp" 30 | uriUdp = "udp" 31 | uriVirtual = "virtual" 32 | uriVirtualAddress = "virtual-address" 33 | uriGtm = "gtm" 34 | uriWideIp = "wideip" 35 | uriARecord = "a" 36 | uriAAAARecord = "aaaa" 37 | uriCNameRecord = "cname" 38 | uriMXRecord = "mx" 39 | uriNaptrRecord = "naptr" 40 | uriSrvRecord = "srv" 41 | uriPoolMembers = "members" 42 | ENABLED = "enable" 43 | DISABLED = "disable" 44 | CONTEXT_SERVER = "serverside" 45 | CONTEXT_CLIENT = "clientside" 46 | CONTEXT_ALL = "all" 47 | 48 | // Newer policy APIs have a draft-publish workflow that this library does not support. 49 | policyVersionSuffix = "?ver=11.5.1" 50 | ) 51 | 52 | var cidr = map[string]string{ 53 | "0": "0.0.0.0", 54 | "1": "128.0.0.0", 55 | "2": "192.0.0.0", 56 | "3": "224.0.0.0", 57 | "4": "240.0.0.0", 58 | "5": "248.0.0.0", 59 | "6": "252.0.0.0", 60 | "7": "254.0.0.0", 61 | "8": "255.0.0.0", 62 | "9": "255.128.0.0", 63 | "10": "255.192.0.0", 64 | "11": "255.224.0.0", 65 | "12": "255.240.0.0", 66 | "13": "255.248.0.0", 67 | "14": "255.252.0.0", 68 | "15": "255.254.0.0", 69 | "16": "255.255.0.0", 70 | "17": "255.255.128.0", 71 | "18": "255.255.192.0", 72 | "19": "255.255.224.0", 73 | "20": "255.255.240.0", 74 | "21": "255.255.248.0", 75 | "22": "255.255.252.0", 76 | "23": "255.255.254.0", 77 | "24": "255.255.255.0", 78 | "25": "255.255.255.128", 79 | "26": "255.255.255.192", 80 | "27": "255.255.255.224", 81 | "28": "255.255.255.240", 82 | "29": "255.255.255.248", 83 | "30": "255.255.255.252", 84 | "31": "255.255.255.254", 85 | "32": "255.255.255.255", 86 | } 87 | 88 | // GTMType handles the record types possible in the GTM as strings 89 | type GTMType string 90 | 91 | // GTM Record Types 92 | const ( 93 | ARecord GTMType = uriARecord 94 | AAAARecord GTMType = uriAAAARecord 95 | CNAMERecord GTMType = uriCNameRecord 96 | MXRecord GTMType = uriMXRecord 97 | NAPTRRecord GTMType = uriNaptrRecord 98 | SRVRecord GTMType = uriSrvRecord 99 | ) 100 | 101 | const ( 102 | uriShared = "shared" 103 | uriLicensing = "licensing" 104 | uriActivation = "activation" 105 | uriRegistration = "registration" 106 | uriFileTransfer = "file-transfer" 107 | uriUploads = "uploads" 108 | 109 | activationComplete = "LICENSING_COMPLETE" 110 | activationInProgress = "LICENSING_ACTIVATION_IN_PROGRESS" 111 | activationFailed = "LICENSING_FAILED" 112 | activationNeedEula = "NEED_EULA_ACCEPT" 113 | ) 114 | 115 | // https://devcentral.f5.com/wiki/iControl.Licensing_resource_API.ashx 116 | type Activation struct { 117 | BaseRegKey string `json:"baseRegKey,omitempty"` 118 | AddOnKeys []string `json:"addOnKeys,omitempty"` 119 | IsAutomaticActivation bool `json:"isAutomaticActivation"` 120 | Status string `json:"status,omitempty"` 121 | LicenseText *string `json:"licenseText,omitempty"` 122 | ErrorText *string `json:"errorText,omitempty"` 123 | EulaText *string `json:"eulaText,omitempty"` 124 | } 125 | 126 | // https://devcentral.f5.com/wiki/iControl.Licensing_resource_API.ashx 127 | type LicenseState struct { 128 | Vendor string `json:"vendor"` 129 | 130 | LicensedDateTime string `json:"licensedDateTime"` 131 | LicensedVersion string `json:"licensedVersion"` 132 | LicenseEndDateTime string `json:"licenseEndDateTime"` 133 | LicenseStartDateTime string `json:"licenseStartDateTime"` 134 | 135 | RegistrationKey string `json:"registrationKey"` 136 | Dossier string `json:"dossier"` 137 | Authorization string `json:"authorization"` 138 | Usage string `json:"usage"` 139 | PlatformId string `json:"platformId"` 140 | AuthVers string `json:"authVers"` 141 | ServiceCheckDateTime string `json:"serviceCheckDateTime"` 142 | MachineId string `json:"machineId"` 143 | ExclusivePlatform []string `json:"exclusivePlatform"` 144 | 145 | ActiveModules []string `json:"activeModules"` 146 | OptionalModules []string `json:"optionalModules"` 147 | FeatureFlags []LicenseFeatureFlag `json:"featureFlags"` 148 | 149 | ExpiresInDays string `json:"expiresInDays"` 150 | ExpiresInDaysMessage string `json:"expiresInDaysMessage"` 151 | } 152 | 153 | // Describes feature flags that are defined in licenses. 154 | type LicenseFeatureFlag struct { 155 | FeatureName string `json:"featureName"` 156 | FeatureValue string `json:"featureValue"` 157 | } 158 | 159 | // Gets the current activation status. Use after calling Activate. See the docs for more: 160 | // https://devcentral.f5.com/wiki/iControl.Licensing_activation_APIs.ashx 161 | func (b *BigIP) GetActivationStatus() (*Activation, error) { 162 | var a Activation 163 | err, _ := b.getForEntity(&a, uriShared, uriLicensing, uriActivation) 164 | if err != nil { 165 | return nil, err 166 | } 167 | return &a, nil 168 | } 169 | 170 | // Sends the Activation to the activation endpoint. For documentation on how this works, see: 171 | // https://devcentral.f5.com/wiki/iControl.Licensing_activation_APIs.ashx 172 | func (b *BigIP) Activate(a Activation) error { 173 | return b.post(a, uriShared, uriLicensing, uriActivation) 174 | } 175 | 176 | // Returns the current license state. 177 | func (b *BigIP) GetLicenseState() (*LicenseState, error) { 178 | var l LicenseState 179 | err, _ := b.getForEntity(&l, uriShared, uriLicensing, uriRegistration) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return &l, nil 184 | } 185 | 186 | // Installs the given license. 187 | func (b *BigIP) InstallLicense(licenseText string) error { 188 | r := map[string]string{"licenseText": licenseText} 189 | return b.put(r, uriShared, uriLicensing, uriRegistration) 190 | } 191 | 192 | // Automatically activate this registration key and install the resulting license. 193 | // The BIG-IP must have access to the activation server for this to work. 194 | func (b *BigIP) AutoLicense(regKey string, addOnKeys []string, timeout time.Duration) error { 195 | deadline := time.Now().Add(timeout) 196 | actreq := Activation{BaseRegKey: regKey, AddOnKeys: addOnKeys, IsAutomaticActivation: true} 197 | 198 | if err := b.Activate(actreq); err != nil { 199 | return err 200 | } 201 | 202 | loop: 203 | for time.Now().Before(deadline) { 204 | actresp, err := b.GetActivationStatus() 205 | if err != nil { 206 | return err 207 | } 208 | 209 | if actresp.Status == activationInProgress { 210 | time.Sleep(1 * time.Second) 211 | continue 212 | } 213 | 214 | switch actresp.Status { 215 | case activationComplete: 216 | return b.InstallLicense(*actresp.LicenseText) 217 | case activationFailed: 218 | return fmt.Errorf("Licensing failed: %s", *actresp.ErrorText) 219 | case activationNeedEula: 220 | eula := *actresp.EulaText 221 | actreq.EulaText = &eula 222 | break loop 223 | default: 224 | return fmt.Errorf("Unknown licensing status: %s", actresp.Status) 225 | } 226 | } 227 | 228 | if actreq.EulaText == nil { 229 | return fmt.Errorf("Timed out after %s", timeout) 230 | } 231 | 232 | // Proceed with EULA acceptance 233 | if err := b.Activate(actreq); err != nil { 234 | return err 235 | } 236 | 237 | for time.Now().Before(deadline) { 238 | actresp, err := b.GetActivationStatus() 239 | if err != nil { 240 | return err 241 | } 242 | 243 | if actresp.Status == activationInProgress { 244 | time.Sleep(1 * time.Second) 245 | continue 246 | } 247 | 248 | switch actresp.Status { 249 | case activationComplete: 250 | return b.InstallLicense(*actresp.LicenseText) 251 | case activationNeedEula: 252 | return fmt.Errorf("Tried to accept EULA, but status is: %s", *actresp.ErrorText) 253 | case activationFailed: 254 | return fmt.Errorf("Licensing failed: %s", *actresp.ErrorText) 255 | } 256 | return fmt.Errorf("Unknown licensing status: %s", actresp.Status) 257 | } 258 | 259 | return fmt.Errorf("Timed out after %s", timeout) 260 | } 261 | 262 | // Upload a file 263 | func (b *BigIP) UploadFile(f *os.File) (*Upload, error) { 264 | if strings.HasSuffix(f.Name(), ".iso") { 265 | err := fmt.Errorf("File must not have .iso extension") 266 | return nil, err 267 | } 268 | info, err := f.Stat() 269 | if err != nil { 270 | return nil, err 271 | } 272 | return b.Upload(f, info.Size(), uriShared, uriFileTransfer, uriUploads, info.Name()) 273 | } 274 | 275 | // Upload a file from a byte slice 276 | func (b *BigIP) UploadBytes(data []byte, filename string) (*Upload, error) { 277 | r := bytes.NewReader(data) 278 | size := int64(len(data)) 279 | return b.Upload(r, size, uriShared, uriFileTransfer, uriUploads, filename) 280 | } 281 | -------------------------------------------------------------------------------- /shared_test.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "net/http" 8 | "net/http/httptest" 9 | "os" 10 | "path" 11 | "testing" 12 | "time" 13 | 14 | "github.com/stretchr/testify/suite" 15 | ) 16 | 17 | const validLicenseState = `{ 18 | "vendor": "F5 Networks, Inc.", 19 | "licensedDateTime": "2018-04-02T00:00:00-07:00", 20 | "licensedVersion": "13.1.0", 21 | "licenseEndDateTime": "2018-05-03T00:00:00-07:00", 22 | "licenseStartDateTime": "2018-04-01T00:00:00-07:00", 23 | "registrationKey": "reg key here", 24 | "dossier": "dossier here", 25 | "authorization": "authorization here", 26 | "usage": "Evaluation", 27 | "platformId": "Z100k", 28 | "authVers": "5b", 29 | "serviceCheckDateTime": "2018-03-29T00:00:00-07:00", 30 | "machineId": "uuid here", 31 | "exclusivePlatform": [ 32 | "Z100", 33 | "Z100A", 34 | "Z100a_icm", 35 | "Z100AzureCloud", 36 | "Z100GoogleCloud", 37 | "Z100K", 38 | "Z100x" 39 | ], 40 | "activeModules": [ 41 | "Local Traffic Manager, VE-10G|RAYPVKR-EYOXDFQ|Routing Bundle, VE|Rate Shaping|APM, Limited|SSL, VE|Max Compression, VE|Anti-Virus Checks|Base Endpoint Security Checks|Firewall Checks|Network Access|Secure Virtual Keyboard|APM, Web Application|Machine Certificate Checks|Protected Workspace|Remote Desktop|App Tunnel" 42 | ], 43 | "optionalModules": [ 44 | "Advanced Protocols, VE", 45 | "APC-VE, Introductory", 46 | "APC-VE, Introductory to Medium Upgrade", 47 | "APC-VE, Medium", 48 | "APM, Base, VE (50 CCU / 200 AS)", 49 | "App Mode (TMSH Only, No Root/Bash)", 50 | "BIG-IP VE, Multicast Routing", 51 | "CGN, ADD-VE, 10G", 52 | "DataSafe, VE-10G", 53 | "DNS and GTM (1K QPS), VE", 54 | "DNS and GTM (250 QPS), VE", 55 | "External Interface and Network HSM, VE", 56 | "FIPS 140-2 Level 1, BIG-IP VE-1G to 10G", 57 | "IP Intelligence, 1Yr, VE-10G", 58 | "IP Intelligence, 3Yr, VE-10G", 59 | "LTM to Best Bundle Upgrade, 10Gbps", 60 | "LTM to Better Bundle Upgrade, 10Gbps", 61 | "PEM, ADD-VE, 5G", 62 | "Secure Web Gateway, 1Yr, VE", 63 | "Secure Web Gateway, 3Yr, VE", 64 | "Secure Web Gateway, VE-3G-10G, 10000 Sessions, 1Yr", 65 | "Secure Web Gateway, VE-3G-10G, 10000 Sessions, 3Yr", 66 | "Secure Web Gateway, VE-3G-10G, 5000 Sessions, 1Yr", 67 | "Secure Web Gateway, VE-3G-10G, 5000 Sessions, 3Yr", 68 | "SSL, Forward Proxy, VE", 69 | "URL Filtering, 1Yr, VE", 70 | "URL Filtering, 3Yr, VE", 71 | "URL Filtering, VE-3G-10G, 10000 Sessions, 1Yr", 72 | "URL Filtering, VE-3G-10G, 10000 Sessions, 3Yr", 73 | "URL Filtering, VE-3G-10G, 5000 Sessions, 1Yr", 74 | "URL Filtering, VE-3G-10G, 5000 Sessions, 3Yr" 75 | ], 76 | "featureFlags": [ 77 | { 78 | "featureName": "perf_SSL_Mbps", 79 | "featureValue": "1" 80 | }, 81 | { 82 | "featureName": "apm_urlf_limited_sessions", 83 | "featureValue": "10" 84 | }, 85 | { 86 | "featureName": "apml_sessions", 87 | "featureValue": "10" 88 | }, 89 | { 90 | "featureName": "perf_VE_throughput_Mbps", 91 | "featureValue": "10000" 92 | }, 93 | { 94 | "featureName": "perf_VE_cores", 95 | "featureValue": "8" 96 | }, 97 | { 98 | "featureName": "perf_remote_crypto_client", 99 | "featureValue": "enabled" 100 | }, 101 | { 102 | "featureName": "mod_ltm", 103 | "featureValue": "enabled" 104 | }, 105 | { 106 | "featureName": "mod_ilx", 107 | "featureValue": "enabled" 108 | }, 109 | { 110 | "featureName": "ltm_network_virtualization", 111 | "featureValue": "enabled" 112 | }, 113 | { 114 | "featureName": "perf_SSL_total_TPS", 115 | "featureValue": "UNLIMITED" 116 | }, 117 | { 118 | "featureName": "perf_SSL_per_core", 119 | "featureValue": "enabled" 120 | }, 121 | { 122 | "featureName": "perf_SSL_cmp", 123 | "featureValue": "enabled" 124 | }, 125 | { 126 | "featureName": "perf_http_compression_Mbps", 127 | "featureValue": "UNLIMITED" 128 | }, 129 | { 130 | "featureName": "nw_routing_rip", 131 | "featureValue": "enabled" 132 | }, 133 | { 134 | "featureName": "nw_routing_ospf", 135 | "featureValue": "enabled" 136 | }, 137 | { 138 | "featureName": "nw_routing_isis", 139 | "featureValue": "enabled" 140 | }, 141 | { 142 | "featureName": "nw_routing_bgp", 143 | "featureValue": "enabled" 144 | }, 145 | { 146 | "featureName": "nw_routing_bfd", 147 | "featureValue": "enabled" 148 | }, 149 | { 150 | "featureName": "mod_apml", 151 | "featureValue": "enabled" 152 | }, 153 | { 154 | "featureName": "ltm_bandw_rate_tosque", 155 | "featureValue": "enabled" 156 | }, 157 | { 158 | "featureName": "ltm_bandw_rate_fairque", 159 | "featureValue": "enabled" 160 | }, 161 | { 162 | "featureName": "ltm_bandw_rate_classl7", 163 | "featureValue": "enabled" 164 | }, 165 | { 166 | "featureName": "ltm_bandw_rate_classl4", 167 | "featureValue": "enabled" 168 | }, 169 | { 170 | "featureName": "ltm_bandw_rate_classes", 171 | "featureValue": "enabled" 172 | }, 173 | { 174 | "featureName": "Deny_version", 175 | "featureValue": "10.*.*" 176 | }, 177 | { 178 | "featureName": "Deny_version", 179 | "featureValue": "11.0.*" 180 | }, 181 | { 182 | "featureName": "Deny_version", 183 | "featureValue": "11.1.*" 184 | }, 185 | { 186 | "featureName": "Deny_version", 187 | "featureValue": "11.2.*" 188 | }, 189 | { 190 | "featureName": "Deny_version", 191 | "featureValue": "11.3.*" 192 | }, 193 | { 194 | "featureName": "Deny_version", 195 | "featureValue": "11.4.*" 196 | }, 197 | { 198 | "featureName": "Deny_version", 199 | "featureValue": "11.5.*" 200 | }, 201 | { 202 | "featureName": "Deny_version", 203 | "featureValue": "9.*.*" 204 | }, 205 | { 206 | "featureName": "apm_web_applications", 207 | "featureValue": "enabled" 208 | }, 209 | { 210 | "featureName": "apm_remote_desktop", 211 | "featureValue": "enabled" 212 | }, 213 | { 214 | "featureName": "apm_na", 215 | "featureValue": "enabled" 216 | }, 217 | { 218 | "featureName": "apm_ep_svk", 219 | "featureValue": "enabled" 220 | }, 221 | { 222 | "featureName": "apm_ep_pws", 223 | "featureValue": "enabled" 224 | }, 225 | { 226 | "featureName": "apm_ep_machinecert", 227 | "featureValue": "enabled" 228 | }, 229 | { 230 | "featureName": "apm_ep_fwcheck", 231 | "featureValue": "enabled" 232 | }, 233 | { 234 | "featureName": "apm_ep_avcheck", 235 | "featureValue": "enabled" 236 | }, 237 | { 238 | "featureName": "apm_ep", 239 | "featureValue": "enabled" 240 | }, 241 | { 242 | "featureName": "apm_app_tunnel", 243 | "featureValue": "enabled" 244 | }, 245 | { 246 | "featureName": "gtm_lc", 247 | "featureValue": "disabled" 248 | } 249 | ], 250 | "expiresInDays": "30.5", 251 | "expiresInDaysMessage": "License expires in 30 days, 11 hours." 252 | }` 253 | 254 | type SharedTestSuite struct { 255 | suite.Suite 256 | Client *BigIP 257 | Server *httptest.Server 258 | LastRequest *http.Request 259 | LastRequestBody string 260 | ResponseFunc func(http.ResponseWriter, *http.Request) 261 | } 262 | 263 | func (s *SharedTestSuite) requireReserializesTo(expected string, actual interface{}, message string) { 264 | b, err := json.Marshal(actual) 265 | s.Require().Nil(err, message) 266 | 267 | s.Require().JSONEq(expected, string(b), message) 268 | } 269 | 270 | func (s *SharedTestSuite) SetupSuite() { 271 | s.Server = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 272 | body, _ := ioutil.ReadAll(r.Body) 273 | s.LastRequestBody = string(body) 274 | s.LastRequest = r 275 | if s.ResponseFunc != nil { 276 | s.ResponseFunc(w, r) 277 | } 278 | })) 279 | 280 | s.Client = NewSession(s.Server.URL, "", "", nil) 281 | } 282 | 283 | func (s *SharedTestSuite) TearDownSuite() { 284 | s.Server.Close() 285 | } 286 | 287 | func (s *SharedTestSuite) SetupTest() { 288 | s.ResponseFunc = nil 289 | s.LastRequest = nil 290 | } 291 | 292 | func TestSharedSuite(t *testing.T) { 293 | suite.Run(t, new(SharedTestSuite)) 294 | } 295 | 296 | func (s *SharedTestSuite) TestGetLicenseState() { 297 | s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) { 298 | w.Write([]byte(validLicenseState)) 299 | } 300 | 301 | license, err := s.Client.GetLicenseState() 302 | 303 | s.Require().Nil(err, "Error getting license state") 304 | s.Require().NotNil(license, "License should not be nil") 305 | 306 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriRegistration), s.LastRequest.URL.Path, "Wrong uri to fetch license") 307 | s.Require().Equal("reg key here", license.RegistrationKey) 308 | s.requireReserializesTo(validLicenseState, license, "License should reserialize to itself") 309 | } 310 | 311 | func (s *SharedTestSuite) TestInstallLicense() { 312 | err := s.Client.InstallLicense("this is a new license\nline 2") 313 | 314 | s.Require().Nil(err, "Error installing license") 315 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriRegistration), s.LastRequest.URL.Path, "Wrong uri to install license") 316 | s.Require().Equal("PUT", s.LastRequest.Method, "Wrong method to install license") 317 | s.Require().JSONEq(`{"licenseText": "this is a new license\nline 2"}`, s.LastRequestBody) 318 | } 319 | 320 | func (s *SharedTestSuite) TestActivateTimeout() { 321 | err := s.Client.AutoLicense("reg key", nil, 0) 322 | s.Require().Error(err) 323 | s.Require().Equal("Timed out after 0s", err.Error(), "Should timeout") 324 | } 325 | 326 | func (s *SharedTestSuite) TestActivateNoEula() { 327 | counter := 0 328 | s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) { 329 | counter += 1 330 | switch counter { 331 | case 1: 332 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriActivation), r.URL.Path, "Wrong uri to activate") 333 | s.Require().Equal("POST", r.Method, "Wrong method to activate license") 334 | w.Write([]byte(`{}`)) 335 | case 2: 336 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriActivation), r.URL.Path, "Wrong uri to activate") 337 | w.Write([]byte(`{"status": "LICENSING_COMPLETE", "licenseText": "this is a new license\nline 2"}`)) 338 | case 3: 339 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriRegistration), r.URL.Path, "Wrong uri to install license") 340 | w.Write([]byte(`{}`)) 341 | default: 342 | w.WriteHeader(http.StatusInternalServerError) 343 | w.Write([]byte(`{"error": "Ran past number of expected requests"}`)) 344 | } 345 | } 346 | 347 | err := s.Client.AutoLicense("reg key", nil, 10*time.Second) 348 | s.Require().Nil(err, "Error auto activating license") 349 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriRegistration), s.LastRequest.URL.Path, "Wrong uri to install license") 350 | s.Require().Equal("PUT", s.LastRequest.Method, "Wrong method to install license") 351 | s.Require().JSONEq(`{"licenseText": "this is a new license\nline 2"}`, s.LastRequestBody) 352 | } 353 | 354 | func (s *SharedTestSuite) TestActivateEula() { 355 | counter := 0 356 | s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) { 357 | counter += 1 358 | switch counter { 359 | case 1: 360 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriActivation), r.URL.Path, "Wrong uri to activate") 361 | s.Require().Equal("POST", r.Method, "Wrong method to activate license") 362 | w.Write([]byte(`{}`)) 363 | case 2: 364 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriActivation), r.URL.Path, "Wrong uri to activate") 365 | w.Write([]byte(`{"status": "NEED_EULA_ACCEPT", "eulaText": "eula to accept"}`)) 366 | case 3: 367 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriActivation), r.URL.Path, "Wrong uri to activate") 368 | s.Require().Equal("POST", r.Method, "Wrong method to install license") 369 | s.Require().JSONEq(`{"baseRegKey": "reg key", "eulaText": "eula to accept", "isAutomaticActivation": true}`, s.LastRequestBody) 370 | w.Write([]byte(`{}`)) 371 | case 4: 372 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriActivation), r.URL.Path, "Wrong uri to activate") 373 | w.Write([]byte(`{"status": "LICENSING_COMPLETE", "licenseText": "this is a new license\nline 2"}`)) 374 | case 5: 375 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriRegistration), r.URL.Path, "Wrong uri to install license") 376 | w.Write([]byte(`{}`)) 377 | default: 378 | w.WriteHeader(http.StatusInternalServerError) 379 | w.Write([]byte(`{"error": "Ran past number of expected requests"}`)) 380 | } 381 | } 382 | 383 | err := s.Client.AutoLicense("reg key", nil, 10*time.Second) 384 | s.Require().Nil(err, "Error auto activating license") 385 | s.Require().Equal(fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriShared, uriLicensing, uriRegistration), s.LastRequest.URL.Path, "Wrong uri to install license") 386 | s.Require().Equal("PUT", s.LastRequest.Method, "Wrong method to install license") 387 | s.Require().JSONEq(`{"licenseText": "this is a new license\nline 2"}`, s.LastRequestBody) 388 | } 389 | 390 | func (s *SharedTestSuite) TestUploadFile() { 391 | tmp, err := ioutil.TempFile("", "test") 392 | defer os.Remove(tmp.Name()) 393 | content := []byte("test file content") 394 | size := len(content) 395 | tmp.Write(content) 396 | tmp.Close() 397 | f, _ := os.Open(tmp.Name()) 398 | filename := path.Base(tmp.Name()) 399 | 400 | s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) { 401 | w.Write([]byte(`{}`)) 402 | } 403 | 404 | upload, err := s.Client.UploadFile(f) 405 | s.Require().Nil(err, "Error uploading file") 406 | s.Require().NotNil(upload, "Upload response should not be nil") 407 | s.Require().Equal("application/octet-stream", s.LastRequest.Header.Get("Content-Type"), "Wrong Content-Type header") 408 | s.Require().Equal(fmt.Sprintf("0-%d/%d", size-1, size), s.LastRequest.Header.Get("Content-Range"), "Wrong Content-Range header") 409 | s.Require().Equal(fmt.Sprintf("/mgmt/shared/file-transfer/uploads/%s", filename), s.LastRequest.URL.Path, "Wrong uri to upload file") 410 | } 411 | 412 | func (s *SharedTestSuite) TestUploadBytes() { 413 | b := []byte("test byte content") 414 | size := len(b) 415 | filename := "test.txt" 416 | 417 | s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) { 418 | w.Write([]byte(`{}`)) 419 | } 420 | 421 | upload, err := s.Client.UploadBytes(b, filename) 422 | s.Require().Nil(err, "Error uploading file") 423 | s.Require().NotNil(upload, "Upload response should not be nil") 424 | s.Require().Equal("application/octet-stream", s.LastRequest.Header.Get("Content-Type"), "Wrong Content-Type header") 425 | s.Require().Equal(fmt.Sprintf("0-%d/%d", size-1, size), s.LastRequest.Header.Get("Content-Range"), "Wrong Content-Range header") 426 | s.Require().Equal(fmt.Sprintf("/mgmt/shared/file-transfer/uploads/%s", filename), s.LastRequest.URL.Path, "Wrong uri to upload file") 427 | } 428 | -------------------------------------------------------------------------------- /sys.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "encoding/json" 5 | "strings" 6 | ) 7 | 8 | const ( 9 | uriSys = "sys" 10 | uriFolder = "folder" 11 | uriSyslog = "syslog" 12 | uriSoftware = "software" 13 | uriVolume = "volume" 14 | uriHardware = "hardware" 15 | uriGlobalSettings = "global-settings" 16 | uriManagementIp = "management-ip" 17 | uriFile = "file" 18 | uriSslCert = "ssl-cert" 19 | uriSslKey = "ssl-key" 20 | //uriPlatform = "?$select=platform" 21 | uriConfig = "config" 22 | ) 23 | 24 | type Volumes struct { 25 | Volumes []Volume `json:"items,omitempty"` 26 | } 27 | 28 | type Volume struct { 29 | Name string `json:"items,omitempty"` 30 | FullPath string `json:"fullPath,omitempty"` 31 | Generation int `json:"generation,omitempty"` 32 | SelfLink string `json:"selfLink,omitempty"` 33 | Active bool `json:"active,omitempty"` 34 | BaseBuild string `json:"basebuild,omitempty"` 35 | Build string `json:"build,omitempty"` 36 | Product string `json:"product,omitempty"` 37 | Status string `json:"status,omitempty"` 38 | Version string `json:"version,omitempty"` 39 | } 40 | 41 | // Volumes returns a list of Software Volumes. 42 | func (b *BigIP) Volumes() (*Volumes, error) { 43 | var volumes Volumes 44 | err, _ := b.getForEntity(&volumes, uriSys, uriSoftware, uriVolume) 45 | if err != nil { 46 | return nil, err 47 | } 48 | 49 | return &volumes, nil 50 | } 51 | 52 | type ManagementIP struct { 53 | Addresses []ManagementIPAddress 54 | } 55 | 56 | type ManagementIPAddress struct { 57 | Name string `json:"items,omitempty"` 58 | FullPath string `json:"fullPath,omitempty"` 59 | Generation int `json:"generation,omitempty"` 60 | SelfLink string `json:"selfLink,omitempty"` 61 | } 62 | 63 | func (b *BigIP) ManagementIPs() (*ManagementIP, error) { 64 | var managementIP ManagementIP 65 | err, _ := b.getForEntity(&managementIP, uriSys, uriManagementIp) 66 | if err != nil { 67 | return nil, err 68 | } 69 | 70 | return &managementIP, nil 71 | } 72 | 73 | type SyslogRemoteServer struct { 74 | Name string `json:"name,omitempty"` 75 | Host string `json:"host,omitempty"` 76 | LocalIP string `json:"localIp,omitempty"` 77 | RemotePort int `json:"remotePort,omitempty"` 78 | } 79 | 80 | type Syslog struct { 81 | SelfLink string `json:"selfLink,omitempty"` 82 | RemoteServers []SyslogRemoteServer `json:"remoteServers,omitempty"` 83 | } 84 | 85 | func (b *BigIP) Syslog() (*Syslog, error) { 86 | var syslog Syslog 87 | 88 | err, _ := b.getForEntity(&syslog, uriSys, uriSyslog) 89 | if err != nil { 90 | return nil, err 91 | } 92 | 93 | return &syslog, nil 94 | } 95 | 96 | func (b *BigIP) SetSyslog(config Syslog) error { 97 | return b.put(config, uriSys, uriSyslog) 98 | } 99 | 100 | // Folders contains a list of every folder on the BIG-IP system. 101 | type Folders struct { 102 | Folders []Folder `json:"items"` 103 | } 104 | 105 | type folderDTO struct { 106 | Name string `json:"name,omitempty"` 107 | Partition string `json:"partition,omitempty"` 108 | SubPath string `json:"subPath,omitempty"` 109 | FullPath string `json:"fullPath,omitempty"` 110 | 111 | AppService string `json:"appService,omitempty"` 112 | Description string `json:"description,omitempty"` 113 | // Set to "default" to inherit or a device group name to control. You can also set it to "non-default" to pin its device group to its current setting and turn off inheritance. 114 | DeviceGroup string `json:"deviceGroup,omitempty"` 115 | Hidden string `json:"hidden,omitempty" bool:"true"` 116 | NoRefCheck string `json:"noRefCheck,omitempty" bool:"true"` 117 | // Set to "default" to inherit or a traffic group name to control. You can also set it to "non-default" to pin its traffic group to its current setting and turn off inheritance. 118 | TrafficGroup string `json:"trafficGroup,omitempty"` 119 | 120 | // Read-only property. Set DeviceGroup to control. 121 | InheritedDeviceGroup string `json:"inheritedDevicegroup,omitempty" bool:"true"` 122 | 123 | // Read-only property. Set TrafficGroup to control. 124 | InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty" bool:"true"` 125 | } 126 | 127 | type Folder struct { 128 | Name string `json:"name,omitempty"` 129 | Partition string `json:"partition,omitempty"` 130 | SubPath string `json:"subPath,omitempty"` 131 | FullPath string `json:"fullPath,omitempty"` 132 | 133 | AppService string `json:"appService,omitempty"` 134 | Description string `json:"description,omitempty"` 135 | DeviceGroup string `json:"deviceGroup,omitempty"` 136 | Hidden *bool `json:"hidden,omitempty"` 137 | NoRefCheck *bool `json:"noRefCheck,omitempty"` 138 | TrafficGroup string `json:"trafficGroup,omitempty"` 139 | 140 | // Read-only property. Set DeviceGroup to "default" or "non-default" to control. 141 | InheritedDeviceGroup *bool `json:"inheritedDevicegroup,omitempty"` 142 | 143 | // Read-only property. Set TrafficGroup to "default" or "non-default" to control. 144 | InheritedTrafficGroup *bool `json:"inheritedTrafficGroup,omitempty"` 145 | } 146 | 147 | func (f *Folder) MarshalJSON() ([]byte, error) { 148 | var dto folderDTO 149 | marshal(&dto, f) 150 | return json.Marshal(dto) 151 | } 152 | 153 | func (f *Folder) UnmarshalJSON(b []byte) error { 154 | var dto folderDTO 155 | err := json.Unmarshal(b, &dto) 156 | if err != nil { 157 | return err 158 | } 159 | return marshal(f, &dto) 160 | } 161 | 162 | // Folders returns a list of folders. 163 | func (b *BigIP) Folders() (*Folders, error) { 164 | var folders Folders 165 | err, _ := b.getForEntity(&folders, uriSys, uriFolder) 166 | if err != nil { 167 | return nil, err 168 | } 169 | 170 | return &folders, nil 171 | } 172 | 173 | // CreateFolder adds a new folder to the BIG-IP system. 174 | func (b *BigIP) CreateFolder(name string) error { 175 | config := &Folder{ 176 | Name: name, 177 | } 178 | 179 | return b.post(config, uriSys, uriFolder) 180 | } 181 | 182 | // AddFolder adds a new folder by config to the BIG-IP system. 183 | func (b *BigIP) AddFolder(config *Folder) error { 184 | 185 | return b.post(config, uriSys, uriFolder) 186 | } 187 | 188 | // GetFolder retrieves a Folder by name. Returns nil if the folder does not exist 189 | func (b *BigIP) GetFolder(name string) (*Folder, error) { 190 | var folder Folder 191 | err, ok := b.getForEntity(&folder, uriSys, uriFolder, name) 192 | if err != nil { 193 | return nil, err 194 | } 195 | if !ok { 196 | return nil, nil 197 | } 198 | 199 | return &folder, nil 200 | } 201 | 202 | // DeleteFolder removes a folder. 203 | func (b *BigIP) DeleteFolder(name string) error { 204 | return b.delete(uriSys, uriFolder, name) 205 | } 206 | 207 | // ModifyFolder allows you to change any attribute of a folder. Fields that can 208 | // be modified are referenced in the Folder struct. This replaces the existing 209 | // configuration, so use PatchFolder if you want to change only particular 210 | // attributes. 211 | func (b *BigIP) ModifyFolder(name string, config *Folder) error { 212 | return b.put(config, uriSys, uriFolder, name) 213 | } 214 | 215 | // PatchFolder allows you to change any attribute of a folder. Fields that can 216 | // be modified are referenced in the Folder struct. This changes only the 217 | // attributes provided, so use ModifyFolder if you want to replace the existing 218 | // configuration. 219 | func (b *BigIP) PatchFolder(name string, config *Folder) error { 220 | return b.patch(config, uriSys, uriFolder, name) 221 | } 222 | 223 | // Certificates represents a list of installed SSL certificates. 224 | type Certificates struct { 225 | Certificates []Certificate `json:"items,omitempty"` 226 | } 227 | 228 | // Certificate represents an SSL Certificate. 229 | type Certificate struct { 230 | AppService string `json:"appService,omitempty"` 231 | CachePath string `json:"cachePath,omitempty"` 232 | CertificateKeyCurveName string `json:"certificateKeyCurveName,omitempty"` 233 | CertificateKeySize int `json:"certificateKeySize,omitempty"` 234 | CertValidationOptions string `json:"certValidationOptions,omitempty"` 235 | Checksum string `json:"checksum,omitempty"` 236 | CreatedBy string `json:"createdBy,omitempty"` 237 | CreateTime string `json:"createTime,omitempty"` 238 | Email string `json:"email,omitempty"` 239 | ExpirationDate int `json:"expirationDate,omitempty"` 240 | ExpirationString string `json:"expirationString,omitempty"` 241 | Fingerprint string `json:"fingerprint,omitempty"` 242 | FullPath string `json:"fullPath,omitempty"` 243 | Generation int `json:"generation,omitempty"` 244 | IsBundle string `json:"isBundle,omitempty"` 245 | IsDynamic string `json:"isDynamic,omitempty"` 246 | Issuer string `json:"issuer,omitempty"` 247 | IssuerCert string `json:"issuerCert,omitempty"` 248 | KeyType string `json:"keyType,omitempty"` 249 | LastUpdateTime string `json:"lastUpdateTime,omitempty"` 250 | Mode int `json:"mode,omitempty"` 251 | Name string `json:"name,omitempty"` 252 | Partition string `json:"partition,omitempty"` 253 | Revision int `json:"revision,omitempty"` 254 | SerialNumber string `json:"serialNumber,omitempty"` 255 | Size uint64 `json:"size,omitempty"` 256 | SourcePath string `json:"sourcePath,omitempty"` 257 | Subject string `json:"subject,omitempty"` 258 | SubjectAlternativeName string `json:"subjectAlternativeName,omitempty"` 259 | SystemPath string `json:"systemPath,omitempty"` 260 | UpdatedBy string `json:"updatedBy,omitempty"` 261 | Version int `json:"version,omitempty"` 262 | } 263 | 264 | // Certificates returns a list of certificates. 265 | func (b *BigIP) Certificates() (*Certificates, error) { 266 | var certs Certificates 267 | err, _ := b.getForEntity(&certs, uriSys, uriFile, uriSslCert) 268 | if err != nil { 269 | return nil, err 270 | } 271 | 272 | return &certs, nil 273 | } 274 | 275 | // AddCertificate installs a certificate. 276 | func (b *BigIP) AddCertificate(cert *Certificate) error { 277 | return b.post(cert, uriSys, uriFile, uriSslCert) 278 | } 279 | 280 | // GetCertificate retrieves a Certificate by name. Returns nil if the certificate does not exist 281 | func (b *BigIP) GetCertificate(name string) (*Certificate, error) { 282 | var cert Certificate 283 | err, ok := b.getForEntity(&cert, uriSys, uriFile, uriSslCert, name) 284 | if err != nil { 285 | return nil, err 286 | } 287 | if !ok { 288 | return nil, nil 289 | } 290 | 291 | return &cert, nil 292 | } 293 | 294 | // DeleteCertificate removes a certificate. 295 | func (b *BigIP) DeleteCertificate(name string) error { 296 | return b.delete(uriSys, uriFile, uriSslCert, name) 297 | } 298 | 299 | // Keys represents a list of installed keys. 300 | type Keys struct { 301 | Keys []Key `json:"items,omitempty"` 302 | } 303 | 304 | // Key represents a private key associated with a certificate. 305 | type Key struct { 306 | AppService string `json:"appService,omitempty"` 307 | CachePath string `json:"cachePath,omitempty"` 308 | Checksum string `json:"checksum,omitempty"` 309 | CreatedBy string `json:"createdBy,omitempty"` 310 | CreateTime string `json:"createTime,omitempty"` 311 | CurveName string `json:"curveName,omitempty"` 312 | FullPath string `json:"fullPath,omitempty"` 313 | Generation int `json:"generation,omitempty"` 314 | IsDynamic string `json:"isDynamic,omitempty"` 315 | KeySize int `json:"keySize,omitempty"` 316 | KeyType string `json:"keyType,omitempty"` 317 | LastUpdateTime string `json:"lastUpdateTime,omitempty"` 318 | Mode int `json:"mode,omitempty"` 319 | Name string `json:"name,omitempty"` 320 | Partition string `json:"partition,omitempty"` 321 | Passphrase string `json:"passphrase,omitempty"` 322 | Revision int `json:"revision,omitempty"` 323 | SecurityType string `json:"securityType,omitempty"` 324 | Size uint64 `json:"size,omitempty"` 325 | SourcePath string `json:"sourcePath,omitempty"` 326 | SystemPath string `json:"systemPath,omitempty"` 327 | UpdatedBy string `json:"updatedBy,omitempty"` 328 | } 329 | 330 | // Keys returns a list of keys. 331 | func (b *BigIP) Keys() (*Keys, error) { 332 | var keys Keys 333 | err, _ := b.getForEntity(&keys, uriSys, uriFile, uriSslKey) 334 | if err != nil { 335 | return nil, err 336 | } 337 | 338 | return &keys, nil 339 | } 340 | 341 | // AddKey installs a key. 342 | func (b *BigIP) AddKey(config *Key) error { 343 | return b.post(config, uriSys, uriFile, uriSslKey) 344 | } 345 | 346 | // GetKey retrieves a key by name. Returns nil if the key does not exist. 347 | func (b *BigIP) GetKey(name string) (*Key, error) { 348 | var key Key 349 | err, ok := b.getForEntity(&key, uriSys, uriFile, uriSslKey, name) 350 | if err != nil { 351 | return nil, err 352 | } 353 | if !ok { 354 | return nil, nil 355 | } 356 | 357 | return &key, nil 358 | } 359 | 360 | // DeleteKey removes a key. 361 | func (b *BigIP) DeleteKey(name string) error { 362 | return b.delete(uriSys, uriFile, uriSslKey, name) 363 | } 364 | 365 | type SysConfig struct { 366 | Command string `json:"command"` 367 | Options []map[string]interface{} `json:"options, omitempty"` 368 | } 369 | 370 | //SaveSysConfig saves the running configuration to file. The file can be either an .scf file or a .tar file 371 | func (b *BigIP) SaveSysConfig(fileName, passphrase string) error { 372 | options := buildSysConfigOptions(fileName, passphrase) 373 | config := &SysConfig{ 374 | Command: "save", 375 | Options: options, 376 | } 377 | return b.post(config, uriSys, uriConfig) 378 | } 379 | 380 | //LoadSysConfig loads system configuration from a file. The file can be either an .scf file or a .tar file 381 | func (b *BigIP) LoadSysConfig(fileName, passphrase string) error { 382 | options := buildSysConfigOptions(fileName, passphrase) 383 | config := &SysConfig{ 384 | Command: "load", 385 | Options: options, 386 | } 387 | return b.post(config, uriSys, uriConfig) 388 | } 389 | 390 | func buildSysConfigOptions(fileName string, passphrase string) []map[string]interface{} { 391 | options := make([]map[string]interface{}, 0, 0) 392 | if fileName != "" { 393 | if strings.HasSuffix(fileName, ".tar") { 394 | options = append(options, map[string]interface{}{"tar-file": fileName}) 395 | } else { 396 | options = append(options, map[string]interface{}{"file": fileName}) 397 | } 398 | if passphrase != "" { //passphrase is needed only when file is present 399 | options = append(options, map[string]interface{}{"passphrase": passphrase}) 400 | } else { 401 | options = append(options, map[string]interface{}{"no-passphrase": ""}) 402 | } 403 | } 404 | return options 405 | } 406 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypass.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is not running on Google App Engine, compiled by GopherJS, and 17 | // "-tags safe" is not added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // Go versions prior to 1.4 are disabled because they use a different layout 20 | // for interfaces which make the implementation of unsafeReflectValue more complex. 21 | // +build !js,!appengine,!safe,!disableunsafe,go1.4 22 | 23 | package spew 24 | 25 | import ( 26 | "reflect" 27 | "unsafe" 28 | ) 29 | 30 | const ( 31 | // UnsafeDisabled is a build-time constant which specifies whether or 32 | // not access to the unsafe package is available. 33 | UnsafeDisabled = false 34 | 35 | // ptrSize is the size of a pointer on the current arch. 36 | ptrSize = unsafe.Sizeof((*byte)(nil)) 37 | ) 38 | 39 | type flag uintptr 40 | 41 | var ( 42 | // flagRO indicates whether the value field of a reflect.Value 43 | // is read-only. 44 | flagRO flag 45 | 46 | // flagAddr indicates whether the address of the reflect.Value's 47 | // value may be taken. 48 | flagAddr flag 49 | ) 50 | 51 | // flagKindMask holds the bits that make up the kind 52 | // part of the flags field. In all the supported versions, 53 | // it is in the lower 5 bits. 54 | const flagKindMask = flag(0x1f) 55 | 56 | // Different versions of Go have used different 57 | // bit layouts for the flags type. This table 58 | // records the known combinations. 59 | var okFlags = []struct { 60 | ro, addr flag 61 | }{{ 62 | // From Go 1.4 to 1.5 63 | ro: 1 << 5, 64 | addr: 1 << 7, 65 | }, { 66 | // Up to Go tip. 67 | ro: 1<<5 | 1<<6, 68 | addr: 1 << 8, 69 | }} 70 | 71 | var flagValOffset = func() uintptr { 72 | field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") 73 | if !ok { 74 | panic("reflect.Value has no flag field") 75 | } 76 | return field.Offset 77 | }() 78 | 79 | // flagField returns a pointer to the flag field of a reflect.Value. 80 | func flagField(v *reflect.Value) *flag { 81 | return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) 82 | } 83 | 84 | // unsafeReflectValue converts the passed reflect.Value into a one that bypasses 85 | // the typical safety restrictions preventing access to unaddressable and 86 | // unexported data. It works by digging the raw pointer to the underlying 87 | // value out of the protected value and generating a new unprotected (unsafe) 88 | // reflect.Value to it. 89 | // 90 | // This allows us to check for implementations of the Stringer and error 91 | // interfaces to be used for pretty printing ordinarily unaddressable and 92 | // inaccessible values such as unexported struct fields. 93 | func unsafeReflectValue(v reflect.Value) reflect.Value { 94 | if !v.IsValid() || (v.CanInterface() && v.CanAddr()) { 95 | return v 96 | } 97 | flagFieldPtr := flagField(&v) 98 | *flagFieldPtr &^= flagRO 99 | *flagFieldPtr |= flagAddr 100 | return v 101 | } 102 | 103 | // Sanity checks against future reflect package changes 104 | // to the type or semantics of the Value.flag field. 105 | func init() { 106 | field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") 107 | if !ok { 108 | panic("reflect.Value has no flag field") 109 | } 110 | if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { 111 | panic("reflect.Value flag field has changed kind") 112 | } 113 | type t0 int 114 | var t struct { 115 | A t0 116 | // t0 will have flagEmbedRO set. 117 | t0 118 | // a will have flagStickyRO set 119 | a t0 120 | } 121 | vA := reflect.ValueOf(t).FieldByName("A") 122 | va := reflect.ValueOf(t).FieldByName("a") 123 | vt0 := reflect.ValueOf(t).FieldByName("t0") 124 | 125 | // Infer flagRO from the difference between the flags 126 | // for the (otherwise identical) fields in t. 127 | flagPublic := *flagField(&vA) 128 | flagWithRO := *flagField(&va) | *flagField(&vt0) 129 | flagRO = flagPublic ^ flagWithRO 130 | 131 | // Infer flagAddr from the difference between a value 132 | // taken from a pointer and not. 133 | vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") 134 | flagNoPtr := *flagField(&vA) 135 | flagPtr := *flagField(&vPtrA) 136 | flagAddr = flagNoPtr ^ flagPtr 137 | 138 | // Check that the inferred flags tally with one of the known versions. 139 | for _, f := range okFlags { 140 | if flagRO == f.ro && flagAddr == f.addr { 141 | return 142 | } 143 | } 144 | panic("reflect.Value read-only flag has changed semantics") 145 | } 146 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe !go1.4 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Dave Collins 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | package spew 18 | 19 | import ( 20 | "bytes" 21 | "fmt" 22 | "io" 23 | "reflect" 24 | "sort" 25 | "strconv" 26 | ) 27 | 28 | // Some constants in the form of bytes to avoid string overhead. This mirrors 29 | // the technique used in the fmt package. 30 | var ( 31 | panicBytes = []byte("(PANIC=") 32 | plusBytes = []byte("+") 33 | iBytes = []byte("i") 34 | trueBytes = []byte("true") 35 | falseBytes = []byte("false") 36 | interfaceBytes = []byte("(interface {})") 37 | commaNewlineBytes = []byte(",\n") 38 | newlineBytes = []byte("\n") 39 | openBraceBytes = []byte("{") 40 | openBraceNewlineBytes = []byte("{\n") 41 | closeBraceBytes = []byte("}") 42 | asteriskBytes = []byte("*") 43 | colonBytes = []byte(":") 44 | colonSpaceBytes = []byte(": ") 45 | openParenBytes = []byte("(") 46 | closeParenBytes = []byte(")") 47 | spaceBytes = []byte(" ") 48 | pointerChainBytes = []byte("->") 49 | nilAngleBytes = []byte("") 50 | maxNewlineBytes = []byte("\n") 51 | maxShortBytes = []byte("") 52 | circularBytes = []byte("") 53 | circularShortBytes = []byte("") 54 | invalidAngleBytes = []byte("") 55 | openBracketBytes = []byte("[") 56 | closeBracketBytes = []byte("]") 57 | percentBytes = []byte("%") 58 | precisionBytes = []byte(".") 59 | openAngleBytes = []byte("<") 60 | closeAngleBytes = []byte(">") 61 | openMapBytes = []byte("map[") 62 | closeMapBytes = []byte("]") 63 | lenEqualsBytes = []byte("len=") 64 | capEqualsBytes = []byte("cap=") 65 | ) 66 | 67 | // hexDigits is used to map a decimal value to a hex digit. 68 | var hexDigits = "0123456789abcdef" 69 | 70 | // catchPanic handles any panics that might occur during the handleMethods 71 | // calls. 72 | func catchPanic(w io.Writer, v reflect.Value) { 73 | if err := recover(); err != nil { 74 | w.Write(panicBytes) 75 | fmt.Fprintf(w, "%v", err) 76 | w.Write(closeParenBytes) 77 | } 78 | } 79 | 80 | // handleMethods attempts to call the Error and String methods on the underlying 81 | // type the passed reflect.Value represents and outputes the result to Writer w. 82 | // 83 | // It handles panics in any called methods by catching and displaying the error 84 | // as the formatted value. 85 | func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) { 86 | // We need an interface to check if the type implements the error or 87 | // Stringer interface. However, the reflect package won't give us an 88 | // interface on certain things like unexported struct fields in order 89 | // to enforce visibility rules. We use unsafe, when it's available, 90 | // to bypass these restrictions since this package does not mutate the 91 | // values. 92 | if !v.CanInterface() { 93 | if UnsafeDisabled { 94 | return false 95 | } 96 | 97 | v = unsafeReflectValue(v) 98 | } 99 | 100 | // Choose whether or not to do error and Stringer interface lookups against 101 | // the base type or a pointer to the base type depending on settings. 102 | // Technically calling one of these methods with a pointer receiver can 103 | // mutate the value, however, types which choose to satisify an error or 104 | // Stringer interface with a pointer receiver should not be mutating their 105 | // state inside these interface methods. 106 | if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() { 107 | v = unsafeReflectValue(v) 108 | } 109 | if v.CanAddr() { 110 | v = v.Addr() 111 | } 112 | 113 | // Is it an error or Stringer? 114 | switch iface := v.Interface().(type) { 115 | case error: 116 | defer catchPanic(w, v) 117 | if cs.ContinueOnMethod { 118 | w.Write(openParenBytes) 119 | w.Write([]byte(iface.Error())) 120 | w.Write(closeParenBytes) 121 | w.Write(spaceBytes) 122 | return false 123 | } 124 | 125 | w.Write([]byte(iface.Error())) 126 | return true 127 | 128 | case fmt.Stringer: 129 | defer catchPanic(w, v) 130 | if cs.ContinueOnMethod { 131 | w.Write(openParenBytes) 132 | w.Write([]byte(iface.String())) 133 | w.Write(closeParenBytes) 134 | w.Write(spaceBytes) 135 | return false 136 | } 137 | w.Write([]byte(iface.String())) 138 | return true 139 | } 140 | return false 141 | } 142 | 143 | // printBool outputs a boolean value as true or false to Writer w. 144 | func printBool(w io.Writer, val bool) { 145 | if val { 146 | w.Write(trueBytes) 147 | } else { 148 | w.Write(falseBytes) 149 | } 150 | } 151 | 152 | // printInt outputs a signed integer value to Writer w. 153 | func printInt(w io.Writer, val int64, base int) { 154 | w.Write([]byte(strconv.FormatInt(val, base))) 155 | } 156 | 157 | // printUint outputs an unsigned integer value to Writer w. 158 | func printUint(w io.Writer, val uint64, base int) { 159 | w.Write([]byte(strconv.FormatUint(val, base))) 160 | } 161 | 162 | // printFloat outputs a floating point value using the specified precision, 163 | // which is expected to be 32 or 64bit, to Writer w. 164 | func printFloat(w io.Writer, val float64, precision int) { 165 | w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision))) 166 | } 167 | 168 | // printComplex outputs a complex value using the specified float precision 169 | // for the real and imaginary parts to Writer w. 170 | func printComplex(w io.Writer, c complex128, floatPrecision int) { 171 | r := real(c) 172 | w.Write(openParenBytes) 173 | w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision))) 174 | i := imag(c) 175 | if i >= 0 { 176 | w.Write(plusBytes) 177 | } 178 | w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision))) 179 | w.Write(iBytes) 180 | w.Write(closeParenBytes) 181 | } 182 | 183 | // printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' 184 | // prefix to Writer w. 185 | func printHexPtr(w io.Writer, p uintptr) { 186 | // Null pointer. 187 | num := uint64(p) 188 | if num == 0 { 189 | w.Write(nilAngleBytes) 190 | return 191 | } 192 | 193 | // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix 194 | buf := make([]byte, 18) 195 | 196 | // It's simpler to construct the hex string right to left. 197 | base := uint64(16) 198 | i := len(buf) - 1 199 | for num >= base { 200 | buf[i] = hexDigits[num%base] 201 | num /= base 202 | i-- 203 | } 204 | buf[i] = hexDigits[num] 205 | 206 | // Add '0x' prefix. 207 | i-- 208 | buf[i] = 'x' 209 | i-- 210 | buf[i] = '0' 211 | 212 | // Strip unused leading bytes. 213 | buf = buf[i:] 214 | w.Write(buf) 215 | } 216 | 217 | // valuesSorter implements sort.Interface to allow a slice of reflect.Value 218 | // elements to be sorted. 219 | type valuesSorter struct { 220 | values []reflect.Value 221 | strings []string // either nil or same len and values 222 | cs *ConfigState 223 | } 224 | 225 | // newValuesSorter initializes a valuesSorter instance, which holds a set of 226 | // surrogate keys on which the data should be sorted. It uses flags in 227 | // ConfigState to decide if and how to populate those surrogate keys. 228 | func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface { 229 | vs := &valuesSorter{values: values, cs: cs} 230 | if canSortSimply(vs.values[0].Kind()) { 231 | return vs 232 | } 233 | if !cs.DisableMethods { 234 | vs.strings = make([]string, len(values)) 235 | for i := range vs.values { 236 | b := bytes.Buffer{} 237 | if !handleMethods(cs, &b, vs.values[i]) { 238 | vs.strings = nil 239 | break 240 | } 241 | vs.strings[i] = b.String() 242 | } 243 | } 244 | if vs.strings == nil && cs.SpewKeys { 245 | vs.strings = make([]string, len(values)) 246 | for i := range vs.values { 247 | vs.strings[i] = Sprintf("%#v", vs.values[i].Interface()) 248 | } 249 | } 250 | return vs 251 | } 252 | 253 | // canSortSimply tests whether a reflect.Kind is a primitive that can be sorted 254 | // directly, or whether it should be considered for sorting by surrogate keys 255 | // (if the ConfigState allows it). 256 | func canSortSimply(kind reflect.Kind) bool { 257 | // This switch parallels valueSortLess, except for the default case. 258 | switch kind { 259 | case reflect.Bool: 260 | return true 261 | case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: 262 | return true 263 | case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: 264 | return true 265 | case reflect.Float32, reflect.Float64: 266 | return true 267 | case reflect.String: 268 | return true 269 | case reflect.Uintptr: 270 | return true 271 | case reflect.Array: 272 | return true 273 | } 274 | return false 275 | } 276 | 277 | // Len returns the number of values in the slice. It is part of the 278 | // sort.Interface implementation. 279 | func (s *valuesSorter) Len() int { 280 | return len(s.values) 281 | } 282 | 283 | // Swap swaps the values at the passed indices. It is part of the 284 | // sort.Interface implementation. 285 | func (s *valuesSorter) Swap(i, j int) { 286 | s.values[i], s.values[j] = s.values[j], s.values[i] 287 | if s.strings != nil { 288 | s.strings[i], s.strings[j] = s.strings[j], s.strings[i] 289 | } 290 | } 291 | 292 | // valueSortLess returns whether the first value should sort before the second 293 | // value. It is used by valueSorter.Less as part of the sort.Interface 294 | // implementation. 295 | func valueSortLess(a, b reflect.Value) bool { 296 | switch a.Kind() { 297 | case reflect.Bool: 298 | return !a.Bool() && b.Bool() 299 | case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: 300 | return a.Int() < b.Int() 301 | case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: 302 | return a.Uint() < b.Uint() 303 | case reflect.Float32, reflect.Float64: 304 | return a.Float() < b.Float() 305 | case reflect.String: 306 | return a.String() < b.String() 307 | case reflect.Uintptr: 308 | return a.Uint() < b.Uint() 309 | case reflect.Array: 310 | // Compare the contents of both arrays. 311 | l := a.Len() 312 | for i := 0; i < l; i++ { 313 | av := a.Index(i) 314 | bv := b.Index(i) 315 | if av.Interface() == bv.Interface() { 316 | continue 317 | } 318 | return valueSortLess(av, bv) 319 | } 320 | } 321 | return a.String() < b.String() 322 | } 323 | 324 | // Less returns whether the value at index i should sort before the 325 | // value at index j. It is part of the sort.Interface implementation. 326 | func (s *valuesSorter) Less(i, j int) bool { 327 | if s.strings == nil { 328 | return valueSortLess(s.values[i], s.values[j]) 329 | } 330 | return s.strings[i] < s.strings[j] 331 | } 332 | 333 | // sortValues is a sort function that handles both native types and any type that 334 | // can be converted to error or Stringer. Other inputs are sorted according to 335 | // their Value.String() value to ensure display stability. 336 | func sortValues(values []reflect.Value, cs *ConfigState) { 337 | if len(values) == 0 { 338 | return 339 | } 340 | sort.Sort(newValuesSorter(values, cs)) 341 | } 342 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Dave Collins 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | package spew 18 | 19 | import ( 20 | "bytes" 21 | "fmt" 22 | "io" 23 | "os" 24 | ) 25 | 26 | // ConfigState houses the configuration options used by spew to format and 27 | // display values. There is a global instance, Config, that is used to control 28 | // all top-level Formatter and Dump functionality. Each ConfigState instance 29 | // provides methods equivalent to the top-level functions. 30 | // 31 | // The zero value for ConfigState provides no indentation. You would typically 32 | // want to set it to a space or a tab. 33 | // 34 | // Alternatively, you can use NewDefaultConfig to get a ConfigState instance 35 | // with default settings. See the documentation of NewDefaultConfig for default 36 | // values. 37 | type ConfigState struct { 38 | // Indent specifies the string to use for each indentation level. The 39 | // global config instance that all top-level functions use set this to a 40 | // single space by default. If you would like more indentation, you might 41 | // set this to a tab with "\t" or perhaps two spaces with " ". 42 | Indent string 43 | 44 | // MaxDepth controls the maximum number of levels to descend into nested 45 | // data structures. The default, 0, means there is no limit. 46 | // 47 | // NOTE: Circular data structures are properly detected, so it is not 48 | // necessary to set this value unless you specifically want to limit deeply 49 | // nested data structures. 50 | MaxDepth int 51 | 52 | // DisableMethods specifies whether or not error and Stringer interfaces are 53 | // invoked for types that implement them. 54 | DisableMethods bool 55 | 56 | // DisablePointerMethods specifies whether or not to check for and invoke 57 | // error and Stringer interfaces on types which only accept a pointer 58 | // receiver when the current type is not a pointer. 59 | // 60 | // NOTE: This might be an unsafe action since calling one of these methods 61 | // with a pointer receiver could technically mutate the value, however, 62 | // in practice, types which choose to satisify an error or Stringer 63 | // interface with a pointer receiver should not be mutating their state 64 | // inside these interface methods. As a result, this option relies on 65 | // access to the unsafe package, so it will not have any effect when 66 | // running in environments without access to the unsafe package such as 67 | // Google App Engine or with the "safe" build tag specified. 68 | DisablePointerMethods bool 69 | 70 | // DisablePointerAddresses specifies whether to disable the printing of 71 | // pointer addresses. This is useful when diffing data structures in tests. 72 | DisablePointerAddresses bool 73 | 74 | // DisableCapacities specifies whether to disable the printing of capacities 75 | // for arrays, slices, maps and channels. This is useful when diffing 76 | // data structures in tests. 77 | DisableCapacities bool 78 | 79 | // ContinueOnMethod specifies whether or not recursion should continue once 80 | // a custom error or Stringer interface is invoked. The default, false, 81 | // means it will print the results of invoking the custom error or Stringer 82 | // interface and return immediately instead of continuing to recurse into 83 | // the internals of the data type. 84 | // 85 | // NOTE: This flag does not have any effect if method invocation is disabled 86 | // via the DisableMethods or DisablePointerMethods options. 87 | ContinueOnMethod bool 88 | 89 | // SortKeys specifies map keys should be sorted before being printed. Use 90 | // this to have a more deterministic, diffable output. Note that only 91 | // native types (bool, int, uint, floats, uintptr and string) and types 92 | // that support the error or Stringer interfaces (if methods are 93 | // enabled) are supported, with other types sorted according to the 94 | // reflect.Value.String() output which guarantees display stability. 95 | SortKeys bool 96 | 97 | // SpewKeys specifies that, as a last resort attempt, map keys should 98 | // be spewed to strings and sorted by those strings. This is only 99 | // considered if SortKeys is true. 100 | SpewKeys bool 101 | } 102 | 103 | // Config is the active configuration of the top-level functions. 104 | // The configuration can be changed by modifying the contents of spew.Config. 105 | var Config = ConfigState{Indent: " "} 106 | 107 | // Errorf is a wrapper for fmt.Errorf that treats each argument as if it were 108 | // passed with a Formatter interface returned by c.NewFormatter. It returns 109 | // the formatted string as a value that satisfies error. See NewFormatter 110 | // for formatting details. 111 | // 112 | // This function is shorthand for the following syntax: 113 | // 114 | // fmt.Errorf(format, c.NewFormatter(a), c.NewFormatter(b)) 115 | func (c *ConfigState) Errorf(format string, a ...interface{}) (err error) { 116 | return fmt.Errorf(format, c.convertArgs(a)...) 117 | } 118 | 119 | // Fprint is a wrapper for fmt.Fprint that treats each argument as if it were 120 | // passed with a Formatter interface returned by c.NewFormatter. It returns 121 | // the number of bytes written and any write error encountered. See 122 | // NewFormatter for formatting details. 123 | // 124 | // This function is shorthand for the following syntax: 125 | // 126 | // fmt.Fprint(w, c.NewFormatter(a), c.NewFormatter(b)) 127 | func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (n int, err error) { 128 | return fmt.Fprint(w, c.convertArgs(a)...) 129 | } 130 | 131 | // Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were 132 | // passed with a Formatter interface returned by c.NewFormatter. It returns 133 | // the number of bytes written and any write error encountered. See 134 | // NewFormatter for formatting details. 135 | // 136 | // This function is shorthand for the following syntax: 137 | // 138 | // fmt.Fprintf(w, format, c.NewFormatter(a), c.NewFormatter(b)) 139 | func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { 140 | return fmt.Fprintf(w, format, c.convertArgs(a)...) 141 | } 142 | 143 | // Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it 144 | // passed with a Formatter interface returned by c.NewFormatter. See 145 | // NewFormatter for formatting details. 146 | // 147 | // This function is shorthand for the following syntax: 148 | // 149 | // fmt.Fprintln(w, c.NewFormatter(a), c.NewFormatter(b)) 150 | func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (n int, err error) { 151 | return fmt.Fprintln(w, c.convertArgs(a)...) 152 | } 153 | 154 | // Print is a wrapper for fmt.Print that treats each argument as if it were 155 | // passed with a Formatter interface returned by c.NewFormatter. It returns 156 | // the number of bytes written and any write error encountered. See 157 | // NewFormatter for formatting details. 158 | // 159 | // This function is shorthand for the following syntax: 160 | // 161 | // fmt.Print(c.NewFormatter(a), c.NewFormatter(b)) 162 | func (c *ConfigState) Print(a ...interface{}) (n int, err error) { 163 | return fmt.Print(c.convertArgs(a)...) 164 | } 165 | 166 | // Printf is a wrapper for fmt.Printf that treats each argument as if it were 167 | // passed with a Formatter interface returned by c.NewFormatter. It returns 168 | // the number of bytes written and any write error encountered. See 169 | // NewFormatter for formatting details. 170 | // 171 | // This function is shorthand for the following syntax: 172 | // 173 | // fmt.Printf(format, c.NewFormatter(a), c.NewFormatter(b)) 174 | func (c *ConfigState) Printf(format string, a ...interface{}) (n int, err error) { 175 | return fmt.Printf(format, c.convertArgs(a)...) 176 | } 177 | 178 | // Println is a wrapper for fmt.Println that treats each argument as if it were 179 | // passed with a Formatter interface returned by c.NewFormatter. It returns 180 | // the number of bytes written and any write error encountered. See 181 | // NewFormatter for formatting details. 182 | // 183 | // This function is shorthand for the following syntax: 184 | // 185 | // fmt.Println(c.NewFormatter(a), c.NewFormatter(b)) 186 | func (c *ConfigState) Println(a ...interface{}) (n int, err error) { 187 | return fmt.Println(c.convertArgs(a)...) 188 | } 189 | 190 | // Sprint is a wrapper for fmt.Sprint that treats each argument as if it were 191 | // passed with a Formatter interface returned by c.NewFormatter. It returns 192 | // the resulting string. See NewFormatter for formatting details. 193 | // 194 | // This function is shorthand for the following syntax: 195 | // 196 | // fmt.Sprint(c.NewFormatter(a), c.NewFormatter(b)) 197 | func (c *ConfigState) Sprint(a ...interface{}) string { 198 | return fmt.Sprint(c.convertArgs(a)...) 199 | } 200 | 201 | // Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were 202 | // passed with a Formatter interface returned by c.NewFormatter. It returns 203 | // the resulting string. See NewFormatter for formatting details. 204 | // 205 | // This function is shorthand for the following syntax: 206 | // 207 | // fmt.Sprintf(format, c.NewFormatter(a), c.NewFormatter(b)) 208 | func (c *ConfigState) Sprintf(format string, a ...interface{}) string { 209 | return fmt.Sprintf(format, c.convertArgs(a)...) 210 | } 211 | 212 | // Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it 213 | // were passed with a Formatter interface returned by c.NewFormatter. It 214 | // returns the resulting string. See NewFormatter for formatting details. 215 | // 216 | // This function is shorthand for the following syntax: 217 | // 218 | // fmt.Sprintln(c.NewFormatter(a), c.NewFormatter(b)) 219 | func (c *ConfigState) Sprintln(a ...interface{}) string { 220 | return fmt.Sprintln(c.convertArgs(a)...) 221 | } 222 | 223 | /* 224 | NewFormatter returns a custom formatter that satisfies the fmt.Formatter 225 | interface. As a result, it integrates cleanly with standard fmt package 226 | printing functions. The formatter is useful for inline printing of smaller data 227 | types similar to the standard %v format specifier. 228 | 229 | The custom formatter only responds to the %v (most compact), %+v (adds pointer 230 | addresses), %#v (adds types), and %#+v (adds types and pointer addresses) verb 231 | combinations. Any other verbs such as %x and %q will be sent to the the 232 | standard fmt package for formatting. In addition, the custom formatter ignores 233 | the width and precision arguments (however they will still work on the format 234 | specifiers not handled by the custom formatter). 235 | 236 | Typically this function shouldn't be called directly. It is much easier to make 237 | use of the custom formatter by calling one of the convenience functions such as 238 | c.Printf, c.Println, or c.Printf. 239 | */ 240 | func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter { 241 | return newFormatter(c, v) 242 | } 243 | 244 | // Fdump formats and displays the passed arguments to io.Writer w. It formats 245 | // exactly the same as Dump. 246 | func (c *ConfigState) Fdump(w io.Writer, a ...interface{}) { 247 | fdump(c, w, a...) 248 | } 249 | 250 | /* 251 | Dump displays the passed parameters to standard out with newlines, customizable 252 | indentation, and additional debug information such as complete types and all 253 | pointer addresses used to indirect to the final value. It provides the 254 | following features over the built-in printing facilities provided by the fmt 255 | package: 256 | 257 | * Pointers are dereferenced and followed 258 | * Circular data structures are detected and handled properly 259 | * Custom Stringer/error interfaces are optionally invoked, including 260 | on unexported types 261 | * Custom types which only implement the Stringer/error interfaces via 262 | a pointer receiver are optionally invoked when passing non-pointer 263 | variables 264 | * Byte arrays and slices are dumped like the hexdump -C command which 265 | includes offsets, byte values in hex, and ASCII output 266 | 267 | The configuration options are controlled by modifying the public members 268 | of c. See ConfigState for options documentation. 269 | 270 | See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to 271 | get the formatted result as a string. 272 | */ 273 | func (c *ConfigState) Dump(a ...interface{}) { 274 | fdump(c, os.Stdout, a...) 275 | } 276 | 277 | // Sdump returns a string with the passed arguments formatted exactly the same 278 | // as Dump. 279 | func (c *ConfigState) Sdump(a ...interface{}) string { 280 | var buf bytes.Buffer 281 | fdump(c, &buf, a...) 282 | return buf.String() 283 | } 284 | 285 | // convertArgs accepts a slice of arguments and returns a slice of the same 286 | // length with each argument converted to a spew Formatter interface using 287 | // the ConfigState associated with s. 288 | func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) { 289 | formatters = make([]interface{}, len(args)) 290 | for index, arg := range args { 291 | formatters[index] = newFormatter(c, arg) 292 | } 293 | return formatters 294 | } 295 | 296 | // NewDefaultConfig returns a ConfigState with the following default settings. 297 | // 298 | // Indent: " " 299 | // MaxDepth: 0 300 | // DisableMethods: false 301 | // DisablePointerMethods: false 302 | // ContinueOnMethod: false 303 | // SortKeys: false 304 | func NewDefaultConfig() *ConfigState { 305 | return &ConfigState{Indent: " "} 306 | } 307 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Dave Collins 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | Package spew implements a deep pretty printer for Go data structures to aid in 19 | debugging. 20 | 21 | A quick overview of the additional features spew provides over the built-in 22 | printing facilities for Go data types are as follows: 23 | 24 | * Pointers are dereferenced and followed 25 | * Circular data structures are detected and handled properly 26 | * Custom Stringer/error interfaces are optionally invoked, including 27 | on unexported types 28 | * Custom types which only implement the Stringer/error interfaces via 29 | a pointer receiver are optionally invoked when passing non-pointer 30 | variables 31 | * Byte arrays and slices are dumped like the hexdump -C command which 32 | includes offsets, byte values in hex, and ASCII output (only when using 33 | Dump style) 34 | 35 | There are two different approaches spew allows for dumping Go data structures: 36 | 37 | * Dump style which prints with newlines, customizable indentation, 38 | and additional debug information such as types and all pointer addresses 39 | used to indirect to the final value 40 | * A custom Formatter interface that integrates cleanly with the standard fmt 41 | package and replaces %v, %+v, %#v, and %#+v to provide inline printing 42 | similar to the default %v while providing the additional functionality 43 | outlined above and passing unsupported format verbs such as %x and %q 44 | along to fmt 45 | 46 | Quick Start 47 | 48 | This section demonstrates how to quickly get started with spew. See the 49 | sections below for further details on formatting and configuration options. 50 | 51 | To dump a variable with full newlines, indentation, type, and pointer 52 | information use Dump, Fdump, or Sdump: 53 | spew.Dump(myVar1, myVar2, ...) 54 | spew.Fdump(someWriter, myVar1, myVar2, ...) 55 | str := spew.Sdump(myVar1, myVar2, ...) 56 | 57 | Alternatively, if you would prefer to use format strings with a compacted inline 58 | printing style, use the convenience wrappers Printf, Fprintf, etc with 59 | %v (most compact), %+v (adds pointer addresses), %#v (adds types), or 60 | %#+v (adds types and pointer addresses): 61 | spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) 62 | spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) 63 | spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) 64 | spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) 65 | 66 | Configuration Options 67 | 68 | Configuration of spew is handled by fields in the ConfigState type. For 69 | convenience, all of the top-level functions use a global state available 70 | via the spew.Config global. 71 | 72 | It is also possible to create a ConfigState instance that provides methods 73 | equivalent to the top-level functions. This allows concurrent configuration 74 | options. See the ConfigState documentation for more details. 75 | 76 | The following configuration options are available: 77 | * Indent 78 | String to use for each indentation level for Dump functions. 79 | It is a single space by default. A popular alternative is "\t". 80 | 81 | * MaxDepth 82 | Maximum number of levels to descend into nested data structures. 83 | There is no limit by default. 84 | 85 | * DisableMethods 86 | Disables invocation of error and Stringer interface methods. 87 | Method invocation is enabled by default. 88 | 89 | * DisablePointerMethods 90 | Disables invocation of error and Stringer interface methods on types 91 | which only accept pointer receivers from non-pointer variables. 92 | Pointer method invocation is enabled by default. 93 | 94 | * DisablePointerAddresses 95 | DisablePointerAddresses specifies whether to disable the printing of 96 | pointer addresses. This is useful when diffing data structures in tests. 97 | 98 | * DisableCapacities 99 | DisableCapacities specifies whether to disable the printing of 100 | capacities for arrays, slices, maps and channels. This is useful when 101 | diffing data structures in tests. 102 | 103 | * ContinueOnMethod 104 | Enables recursion into types after invoking error and Stringer interface 105 | methods. Recursion after method invocation is disabled by default. 106 | 107 | * SortKeys 108 | Specifies map keys should be sorted before being printed. Use 109 | this to have a more deterministic, diffable output. Note that 110 | only native types (bool, int, uint, floats, uintptr and string) 111 | and types which implement error or Stringer interfaces are 112 | supported with other types sorted according to the 113 | reflect.Value.String() output which guarantees display 114 | stability. Natural map order is used by default. 115 | 116 | * SpewKeys 117 | Specifies that, as a last resort attempt, map keys should be 118 | spewed to strings and sorted by those strings. This is only 119 | considered if SortKeys is true. 120 | 121 | Dump Usage 122 | 123 | Simply call spew.Dump with a list of variables you want to dump: 124 | 125 | spew.Dump(myVar1, myVar2, ...) 126 | 127 | You may also call spew.Fdump if you would prefer to output to an arbitrary 128 | io.Writer. For example, to dump to standard error: 129 | 130 | spew.Fdump(os.Stderr, myVar1, myVar2, ...) 131 | 132 | A third option is to call spew.Sdump to get the formatted output as a string: 133 | 134 | str := spew.Sdump(myVar1, myVar2, ...) 135 | 136 | Sample Dump Output 137 | 138 | See the Dump example for details on the setup of the types and variables being 139 | shown here. 140 | 141 | (main.Foo) { 142 | unexportedField: (*main.Bar)(0xf84002e210)({ 143 | flag: (main.Flag) flagTwo, 144 | data: (uintptr) 145 | }), 146 | ExportedField: (map[interface {}]interface {}) (len=1) { 147 | (string) (len=3) "one": (bool) true 148 | } 149 | } 150 | 151 | Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C 152 | command as shown. 153 | ([]uint8) (len=32 cap=32) { 154 | 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | 155 | 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| 156 | 00000020 31 32 |12| 157 | } 158 | 159 | Custom Formatter 160 | 161 | Spew provides a custom formatter that implements the fmt.Formatter interface 162 | so that it integrates cleanly with standard fmt package printing functions. The 163 | formatter is useful for inline printing of smaller data types similar to the 164 | standard %v format specifier. 165 | 166 | The custom formatter only responds to the %v (most compact), %+v (adds pointer 167 | addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb 168 | combinations. Any other verbs such as %x and %q will be sent to the the 169 | standard fmt package for formatting. In addition, the custom formatter ignores 170 | the width and precision arguments (however they will still work on the format 171 | specifiers not handled by the custom formatter). 172 | 173 | Custom Formatter Usage 174 | 175 | The simplest way to make use of the spew custom formatter is to call one of the 176 | convenience functions such as spew.Printf, spew.Println, or spew.Printf. The 177 | functions have syntax you are most likely already familiar with: 178 | 179 | spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) 180 | spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) 181 | spew.Println(myVar, myVar2) 182 | spew.Fprintf(os.Stderr, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) 183 | spew.Fprintf(os.Stderr, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) 184 | 185 | See the Index for the full list convenience functions. 186 | 187 | Sample Formatter Output 188 | 189 | Double pointer to a uint8: 190 | %v: <**>5 191 | %+v: <**>(0xf8400420d0->0xf8400420c8)5 192 | %#v: (**uint8)5 193 | %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5 194 | 195 | Pointer to circular struct with a uint8 field and a pointer to itself: 196 | %v: <*>{1 <*>} 197 | %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)} 198 | %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)} 199 | %#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)} 200 | 201 | See the Printf example for details on the setup of variables being shown 202 | here. 203 | 204 | Errors 205 | 206 | Since it is possible for custom Stringer/error interfaces to panic, spew 207 | detects them and handles them internally by printing the panic information 208 | inline with the output. Since spew is intended to provide deep pretty printing 209 | capabilities on structures, it intentionally does not return any errors. 210 | */ 211 | package spew 212 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/dump.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Dave Collins 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | package spew 18 | 19 | import ( 20 | "bytes" 21 | "encoding/hex" 22 | "fmt" 23 | "io" 24 | "os" 25 | "reflect" 26 | "regexp" 27 | "strconv" 28 | "strings" 29 | ) 30 | 31 | var ( 32 | // uint8Type is a reflect.Type representing a uint8. It is used to 33 | // convert cgo types to uint8 slices for hexdumping. 34 | uint8Type = reflect.TypeOf(uint8(0)) 35 | 36 | // cCharRE is a regular expression that matches a cgo char. 37 | // It is used to detect character arrays to hexdump them. 38 | cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`) 39 | 40 | // cUnsignedCharRE is a regular expression that matches a cgo unsigned 41 | // char. It is used to detect unsigned character arrays to hexdump 42 | // them. 43 | cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`) 44 | 45 | // cUint8tCharRE is a regular expression that matches a cgo uint8_t. 46 | // It is used to detect uint8_t arrays to hexdump them. 47 | cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`) 48 | ) 49 | 50 | // dumpState contains information about the state of a dump operation. 51 | type dumpState struct { 52 | w io.Writer 53 | depth int 54 | pointers map[uintptr]int 55 | ignoreNextType bool 56 | ignoreNextIndent bool 57 | cs *ConfigState 58 | } 59 | 60 | // indent performs indentation according to the depth level and cs.Indent 61 | // option. 62 | func (d *dumpState) indent() { 63 | if d.ignoreNextIndent { 64 | d.ignoreNextIndent = false 65 | return 66 | } 67 | d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) 68 | } 69 | 70 | // unpackValue returns values inside of non-nil interfaces when possible. 71 | // This is useful for data types like structs, arrays, slices, and maps which 72 | // can contain varying types packed inside an interface. 73 | func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { 74 | if v.Kind() == reflect.Interface && !v.IsNil() { 75 | v = v.Elem() 76 | } 77 | return v 78 | } 79 | 80 | // dumpPtr handles formatting of pointers by indirecting them as necessary. 81 | func (d *dumpState) dumpPtr(v reflect.Value) { 82 | // Remove pointers at or below the current depth from map used to detect 83 | // circular refs. 84 | for k, depth := range d.pointers { 85 | if depth >= d.depth { 86 | delete(d.pointers, k) 87 | } 88 | } 89 | 90 | // Keep list of all dereferenced pointers to show later. 91 | pointerChain := make([]uintptr, 0) 92 | 93 | // Figure out how many levels of indirection there are by dereferencing 94 | // pointers and unpacking interfaces down the chain while detecting circular 95 | // references. 96 | nilFound := false 97 | cycleFound := false 98 | indirects := 0 99 | ve := v 100 | for ve.Kind() == reflect.Ptr { 101 | if ve.IsNil() { 102 | nilFound = true 103 | break 104 | } 105 | indirects++ 106 | addr := ve.Pointer() 107 | pointerChain = append(pointerChain, addr) 108 | if pd, ok := d.pointers[addr]; ok && pd < d.depth { 109 | cycleFound = true 110 | indirects-- 111 | break 112 | } 113 | d.pointers[addr] = d.depth 114 | 115 | ve = ve.Elem() 116 | if ve.Kind() == reflect.Interface { 117 | if ve.IsNil() { 118 | nilFound = true 119 | break 120 | } 121 | ve = ve.Elem() 122 | } 123 | } 124 | 125 | // Display type information. 126 | d.w.Write(openParenBytes) 127 | d.w.Write(bytes.Repeat(asteriskBytes, indirects)) 128 | d.w.Write([]byte(ve.Type().String())) 129 | d.w.Write(closeParenBytes) 130 | 131 | // Display pointer information. 132 | if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { 133 | d.w.Write(openParenBytes) 134 | for i, addr := range pointerChain { 135 | if i > 0 { 136 | d.w.Write(pointerChainBytes) 137 | } 138 | printHexPtr(d.w, addr) 139 | } 140 | d.w.Write(closeParenBytes) 141 | } 142 | 143 | // Display dereferenced value. 144 | d.w.Write(openParenBytes) 145 | switch { 146 | case nilFound: 147 | d.w.Write(nilAngleBytes) 148 | 149 | case cycleFound: 150 | d.w.Write(circularBytes) 151 | 152 | default: 153 | d.ignoreNextType = true 154 | d.dump(ve) 155 | } 156 | d.w.Write(closeParenBytes) 157 | } 158 | 159 | // dumpSlice handles formatting of arrays and slices. Byte (uint8 under 160 | // reflection) arrays and slices are dumped in hexdump -C fashion. 161 | func (d *dumpState) dumpSlice(v reflect.Value) { 162 | // Determine whether this type should be hex dumped or not. Also, 163 | // for types which should be hexdumped, try to use the underlying data 164 | // first, then fall back to trying to convert them to a uint8 slice. 165 | var buf []uint8 166 | doConvert := false 167 | doHexDump := false 168 | numEntries := v.Len() 169 | if numEntries > 0 { 170 | vt := v.Index(0).Type() 171 | vts := vt.String() 172 | switch { 173 | // C types that need to be converted. 174 | case cCharRE.MatchString(vts): 175 | fallthrough 176 | case cUnsignedCharRE.MatchString(vts): 177 | fallthrough 178 | case cUint8tCharRE.MatchString(vts): 179 | doConvert = true 180 | 181 | // Try to use existing uint8 slices and fall back to converting 182 | // and copying if that fails. 183 | case vt.Kind() == reflect.Uint8: 184 | // We need an addressable interface to convert the type 185 | // to a byte slice. However, the reflect package won't 186 | // give us an interface on certain things like 187 | // unexported struct fields in order to enforce 188 | // visibility rules. We use unsafe, when available, to 189 | // bypass these restrictions since this package does not 190 | // mutate the values. 191 | vs := v 192 | if !vs.CanInterface() || !vs.CanAddr() { 193 | vs = unsafeReflectValue(vs) 194 | } 195 | if !UnsafeDisabled { 196 | vs = vs.Slice(0, numEntries) 197 | 198 | // Use the existing uint8 slice if it can be 199 | // type asserted. 200 | iface := vs.Interface() 201 | if slice, ok := iface.([]uint8); ok { 202 | buf = slice 203 | doHexDump = true 204 | break 205 | } 206 | } 207 | 208 | // The underlying data needs to be converted if it can't 209 | // be type asserted to a uint8 slice. 210 | doConvert = true 211 | } 212 | 213 | // Copy and convert the underlying type if needed. 214 | if doConvert && vt.ConvertibleTo(uint8Type) { 215 | // Convert and copy each element into a uint8 byte 216 | // slice. 217 | buf = make([]uint8, numEntries) 218 | for i := 0; i < numEntries; i++ { 219 | vv := v.Index(i) 220 | buf[i] = uint8(vv.Convert(uint8Type).Uint()) 221 | } 222 | doHexDump = true 223 | } 224 | } 225 | 226 | // Hexdump the entire slice as needed. 227 | if doHexDump { 228 | indent := strings.Repeat(d.cs.Indent, d.depth) 229 | str := indent + hex.Dump(buf) 230 | str = strings.Replace(str, "\n", "\n"+indent, -1) 231 | str = strings.TrimRight(str, d.cs.Indent) 232 | d.w.Write([]byte(str)) 233 | return 234 | } 235 | 236 | // Recursively call dump for each item. 237 | for i := 0; i < numEntries; i++ { 238 | d.dump(d.unpackValue(v.Index(i))) 239 | if i < (numEntries - 1) { 240 | d.w.Write(commaNewlineBytes) 241 | } else { 242 | d.w.Write(newlineBytes) 243 | } 244 | } 245 | } 246 | 247 | // dump is the main workhorse for dumping a value. It uses the passed reflect 248 | // value to figure out what kind of object we are dealing with and formats it 249 | // appropriately. It is a recursive function, however circular data structures 250 | // are detected and handled properly. 251 | func (d *dumpState) dump(v reflect.Value) { 252 | // Handle invalid reflect values immediately. 253 | kind := v.Kind() 254 | if kind == reflect.Invalid { 255 | d.w.Write(invalidAngleBytes) 256 | return 257 | } 258 | 259 | // Handle pointers specially. 260 | if kind == reflect.Ptr { 261 | d.indent() 262 | d.dumpPtr(v) 263 | return 264 | } 265 | 266 | // Print type information unless already handled elsewhere. 267 | if !d.ignoreNextType { 268 | d.indent() 269 | d.w.Write(openParenBytes) 270 | d.w.Write([]byte(v.Type().String())) 271 | d.w.Write(closeParenBytes) 272 | d.w.Write(spaceBytes) 273 | } 274 | d.ignoreNextType = false 275 | 276 | // Display length and capacity if the built-in len and cap functions 277 | // work with the value's kind and the len/cap itself is non-zero. 278 | valueLen, valueCap := 0, 0 279 | switch v.Kind() { 280 | case reflect.Array, reflect.Slice, reflect.Chan: 281 | valueLen, valueCap = v.Len(), v.Cap() 282 | case reflect.Map, reflect.String: 283 | valueLen = v.Len() 284 | } 285 | if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 { 286 | d.w.Write(openParenBytes) 287 | if valueLen != 0 { 288 | d.w.Write(lenEqualsBytes) 289 | printInt(d.w, int64(valueLen), 10) 290 | } 291 | if !d.cs.DisableCapacities && valueCap != 0 { 292 | if valueLen != 0 { 293 | d.w.Write(spaceBytes) 294 | } 295 | d.w.Write(capEqualsBytes) 296 | printInt(d.w, int64(valueCap), 10) 297 | } 298 | d.w.Write(closeParenBytes) 299 | d.w.Write(spaceBytes) 300 | } 301 | 302 | // Call Stringer/error interfaces if they exist and the handle methods flag 303 | // is enabled 304 | if !d.cs.DisableMethods { 305 | if (kind != reflect.Invalid) && (kind != reflect.Interface) { 306 | if handled := handleMethods(d.cs, d.w, v); handled { 307 | return 308 | } 309 | } 310 | } 311 | 312 | switch kind { 313 | case reflect.Invalid: 314 | // Do nothing. We should never get here since invalid has already 315 | // been handled above. 316 | 317 | case reflect.Bool: 318 | printBool(d.w, v.Bool()) 319 | 320 | case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: 321 | printInt(d.w, v.Int(), 10) 322 | 323 | case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: 324 | printUint(d.w, v.Uint(), 10) 325 | 326 | case reflect.Float32: 327 | printFloat(d.w, v.Float(), 32) 328 | 329 | case reflect.Float64: 330 | printFloat(d.w, v.Float(), 64) 331 | 332 | case reflect.Complex64: 333 | printComplex(d.w, v.Complex(), 32) 334 | 335 | case reflect.Complex128: 336 | printComplex(d.w, v.Complex(), 64) 337 | 338 | case reflect.Slice: 339 | if v.IsNil() { 340 | d.w.Write(nilAngleBytes) 341 | break 342 | } 343 | fallthrough 344 | 345 | case reflect.Array: 346 | d.w.Write(openBraceNewlineBytes) 347 | d.depth++ 348 | if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { 349 | d.indent() 350 | d.w.Write(maxNewlineBytes) 351 | } else { 352 | d.dumpSlice(v) 353 | } 354 | d.depth-- 355 | d.indent() 356 | d.w.Write(closeBraceBytes) 357 | 358 | case reflect.String: 359 | d.w.Write([]byte(strconv.Quote(v.String()))) 360 | 361 | case reflect.Interface: 362 | // The only time we should get here is for nil interfaces due to 363 | // unpackValue calls. 364 | if v.IsNil() { 365 | d.w.Write(nilAngleBytes) 366 | } 367 | 368 | case reflect.Ptr: 369 | // Do nothing. We should never get here since pointers have already 370 | // been handled above. 371 | 372 | case reflect.Map: 373 | // nil maps should be indicated as different than empty maps 374 | if v.IsNil() { 375 | d.w.Write(nilAngleBytes) 376 | break 377 | } 378 | 379 | d.w.Write(openBraceNewlineBytes) 380 | d.depth++ 381 | if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { 382 | d.indent() 383 | d.w.Write(maxNewlineBytes) 384 | } else { 385 | numEntries := v.Len() 386 | keys := v.MapKeys() 387 | if d.cs.SortKeys { 388 | sortValues(keys, d.cs) 389 | } 390 | for i, key := range keys { 391 | d.dump(d.unpackValue(key)) 392 | d.w.Write(colonSpaceBytes) 393 | d.ignoreNextIndent = true 394 | d.dump(d.unpackValue(v.MapIndex(key))) 395 | if i < (numEntries - 1) { 396 | d.w.Write(commaNewlineBytes) 397 | } else { 398 | d.w.Write(newlineBytes) 399 | } 400 | } 401 | } 402 | d.depth-- 403 | d.indent() 404 | d.w.Write(closeBraceBytes) 405 | 406 | case reflect.Struct: 407 | d.w.Write(openBraceNewlineBytes) 408 | d.depth++ 409 | if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { 410 | d.indent() 411 | d.w.Write(maxNewlineBytes) 412 | } else { 413 | vt := v.Type() 414 | numFields := v.NumField() 415 | for i := 0; i < numFields; i++ { 416 | d.indent() 417 | vtf := vt.Field(i) 418 | d.w.Write([]byte(vtf.Name)) 419 | d.w.Write(colonSpaceBytes) 420 | d.ignoreNextIndent = true 421 | d.dump(d.unpackValue(v.Field(i))) 422 | if i < (numFields - 1) { 423 | d.w.Write(commaNewlineBytes) 424 | } else { 425 | d.w.Write(newlineBytes) 426 | } 427 | } 428 | } 429 | d.depth-- 430 | d.indent() 431 | d.w.Write(closeBraceBytes) 432 | 433 | case reflect.Uintptr: 434 | printHexPtr(d.w, uintptr(v.Uint())) 435 | 436 | case reflect.UnsafePointer, reflect.Chan, reflect.Func: 437 | printHexPtr(d.w, v.Pointer()) 438 | 439 | // There were not any other types at the time this code was written, but 440 | // fall back to letting the default fmt package handle it in case any new 441 | // types are added. 442 | default: 443 | if v.CanInterface() { 444 | fmt.Fprintf(d.w, "%v", v.Interface()) 445 | } else { 446 | fmt.Fprintf(d.w, "%v", v.String()) 447 | } 448 | } 449 | } 450 | 451 | // fdump is a helper function to consolidate the logic from the various public 452 | // methods which take varying writers and config states. 453 | func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { 454 | for _, arg := range a { 455 | if arg == nil { 456 | w.Write(interfaceBytes) 457 | w.Write(spaceBytes) 458 | w.Write(nilAngleBytes) 459 | w.Write(newlineBytes) 460 | continue 461 | } 462 | 463 | d := dumpState{w: w, cs: cs} 464 | d.pointers = make(map[uintptr]int) 465 | d.dump(reflect.ValueOf(arg)) 466 | d.w.Write(newlineBytes) 467 | } 468 | } 469 | 470 | // Fdump formats and displays the passed arguments to io.Writer w. It formats 471 | // exactly the same as Dump. 472 | func Fdump(w io.Writer, a ...interface{}) { 473 | fdump(&Config, w, a...) 474 | } 475 | 476 | // Sdump returns a string with the passed arguments formatted exactly the same 477 | // as Dump. 478 | func Sdump(a ...interface{}) string { 479 | var buf bytes.Buffer 480 | fdump(&Config, &buf, a...) 481 | return buf.String() 482 | } 483 | 484 | /* 485 | Dump displays the passed parameters to standard out with newlines, customizable 486 | indentation, and additional debug information such as complete types and all 487 | pointer addresses used to indirect to the final value. It provides the 488 | following features over the built-in printing facilities provided by the fmt 489 | package: 490 | 491 | * Pointers are dereferenced and followed 492 | * Circular data structures are detected and handled properly 493 | * Custom Stringer/error interfaces are optionally invoked, including 494 | on unexported types 495 | * Custom types which only implement the Stringer/error interfaces via 496 | a pointer receiver are optionally invoked when passing non-pointer 497 | variables 498 | * Byte arrays and slices are dumped like the hexdump -C command which 499 | includes offsets, byte values in hex, and ASCII output 500 | 501 | The configuration options are controlled by an exported package global, 502 | spew.Config. See ConfigState for options documentation. 503 | 504 | See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to 505 | get the formatted result as a string. 506 | */ 507 | func Dump(a ...interface{}) { 508 | fdump(&Config, os.Stdout, a...) 509 | } 510 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/format.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Dave Collins 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | package spew 18 | 19 | import ( 20 | "bytes" 21 | "fmt" 22 | "reflect" 23 | "strconv" 24 | "strings" 25 | ) 26 | 27 | // supportedFlags is a list of all the character flags supported by fmt package. 28 | const supportedFlags = "0-+# " 29 | 30 | // formatState implements the fmt.Formatter interface and contains information 31 | // about the state of a formatting operation. The NewFormatter function can 32 | // be used to get a new Formatter which can be used directly as arguments 33 | // in standard fmt package printing calls. 34 | type formatState struct { 35 | value interface{} 36 | fs fmt.State 37 | depth int 38 | pointers map[uintptr]int 39 | ignoreNextType bool 40 | cs *ConfigState 41 | } 42 | 43 | // buildDefaultFormat recreates the original format string without precision 44 | // and width information to pass in to fmt.Sprintf in the case of an 45 | // unrecognized type. Unless new types are added to the language, this 46 | // function won't ever be called. 47 | func (f *formatState) buildDefaultFormat() (format string) { 48 | buf := bytes.NewBuffer(percentBytes) 49 | 50 | for _, flag := range supportedFlags { 51 | if f.fs.Flag(int(flag)) { 52 | buf.WriteRune(flag) 53 | } 54 | } 55 | 56 | buf.WriteRune('v') 57 | 58 | format = buf.String() 59 | return format 60 | } 61 | 62 | // constructOrigFormat recreates the original format string including precision 63 | // and width information to pass along to the standard fmt package. This allows 64 | // automatic deferral of all format strings this package doesn't support. 65 | func (f *formatState) constructOrigFormat(verb rune) (format string) { 66 | buf := bytes.NewBuffer(percentBytes) 67 | 68 | for _, flag := range supportedFlags { 69 | if f.fs.Flag(int(flag)) { 70 | buf.WriteRune(flag) 71 | } 72 | } 73 | 74 | if width, ok := f.fs.Width(); ok { 75 | buf.WriteString(strconv.Itoa(width)) 76 | } 77 | 78 | if precision, ok := f.fs.Precision(); ok { 79 | buf.Write(precisionBytes) 80 | buf.WriteString(strconv.Itoa(precision)) 81 | } 82 | 83 | buf.WriteRune(verb) 84 | 85 | format = buf.String() 86 | return format 87 | } 88 | 89 | // unpackValue returns values inside of non-nil interfaces when possible and 90 | // ensures that types for values which have been unpacked from an interface 91 | // are displayed when the show types flag is also set. 92 | // This is useful for data types like structs, arrays, slices, and maps which 93 | // can contain varying types packed inside an interface. 94 | func (f *formatState) unpackValue(v reflect.Value) reflect.Value { 95 | if v.Kind() == reflect.Interface { 96 | f.ignoreNextType = false 97 | if !v.IsNil() { 98 | v = v.Elem() 99 | } 100 | } 101 | return v 102 | } 103 | 104 | // formatPtr handles formatting of pointers by indirecting them as necessary. 105 | func (f *formatState) formatPtr(v reflect.Value) { 106 | // Display nil if top level pointer is nil. 107 | showTypes := f.fs.Flag('#') 108 | if v.IsNil() && (!showTypes || f.ignoreNextType) { 109 | f.fs.Write(nilAngleBytes) 110 | return 111 | } 112 | 113 | // Remove pointers at or below the current depth from map used to detect 114 | // circular refs. 115 | for k, depth := range f.pointers { 116 | if depth >= f.depth { 117 | delete(f.pointers, k) 118 | } 119 | } 120 | 121 | // Keep list of all dereferenced pointers to possibly show later. 122 | pointerChain := make([]uintptr, 0) 123 | 124 | // Figure out how many levels of indirection there are by derferencing 125 | // pointers and unpacking interfaces down the chain while detecting circular 126 | // references. 127 | nilFound := false 128 | cycleFound := false 129 | indirects := 0 130 | ve := v 131 | for ve.Kind() == reflect.Ptr { 132 | if ve.IsNil() { 133 | nilFound = true 134 | break 135 | } 136 | indirects++ 137 | addr := ve.Pointer() 138 | pointerChain = append(pointerChain, addr) 139 | if pd, ok := f.pointers[addr]; ok && pd < f.depth { 140 | cycleFound = true 141 | indirects-- 142 | break 143 | } 144 | f.pointers[addr] = f.depth 145 | 146 | ve = ve.Elem() 147 | if ve.Kind() == reflect.Interface { 148 | if ve.IsNil() { 149 | nilFound = true 150 | break 151 | } 152 | ve = ve.Elem() 153 | } 154 | } 155 | 156 | // Display type or indirection level depending on flags. 157 | if showTypes && !f.ignoreNextType { 158 | f.fs.Write(openParenBytes) 159 | f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) 160 | f.fs.Write([]byte(ve.Type().String())) 161 | f.fs.Write(closeParenBytes) 162 | } else { 163 | if nilFound || cycleFound { 164 | indirects += strings.Count(ve.Type().String(), "*") 165 | } 166 | f.fs.Write(openAngleBytes) 167 | f.fs.Write([]byte(strings.Repeat("*", indirects))) 168 | f.fs.Write(closeAngleBytes) 169 | } 170 | 171 | // Display pointer information depending on flags. 172 | if f.fs.Flag('+') && (len(pointerChain) > 0) { 173 | f.fs.Write(openParenBytes) 174 | for i, addr := range pointerChain { 175 | if i > 0 { 176 | f.fs.Write(pointerChainBytes) 177 | } 178 | printHexPtr(f.fs, addr) 179 | } 180 | f.fs.Write(closeParenBytes) 181 | } 182 | 183 | // Display dereferenced value. 184 | switch { 185 | case nilFound: 186 | f.fs.Write(nilAngleBytes) 187 | 188 | case cycleFound: 189 | f.fs.Write(circularShortBytes) 190 | 191 | default: 192 | f.ignoreNextType = true 193 | f.format(ve) 194 | } 195 | } 196 | 197 | // format is the main workhorse for providing the Formatter interface. It 198 | // uses the passed reflect value to figure out what kind of object we are 199 | // dealing with and formats it appropriately. It is a recursive function, 200 | // however circular data structures are detected and handled properly. 201 | func (f *formatState) format(v reflect.Value) { 202 | // Handle invalid reflect values immediately. 203 | kind := v.Kind() 204 | if kind == reflect.Invalid { 205 | f.fs.Write(invalidAngleBytes) 206 | return 207 | } 208 | 209 | // Handle pointers specially. 210 | if kind == reflect.Ptr { 211 | f.formatPtr(v) 212 | return 213 | } 214 | 215 | // Print type information unless already handled elsewhere. 216 | if !f.ignoreNextType && f.fs.Flag('#') { 217 | f.fs.Write(openParenBytes) 218 | f.fs.Write([]byte(v.Type().String())) 219 | f.fs.Write(closeParenBytes) 220 | } 221 | f.ignoreNextType = false 222 | 223 | // Call Stringer/error interfaces if they exist and the handle methods 224 | // flag is enabled. 225 | if !f.cs.DisableMethods { 226 | if (kind != reflect.Invalid) && (kind != reflect.Interface) { 227 | if handled := handleMethods(f.cs, f.fs, v); handled { 228 | return 229 | } 230 | } 231 | } 232 | 233 | switch kind { 234 | case reflect.Invalid: 235 | // Do nothing. We should never get here since invalid has already 236 | // been handled above. 237 | 238 | case reflect.Bool: 239 | printBool(f.fs, v.Bool()) 240 | 241 | case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: 242 | printInt(f.fs, v.Int(), 10) 243 | 244 | case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: 245 | printUint(f.fs, v.Uint(), 10) 246 | 247 | case reflect.Float32: 248 | printFloat(f.fs, v.Float(), 32) 249 | 250 | case reflect.Float64: 251 | printFloat(f.fs, v.Float(), 64) 252 | 253 | case reflect.Complex64: 254 | printComplex(f.fs, v.Complex(), 32) 255 | 256 | case reflect.Complex128: 257 | printComplex(f.fs, v.Complex(), 64) 258 | 259 | case reflect.Slice: 260 | if v.IsNil() { 261 | f.fs.Write(nilAngleBytes) 262 | break 263 | } 264 | fallthrough 265 | 266 | case reflect.Array: 267 | f.fs.Write(openBracketBytes) 268 | f.depth++ 269 | if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { 270 | f.fs.Write(maxShortBytes) 271 | } else { 272 | numEntries := v.Len() 273 | for i := 0; i < numEntries; i++ { 274 | if i > 0 { 275 | f.fs.Write(spaceBytes) 276 | } 277 | f.ignoreNextType = true 278 | f.format(f.unpackValue(v.Index(i))) 279 | } 280 | } 281 | f.depth-- 282 | f.fs.Write(closeBracketBytes) 283 | 284 | case reflect.String: 285 | f.fs.Write([]byte(v.String())) 286 | 287 | case reflect.Interface: 288 | // The only time we should get here is for nil interfaces due to 289 | // unpackValue calls. 290 | if v.IsNil() { 291 | f.fs.Write(nilAngleBytes) 292 | } 293 | 294 | case reflect.Ptr: 295 | // Do nothing. We should never get here since pointers have already 296 | // been handled above. 297 | 298 | case reflect.Map: 299 | // nil maps should be indicated as different than empty maps 300 | if v.IsNil() { 301 | f.fs.Write(nilAngleBytes) 302 | break 303 | } 304 | 305 | f.fs.Write(openMapBytes) 306 | f.depth++ 307 | if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { 308 | f.fs.Write(maxShortBytes) 309 | } else { 310 | keys := v.MapKeys() 311 | if f.cs.SortKeys { 312 | sortValues(keys, f.cs) 313 | } 314 | for i, key := range keys { 315 | if i > 0 { 316 | f.fs.Write(spaceBytes) 317 | } 318 | f.ignoreNextType = true 319 | f.format(f.unpackValue(key)) 320 | f.fs.Write(colonBytes) 321 | f.ignoreNextType = true 322 | f.format(f.unpackValue(v.MapIndex(key))) 323 | } 324 | } 325 | f.depth-- 326 | f.fs.Write(closeMapBytes) 327 | 328 | case reflect.Struct: 329 | numFields := v.NumField() 330 | f.fs.Write(openBraceBytes) 331 | f.depth++ 332 | if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { 333 | f.fs.Write(maxShortBytes) 334 | } else { 335 | vt := v.Type() 336 | for i := 0; i < numFields; i++ { 337 | if i > 0 { 338 | f.fs.Write(spaceBytes) 339 | } 340 | vtf := vt.Field(i) 341 | if f.fs.Flag('+') || f.fs.Flag('#') { 342 | f.fs.Write([]byte(vtf.Name)) 343 | f.fs.Write(colonBytes) 344 | } 345 | f.format(f.unpackValue(v.Field(i))) 346 | } 347 | } 348 | f.depth-- 349 | f.fs.Write(closeBraceBytes) 350 | 351 | case reflect.Uintptr: 352 | printHexPtr(f.fs, uintptr(v.Uint())) 353 | 354 | case reflect.UnsafePointer, reflect.Chan, reflect.Func: 355 | printHexPtr(f.fs, v.Pointer()) 356 | 357 | // There were not any other types at the time this code was written, but 358 | // fall back to letting the default fmt package handle it if any get added. 359 | default: 360 | format := f.buildDefaultFormat() 361 | if v.CanInterface() { 362 | fmt.Fprintf(f.fs, format, v.Interface()) 363 | } else { 364 | fmt.Fprintf(f.fs, format, v.String()) 365 | } 366 | } 367 | } 368 | 369 | // Format satisfies the fmt.Formatter interface. See NewFormatter for usage 370 | // details. 371 | func (f *formatState) Format(fs fmt.State, verb rune) { 372 | f.fs = fs 373 | 374 | // Use standard formatting for verbs that are not v. 375 | if verb != 'v' { 376 | format := f.constructOrigFormat(verb) 377 | fmt.Fprintf(fs, format, f.value) 378 | return 379 | } 380 | 381 | if f.value == nil { 382 | if fs.Flag('#') { 383 | fs.Write(interfaceBytes) 384 | } 385 | fs.Write(nilAngleBytes) 386 | return 387 | } 388 | 389 | f.format(reflect.ValueOf(f.value)) 390 | } 391 | 392 | // newFormatter is a helper function to consolidate the logic from the various 393 | // public methods which take varying config states. 394 | func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { 395 | fs := &formatState{value: v, cs: cs} 396 | fs.pointers = make(map[uintptr]int) 397 | return fs 398 | } 399 | 400 | /* 401 | NewFormatter returns a custom formatter that satisfies the fmt.Formatter 402 | interface. As a result, it integrates cleanly with standard fmt package 403 | printing functions. The formatter is useful for inline printing of smaller data 404 | types similar to the standard %v format specifier. 405 | 406 | The custom formatter only responds to the %v (most compact), %+v (adds pointer 407 | addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb 408 | combinations. Any other verbs such as %x and %q will be sent to the the 409 | standard fmt package for formatting. In addition, the custom formatter ignores 410 | the width and precision arguments (however they will still work on the format 411 | specifiers not handled by the custom formatter). 412 | 413 | Typically this function shouldn't be called directly. It is much easier to make 414 | use of the custom formatter by calling one of the convenience functions such as 415 | Printf, Println, or Fprintf. 416 | */ 417 | func NewFormatter(v interface{}) fmt.Formatter { 418 | return newFormatter(&Config, v) 419 | } 420 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/spew.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2016 Dave Collins 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | package spew 18 | 19 | import ( 20 | "fmt" 21 | "io" 22 | ) 23 | 24 | // Errorf is a wrapper for fmt.Errorf that treats each argument as if it were 25 | // passed with a default Formatter interface returned by NewFormatter. It 26 | // returns the formatted string as a value that satisfies error. See 27 | // NewFormatter for formatting details. 28 | // 29 | // This function is shorthand for the following syntax: 30 | // 31 | // fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b)) 32 | func Errorf(format string, a ...interface{}) (err error) { 33 | return fmt.Errorf(format, convertArgs(a)...) 34 | } 35 | 36 | // Fprint is a wrapper for fmt.Fprint that treats each argument as if it were 37 | // passed with a default Formatter interface returned by NewFormatter. It 38 | // returns the number of bytes written and any write error encountered. See 39 | // NewFormatter for formatting details. 40 | // 41 | // This function is shorthand for the following syntax: 42 | // 43 | // fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b)) 44 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) { 45 | return fmt.Fprint(w, convertArgs(a)...) 46 | } 47 | 48 | // Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were 49 | // passed with a default Formatter interface returned by NewFormatter. It 50 | // returns the number of bytes written and any write error encountered. See 51 | // NewFormatter for formatting details. 52 | // 53 | // This function is shorthand for the following syntax: 54 | // 55 | // fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b)) 56 | func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { 57 | return fmt.Fprintf(w, format, convertArgs(a)...) 58 | } 59 | 60 | // Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it 61 | // passed with a default Formatter interface returned by NewFormatter. See 62 | // NewFormatter for formatting details. 63 | // 64 | // This function is shorthand for the following syntax: 65 | // 66 | // fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b)) 67 | func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { 68 | return fmt.Fprintln(w, convertArgs(a)...) 69 | } 70 | 71 | // Print is a wrapper for fmt.Print that treats each argument as if it were 72 | // passed with a default Formatter interface returned by NewFormatter. It 73 | // returns the number of bytes written and any write error encountered. See 74 | // NewFormatter for formatting details. 75 | // 76 | // This function is shorthand for the following syntax: 77 | // 78 | // fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b)) 79 | func Print(a ...interface{}) (n int, err error) { 80 | return fmt.Print(convertArgs(a)...) 81 | } 82 | 83 | // Printf is a wrapper for fmt.Printf that treats each argument as if it were 84 | // passed with a default Formatter interface returned by NewFormatter. It 85 | // returns the number of bytes written and any write error encountered. See 86 | // NewFormatter for formatting details. 87 | // 88 | // This function is shorthand for the following syntax: 89 | // 90 | // fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b)) 91 | func Printf(format string, a ...interface{}) (n int, err error) { 92 | return fmt.Printf(format, convertArgs(a)...) 93 | } 94 | 95 | // Println is a wrapper for fmt.Println that treats each argument as if it were 96 | // passed with a default Formatter interface returned by NewFormatter. It 97 | // returns the number of bytes written and any write error encountered. See 98 | // NewFormatter for formatting details. 99 | // 100 | // This function is shorthand for the following syntax: 101 | // 102 | // fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b)) 103 | func Println(a ...interface{}) (n int, err error) { 104 | return fmt.Println(convertArgs(a)...) 105 | } 106 | 107 | // Sprint is a wrapper for fmt.Sprint that treats each argument as if it were 108 | // passed with a default Formatter interface returned by NewFormatter. It 109 | // returns the resulting string. See NewFormatter for formatting details. 110 | // 111 | // This function is shorthand for the following syntax: 112 | // 113 | // fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b)) 114 | func Sprint(a ...interface{}) string { 115 | return fmt.Sprint(convertArgs(a)...) 116 | } 117 | 118 | // Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were 119 | // passed with a default Formatter interface returned by NewFormatter. It 120 | // returns the resulting string. See NewFormatter for formatting details. 121 | // 122 | // This function is shorthand for the following syntax: 123 | // 124 | // fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b)) 125 | func Sprintf(format string, a ...interface{}) string { 126 | return fmt.Sprintf(format, convertArgs(a)...) 127 | } 128 | 129 | // Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it 130 | // were passed with a default Formatter interface returned by NewFormatter. It 131 | // returns the resulting string. See NewFormatter for formatting details. 132 | // 133 | // This function is shorthand for the following syntax: 134 | // 135 | // fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b)) 136 | func Sprintln(a ...interface{}) string { 137 | return fmt.Sprintln(convertArgs(a)...) 138 | } 139 | 140 | // convertArgs accepts a slice of arguments and returns a slice of the same 141 | // length with each argument converted to a default spew Formatter interface. 142 | func convertArgs(args []interface{}) (formatters []interface{}) { 143 | formatters = make([]interface{}, len(args)) 144 | for index, arg := range args { 145 | formatters[index] = NewFormatter(arg) 146 | } 147 | return formatters 148 | } 149 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | 4 | debug.test -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.7 5 | - 1.8 6 | - 1.9 7 | - "1.10" 8 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" 6 | name = "github.com/davecgh/go-spew" 7 | packages = ["spew"] 8 | pruneopts = "UT" 9 | revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" 10 | version = "v1.1.1" 11 | 12 | [[projects]] 13 | digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" 14 | name = "github.com/pmezard/go-difflib" 15 | packages = ["difflib"] 16 | pruneopts = "UT" 17 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 18 | version = "v1.0.0" 19 | 20 | [[projects]] 21 | digest = "1:5110e3d4f130772fd39e6ce8208ad1955b242ccfcc8ad9d158857250579c82f4" 22 | name = "github.com/stretchr/testify" 23 | packages = [ 24 | "assert", 25 | "require", 26 | "suite", 27 | ] 28 | pruneopts = "UT" 29 | revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" 30 | version = "v1.2.2" 31 | 32 | [solve-meta] 33 | analyzer-name = "dep" 34 | analyzer-version = 1 35 | input-imports = [ 36 | "github.com/stretchr/testify/assert", 37 | "github.com/stretchr/testify/require", 38 | "github.com/stretchr/testify/suite", 39 | ] 40 | solver-name = "gps-cdcl" 41 | solver-version = 1 42 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | name = "github.com/stretchr/testify" 30 | version = "1.2.2" 31 | 32 | [prune] 33 | go-tests = true 34 | unused-packages = true 35 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Scott Ware 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/README.md: -------------------------------------------------------------------------------- 1 | ## go-bigip 2 | [![GoDoc](https://godoc.org/github.com/scottdware/go-bigip?status.svg)](https://godoc.org/github.com/scottdware/go-bigip) [![Travis-CI](https://travis-ci.org/scottdware/go-bigip.svg?branch=master)](https://travis-ci.org/scottdware/go-bigip) 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/scottdware/go-bigip)](https://goreportcard.com/report/github.com/scottdware/go-bigip) 4 | [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/scottdware/go-bigip/master/LICENSE) 5 | 6 | A Go package that interacts with F5 BIG-IP systems using the REST API. 7 | 8 | Some of the tasks you can do are as follows: 9 | 10 | * Get a detailed list of all nodes, pools, vlans, routes, trunks, route domains, self IP's, virtual servers, monitors on the BIG-IP system. 11 | * Create/delete nodes, pools, vlans, routes, trunks, route domains, self IP's, virtual servers, monitors, etc. 12 | * Modify individual settings for all of the above. 13 | * Change the status of nodes and individual pool members (enable/disable). 14 | 15 | > **Note**: You must be on version 11.4+! For the features that deal with internal data groups, you must be running version 11.6+! 16 | 17 | ### Examples & Documentation 18 | Visit the [GoDoc][godoc-go-bigip] page for package documentation and examples. 19 | 20 | Here's a [blog post][blog] that goes a little more in-depth. 21 | 22 | ### Contributors 23 | A very special thanks to the following who have helped contribute to this software, especially: 24 | 25 | * [Kenneth Maglio](https://github.com/kenmaglio) 26 | * [Adam Burnett](https://github.com/aburnett) 27 | * [Michael D. Ivey](https://github.com/ivey) 28 | 29 | [godoc-go-bigip]: http://godoc.org/github.com/scottdware/go-bigip 30 | [license]: https://github.com/scottdware/go-bigip/blob/master/LICENSE 31 | [blog]: http://sdubs.org/go-big-ip-or-go-home/ 32 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/bigip.go: -------------------------------------------------------------------------------- 1 | // Package bigip interacts with F5 BIG-IP systems using the REST API. 2 | package bigip 3 | 4 | import ( 5 | "bytes" 6 | "crypto/tls" 7 | "encoding/json" 8 | "errors" 9 | "fmt" 10 | "io/ioutil" 11 | "net/http" 12 | "reflect" 13 | "strings" 14 | "time" 15 | ) 16 | 17 | var defaultConfigOptions = &ConfigOptions{ 18 | APICallTimeout: 60 * time.Second, 19 | } 20 | 21 | type ConfigOptions struct { 22 | APICallTimeout time.Duration 23 | } 24 | 25 | // BigIP is a container for our session state. 26 | type BigIP struct { 27 | Host string 28 | User string 29 | Password string 30 | Token string // if set, will be used instead of User/Password 31 | Transport *http.Transport 32 | ConfigOptions *ConfigOptions 33 | } 34 | 35 | // APIRequest builds our request before sending it to the server. 36 | type APIRequest struct { 37 | Method string 38 | URL string 39 | Body string 40 | ContentType string 41 | } 42 | 43 | // RequestError contains information about any error we get from a request. 44 | type RequestError struct { 45 | Code int `json:"code,omitempty"` 46 | Message string `json:"message,omitempty"` 47 | ErrorStack []string `json:"errorStack,omitempty"` 48 | } 49 | 50 | // Error returns the error message. 51 | func (r *RequestError) Error() error { 52 | if r.Message != "" { 53 | return errors.New(r.Message) 54 | } 55 | 56 | return nil 57 | } 58 | 59 | // NewSession sets up our connection to the BIG-IP system. 60 | func NewSession(host, user, passwd string, configOptions *ConfigOptions) *BigIP { 61 | var url string 62 | if !strings.HasPrefix(host, "http") { 63 | url = fmt.Sprintf("https://%s", host) 64 | } else { 65 | url = host 66 | } 67 | if configOptions == nil { 68 | configOptions = defaultConfigOptions 69 | } 70 | return &BigIP{ 71 | Host: url, 72 | User: user, 73 | Password: passwd, 74 | Transport: &http.Transport{ 75 | TLSClientConfig: &tls.Config{ 76 | InsecureSkipVerify: true, 77 | }, 78 | }, 79 | ConfigOptions: configOptions, 80 | } 81 | } 82 | 83 | // NewTokenSession sets up our connection to the BIG-IP system, and 84 | // instructs the session to use token authentication instead of Basic 85 | // Auth. This is required when using an external authentication 86 | // provider, such as Radius or Active Directory. loginProviderName is 87 | // probably "tmos" but your environment may vary. 88 | func NewTokenSession(host, user, passwd, loginProviderName string, configOptions *ConfigOptions) (b *BigIP, err error) { 89 | type authReq struct { 90 | Username string `json:"username"` 91 | Password string `json:"password"` 92 | LoginProviderName string `json:"loginProviderName"` 93 | } 94 | type authResp struct { 95 | Token struct { 96 | Token string 97 | } 98 | } 99 | 100 | auth := authReq{ 101 | user, 102 | passwd, 103 | loginProviderName, 104 | } 105 | 106 | marshalJSON, err := json.Marshal(auth) 107 | if err != nil { 108 | return 109 | } 110 | 111 | req := &APIRequest{ 112 | Method: "post", 113 | URL: "mgmt/shared/authn/login", 114 | Body: string(marshalJSON), 115 | ContentType: "application/json", 116 | } 117 | 118 | b = NewSession(host, user, passwd, configOptions) 119 | resp, err := b.APICall(req) 120 | if err != nil { 121 | return 122 | } 123 | 124 | if resp == nil { 125 | err = fmt.Errorf("unable to acquire authentication token") 126 | return 127 | } 128 | 129 | var aresp authResp 130 | err = json.Unmarshal(resp, &aresp) 131 | if err != nil { 132 | return 133 | } 134 | 135 | if aresp.Token.Token == "" { 136 | err = fmt.Errorf("unable to acquire authentication token") 137 | return 138 | } 139 | 140 | b.Token = aresp.Token.Token 141 | 142 | return 143 | } 144 | 145 | // APICall is used to query the BIG-IP web API. 146 | func (b *BigIP) APICall(options *APIRequest) ([]byte, error) { 147 | var req *http.Request 148 | client := &http.Client{ 149 | Transport: b.Transport, 150 | Timeout: b.ConfigOptions.APICallTimeout, 151 | } 152 | var format string 153 | if strings.Contains(options.URL, "mgmt/") { 154 | format = "%s/%s" 155 | } else { 156 | format = "%s/mgmt/tm/%s" 157 | } 158 | url := fmt.Sprintf(format, b.Host, options.URL) 159 | body := bytes.NewReader([]byte(options.Body)) 160 | req, _ = http.NewRequest(strings.ToUpper(options.Method), url, body) 161 | if b.Token != "" { 162 | req.Header.Set("X-F5-Auth-Token", b.Token) 163 | } else { 164 | req.SetBasicAuth(b.User, b.Password) 165 | } 166 | 167 | // fmt.Println("REQ -- ", options.Method, " ", url, " -- ", options.Body) 168 | 169 | if len(options.ContentType) > 0 { 170 | req.Header.Set("Content-Type", options.ContentType) 171 | } 172 | 173 | res, err := client.Do(req) 174 | if err != nil { 175 | return nil, err 176 | } 177 | 178 | defer res.Body.Close() 179 | 180 | data, _ := ioutil.ReadAll(res.Body) 181 | 182 | if res.StatusCode >= 400 { 183 | if res.Header.Get("Content-Type") == "application/json" { 184 | return data, b.checkError(data) 185 | } 186 | 187 | return data, errors.New(fmt.Sprintf("HTTP %d :: %s", res.StatusCode, string(data[:]))) 188 | } 189 | 190 | // fmt.Println("Resp --", res.StatusCode, " -- ", string(data)) 191 | return data, nil 192 | } 193 | 194 | func (b *BigIP) iControlPath(parts []string) string { 195 | var buffer bytes.Buffer 196 | var lastPath int 197 | if strings.HasPrefix(parts[len(parts)-1], "?") { 198 | lastPath = len(parts) - 2 199 | } else { 200 | lastPath = len(parts) - 1 201 | } 202 | for i, p := range parts { 203 | buffer.WriteString(strings.Replace(p, "/", "~", -1)) 204 | if i < lastPath { 205 | buffer.WriteString("/") 206 | } 207 | } 208 | return buffer.String() 209 | } 210 | 211 | //Generic delete 212 | func (b *BigIP) delete(path ...string) error { 213 | req := &APIRequest{ 214 | Method: "delete", 215 | URL: b.iControlPath(path), 216 | } 217 | 218 | _, callErr := b.APICall(req) 219 | return callErr 220 | } 221 | 222 | func (b *BigIP) post(body interface{}, path ...string) error { 223 | return b.reqWithBody("post", body, path...) 224 | } 225 | 226 | func (b *BigIP) put(body interface{}, path ...string) error { 227 | return b.reqWithBody("put", body, path...) 228 | } 229 | 230 | func (b *BigIP) patch(body interface{}, path ...string) error { 231 | return b.reqWithBody("patch", body, path...) 232 | } 233 | 234 | func (b *BigIP) reqWithBody(method string, body interface{}, path ...string) error { 235 | marshalJSON, err := jsonMarshal(body) 236 | if err != nil { 237 | return err 238 | } 239 | 240 | req := &APIRequest{ 241 | Method: method, 242 | URL: b.iControlPath(path), 243 | Body: strings.TrimRight(string(marshalJSON), "\n"), 244 | ContentType: "application/json", 245 | } 246 | 247 | _, callErr := b.APICall(req) 248 | return callErr 249 | } 250 | 251 | //Get a url and populate an entity. If the entity does not exist (404) then the 252 | //passed entity will be untouched and false will be returned as the second parameter. 253 | //You can use this to distinguish between a missing entity or an actual error. 254 | func (b *BigIP) getForEntity(e interface{}, path ...string) (error, bool) { 255 | req := &APIRequest{ 256 | Method: "get", 257 | URL: b.iControlPath(path), 258 | ContentType: "application/json", 259 | } 260 | 261 | resp, err := b.APICall(req) 262 | if err != nil { 263 | var reqError RequestError 264 | json.Unmarshal(resp, &reqError) 265 | if reqError.Code == 404 { 266 | return nil, false 267 | } 268 | return err, false 269 | } 270 | 271 | err = json.Unmarshal(resp, e) 272 | if err != nil { 273 | return err, false 274 | } 275 | 276 | return nil, true 277 | } 278 | 279 | // checkError handles any errors we get from our API requests. It returns either the 280 | // message of the error, if any, or nil. 281 | func (b *BigIP) checkError(resp []byte) error { 282 | if len(resp) == 0 { 283 | return nil 284 | } 285 | 286 | var reqError RequestError 287 | 288 | err := json.Unmarshal(resp, &reqError) 289 | if err != nil { 290 | return errors.New(fmt.Sprintf("%s\n%s", err.Error(), string(resp[:]))) 291 | } 292 | 293 | err = reqError.Error() 294 | if err != nil { 295 | return err 296 | } 297 | 298 | return nil 299 | } 300 | 301 | // jsonMarshal specifies an encoder with 'SetEscapeHTML' set to 'false' so that <, >, and & are not escaped. https://golang.org/pkg/encoding/json/#Marshal 302 | // https://stackoverflow.com/questions/28595664/how-to-stop-json-marshal-from-escaping-and 303 | func jsonMarshal(t interface{}) ([]byte, error) { 304 | buffer := &bytes.Buffer{} 305 | encoder := json.NewEncoder(buffer) 306 | encoder.SetEscapeHTML(false) 307 | err := encoder.Encode(t) 308 | return buffer.Bytes(), err 309 | } 310 | 311 | // Helper function to return a boolean pointer. 312 | func Bool(b bool) *bool { 313 | return &b 314 | } 315 | 316 | // Helper to copy between transfer objects and model objects to hide the myriad of boolean representations 317 | // in the iControlREST api. DTO fields can be tagged with bool:"yes|enabled|true" to set what true and false 318 | // marshal to. 319 | func marshal(to, from interface{}) error { 320 | toVal := reflect.ValueOf(to).Elem() 321 | fromVal := reflect.ValueOf(from).Elem() 322 | toType := toVal.Type() 323 | for i := 0; i < toVal.NumField(); i++ { 324 | toField := toVal.Field(i) 325 | toFieldType := toType.Field(i) 326 | fromField := fromVal.FieldByName(toFieldType.Name) 327 | if fromField.Interface() != nil && fromField.Kind() == toField.Kind() { 328 | toField.Set(fromField) 329 | } else if toField.Kind() == reflect.Bool && fromField.Kind() == reflect.String { 330 | switch fromField.Interface() { 331 | case "yes", "enabled", "true": 332 | toField.SetBool(true) 333 | break 334 | case "no", "disabled", "false", "": 335 | toField.SetBool(false) 336 | break 337 | default: 338 | return fmt.Errorf("Unknown boolean conversion for %s: %s", toFieldType.Name, fromField.Interface()) 339 | } 340 | } else if _, ok := toField.Interface().(*bool); ok && fromField.Kind() == reflect.String { 341 | switch fromField.Interface() { 342 | case "yes", "enabled", "true": 343 | toField.Set(reflect.ValueOf(Bool(true))) 344 | break 345 | case "no", "disabled", "false": 346 | toField.Set(reflect.ValueOf(Bool(false))) 347 | break 348 | default: 349 | return fmt.Errorf("Unknown boolean conversion for %s: %s", toFieldType.Name, fromField.Interface()) 350 | } 351 | } else if fromField.Kind() == reflect.Bool && toField.Kind() == reflect.String { 352 | tag := toFieldType.Tag.Get("bool") 353 | switch tag { 354 | case "yes": 355 | toField.SetString(toBoolString(fromField.Interface().(bool), "yes", "no")) 356 | break 357 | case "enabled": 358 | toField.SetString(toBoolString(fromField.Interface().(bool), "enabled", "disabled")) 359 | break 360 | case "true": 361 | toField.SetString(toBoolString(fromField.Interface().(bool), "true", "false")) 362 | break 363 | } 364 | } else if b, ok := fromField.Interface().(*bool); ok && toField.Kind() == reflect.String { 365 | if b == nil { 366 | continue 367 | } 368 | 369 | tag := toFieldType.Tag.Get("bool") 370 | switch tag { 371 | case "yes": 372 | toField.SetString(toBoolString(*b, "yes", "no")) 373 | break 374 | case "enabled": 375 | toField.SetString(toBoolString(*b, "enabled", "disabled")) 376 | break 377 | case "true": 378 | toField.SetString(toBoolString(*b, "true", "false")) 379 | break 380 | } 381 | } else { 382 | return fmt.Errorf("Unknown type conversion %s -> %s", fromField.Kind(), toField.Kind()) 383 | } 384 | } 385 | return nil 386 | } 387 | 388 | func toBoolString(b bool, trueStr, falseStr string) string { 389 | if b { 390 | return trueStr 391 | } 392 | return falseStr 393 | } 394 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/cm.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // Devices contains a list of every device on the BIG-IP system. 8 | type Devices struct { 9 | Devices []Device `json:"items"` 10 | } 11 | 12 | 13 | // Device contains information about each individual device. 14 | type Device struct { 15 | Name string `json:"name,omitempty"` 16 | Partition string `json:"partition,omitempty"` 17 | FullPath string `json:"fullPath,omitempty"` 18 | Generation int `json:"generation,omitempty"` 19 | FailoverState string `json:"failoverState,omitempty"` 20 | Hostname string `json:"hostname,omitempty"` 21 | ManagementIp string `json:"managementIp,omitempty"` 22 | SelfDevice string `json:"selfDevice,omitempty"` 23 | } 24 | 25 | type ConfigSync struct { 26 | Command string `json:"command,omitempty"` 27 | UtilCmdArgs string `json:"utilCmdArgs,omitempty"` 28 | } 29 | 30 | const ( 31 | uriCm = "cm" 32 | uriDevice = "device" 33 | ) 34 | 35 | // Devices returns a list of devices. 36 | func (b *BigIP) Devices() (*Devices, error) { 37 | var devices Devices 38 | err, _ := b.getForEntity(&devices, uriCm, uriDevice) 39 | 40 | if err != nil { 41 | return nil, err 42 | } 43 | 44 | return &devices, nil 45 | } 46 | 47 | // GetCurrentDevice returns a current device. 48 | func (b *BigIP) GetCurrentDevice() (*Device, error) { 49 | devices, err := b.Devices() 50 | if err != nil { 51 | return nil, err 52 | } 53 | for _, d := range devices.Devices { 54 | // f5 api is returning bool value as string 55 | if d.SelfDevice == "true" { 56 | return &d, nil 57 | } 58 | } 59 | return nil, errors.New("could not find this device") 60 | } 61 | 62 | // ConfigSyncToGroup runs command config-sync to-group 63 | func (b *BigIP) ConfigSyncToGroup(name string) error { 64 | args := "config-sync to-group "+name 65 | config := &ConfigSync{ 66 | Command: "run", 67 | UtilCmdArgs: args, 68 | } 69 | return b.post(config, uriCm) 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/net.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // Interfaces contains a list of every interface on the BIG-IP system. 8 | type Interfaces struct { 9 | Interfaces []Interface `json:"items"` 10 | } 11 | 12 | // Interface contains information about each individual interface. 13 | type Interface struct { 14 | Name string `json:"name,omitempty"` 15 | FullPath string `json:"fullPath,omitempty"` 16 | Generation int `json:"generation,omitempty"` 17 | Bundle string `json:"bundle,omitempty"` 18 | Enabled bool `json:"enabled,omitempty"` 19 | FlowControl string `json:"flowControl,omitempty"` 20 | ForceGigabitFiber string `json:"forceGigabitFiber,omitempty"` 21 | IfIndex int `json:"ifIndex,omitempty"` 22 | LLDPAdmin string `json:"lldpAdmin,omitempty"` 23 | LLDPTlvmap int `json:"lldpTlvmap,omitempty"` 24 | MACAddress string `json:"macAddress,omitempty"` 25 | MediaActive string `json:"mediaActive,omitempty"` 26 | MediaFixed string `json:"mediaFixed,omitempty"` 27 | MediaMax string `json:"mediaMax,omitempty"` 28 | MediaSFP string `json:"mediaSfp,omitempty"` 29 | MTU int `json:"mtu,omitempty"` 30 | PreferPort string `json:"preferPort,omitempty"` 31 | SFlow struct { 32 | PollInterval int `json:"pollInterval,omitempty"` 33 | PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"` 34 | } `json:"sflow,omitempty"` 35 | STP string `json:"stp,omitempty"` 36 | STPAutoEdgePort string `json:"stpAutoEdgePort,omitempty"` 37 | STPEdgePort string `json:"stpEdgePort,omitempty"` 38 | STPLinkType string `json:"stpLinkType,omitempty"` 39 | } 40 | 41 | // SelfIPs contains a list of every self IP on the BIG-IP system. 42 | type SelfIPs struct { 43 | SelfIPs []SelfIP `json:"items"` 44 | } 45 | 46 | // SelfIP contains information about each individual self IP. You can use all of 47 | // these fields when modifying a self IP. 48 | type SelfIP struct { 49 | Name string `json:"name,omitempty"` 50 | Partition string `json:"partition,omitempty"` 51 | FullPath string `json:"fullPath,omitempty"` 52 | Generation int `json:"generation,omitempty"` 53 | Address string `json:"address,omitempty"` 54 | Floating string `json:"floating,omitempty"` 55 | InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty"` 56 | TrafficGroup string `json:"trafficGroup,omitempty"` 57 | Unit int `json:"unit,omitempty"` 58 | Vlan string `json:"vlan,omitempty"` 59 | // AllowService []string `json:"allowService"` 60 | } 61 | 62 | // Trunks contains a list of every trunk on the BIG-IP system. 63 | type Trunks struct { 64 | Trunks []Trunk `json:"items"` 65 | } 66 | 67 | // Trunk contains information about each individual trunk. You can use all of 68 | // these fields when modifying a trunk. 69 | type Trunk struct { 70 | Name string `json:"name,omitempty"` 71 | FullPath string `json:"fullPath,omitempty"` 72 | Generation int `json:"generation,omitempty"` 73 | Bandwidth int `json:"bandwidth,omitempty"` 74 | MemberCount int `json:"cfgMbrCount,omitempty"` 75 | DistributionHash string `json:"distributionHash,omitempty"` 76 | ID int `json:"id,omitempty"` 77 | LACP string `json:"lacp,omitempty"` 78 | LACPMode string `json:"lacpMode,omitempty"` 79 | LACPTimeout string `json:"lacpTimeout,omitempty"` 80 | LinkSelectPolicy string `json:"linkSelectPolicy,omitempty"` 81 | MACAddress string `json:"macAddress,omitempty"` 82 | STP string `json:"stp,omitempty"` 83 | Type string `json:"type,omitempty"` 84 | WorkingMemberCount int `json:"workingMbrCount,omitempty"` 85 | Interfaces []string `json:"interfaces,omitempty"` 86 | } 87 | 88 | // Vlans contains a list of every VLAN on the BIG-IP system. 89 | type Vlans struct { 90 | Vlans []Vlan `json:"items"` 91 | } 92 | 93 | // Vlan contains information about each individual VLAN. You can use all of 94 | // these fields when modifying a VLAN. 95 | type Vlan struct { 96 | Name string `json:"name,omitempty"` 97 | Partition string `json:"partition,omitempty"` 98 | FullPath string `json:"fullPath,omitempty"` 99 | Generation int `json:"generation,omitempty"` 100 | AutoLastHop string `json:"autoLastHop,omitempty"` 101 | CMPHash string `json:"cmpHash,omitempty"` 102 | DAGRoundRobin string `json:"dagRoundRobin,omitempty"` 103 | Failsafe string `json:"failsafe,omitempty"` 104 | FailsafeAction string `json:"failsafeAction,omitempty"` 105 | FailsafeTimeout int `json:"failsafeTimeout,omitempty"` 106 | IfIndex int `json:"ifIndex,omitempty"` 107 | Learning string `json:"learning,omitempty"` 108 | MTU int `json:"mtu,omitempty"` 109 | SFlow struct { 110 | PollInterval int `json:"pollInterval,omitempty"` 111 | PollIntervalGlobal string `json:"pollIntervalGlobal,omitempty"` 112 | SamplingRate int `json:"samplingRate,omitempty"` 113 | SamplingRateGlobal string `json:"samplingRateGlobal,omitempty"` 114 | } `json:"sflow,omitempty"` 115 | SourceChecking string `json:"sourceChecking,omitempty"` 116 | Tag int `json:"tag,omitempty"` 117 | } 118 | 119 | // VlanInterface contains fields to be used when adding an interface to a VLAN. 120 | type VlanInterface struct { 121 | Name string `json:"name,omitempty"` 122 | Tagged bool `json:"tagged,omitempty"` 123 | Untagged bool `json:"untagged,omitempty"` 124 | } 125 | 126 | // Routes contains a list of every route on the BIG-IP system. 127 | type Routes struct { 128 | Routes []Route `json:"items"` 129 | } 130 | 131 | // Route contains information about each individual route. You can use all 132 | // of these fields when modifying a route. 133 | type Route struct { 134 | Name string `json:"name,omitempty"` 135 | Partition string `json:"partition,omitempty"` 136 | FullPath string `json:"fullPath,omitempty"` 137 | Generation int `json:"generation,omitempty"` 138 | MTU int `json:"mtu,omitempty"` 139 | Network string `json:"network,omitempty"` 140 | 141 | // Mutually exclusive fields 142 | Blackhole bool `json:"blackhole,omitempty"` 143 | Gateway string `json:"gw,omitempty"` 144 | Pool string `json:"pool,omitempty"` 145 | Interface string `json:"tmInterface,omitempty"` 146 | } 147 | 148 | // RouteDomains contains a list of every route domain on the BIG-IP system. 149 | type RouteDomains struct { 150 | RouteDomains []RouteDomain `json:"items"` 151 | } 152 | 153 | // RouteDomain contains information about each individual route domain. You can use all 154 | // of these fields when modifying a route domain. 155 | type RouteDomain struct { 156 | Name string `json:"name,omitempty"` 157 | Partition string `json:"partition,omitempty"` 158 | FullPath string `json:"fullPath,omitempty"` 159 | Generation int `json:"generation,omitempty"` 160 | ID int `json:"id,omitempty"` 161 | Strict string `json:"strict,omitempty"` 162 | Vlans []string `json:"vlans,omitempty"` 163 | } 164 | 165 | const ( 166 | uriNet = "net" 167 | uriInterface = "interface" 168 | uriSelf = "self" 169 | uriTrunk = "trunk" 170 | uriVlan = "vlan" 171 | uriRoute = "route" 172 | uriRouteDomain = "route-domain" 173 | ) 174 | 175 | // Interfaces returns a list of interfaces. 176 | func (b *BigIP) Interfaces() (*Interfaces, error) { 177 | var interfaces Interfaces 178 | err, _ := b.getForEntity(&interfaces, uriNet, uriInterface) 179 | 180 | if err != nil { 181 | return nil, err 182 | } 183 | 184 | return &interfaces, nil 185 | } 186 | 187 | // AddInterfaceToVlan associates the given interface to the specified VLAN. 188 | func (b *BigIP) AddInterfaceToVlan(vlan, iface string, tagged bool) error { 189 | config := &VlanInterface{} 190 | 191 | config.Name = iface 192 | if tagged { 193 | config.Tagged = true 194 | } else { 195 | config.Untagged = true 196 | } 197 | 198 | return b.put(config, uriNet, uriVlan, vlan, "interfaces") 199 | } 200 | 201 | // SelfIPs returns a list of self IP's. 202 | func (b *BigIP) SelfIPs() (*SelfIPs, error) { 203 | var self SelfIPs 204 | err, _ := b.getForEntity(&self, uriNet, uriSelf) 205 | if err != nil { 206 | return nil, err 207 | } 208 | 209 | return &self, nil 210 | } 211 | 212 | // CreateSelfIP adds a new self IP to the BIG-IP system. For
, you 213 | // must include the subnet mask in CIDR notation, i.e.: "10.1.1.1/24". 214 | func (b *BigIP) CreateSelfIP(name, address, vlan string) error { 215 | config := &SelfIP{ 216 | Name: name, 217 | Address: address, 218 | Vlan: vlan, 219 | } 220 | 221 | return b.post(config, uriNet, uriSelf) 222 | } 223 | 224 | // DeleteSelfIP removes a self IP. 225 | func (b *BigIP) DeleteSelfIP(name string) error { 226 | return b.delete(uriNet, uriSelf, name) 227 | } 228 | 229 | // ModifySelfIP allows you to change any attribute of a self IP. Fields that 230 | // can be modified are referenced in the SelfIP struct. 231 | func (b *BigIP) ModifySelfIP(name string, config *SelfIP) error { 232 | return b.put(config, uriNet, uriSelf, name) 233 | } 234 | 235 | // Trunks returns a list of trunks. 236 | func (b *BigIP) Trunks() (*Trunks, error) { 237 | var trunks Trunks 238 | err, _ := b.getForEntity(&trunks, uriNet, uriTrunk) 239 | if err != nil { 240 | return nil, err 241 | } 242 | 243 | return &trunks, nil 244 | } 245 | 246 | // CreateTrunk adds a new trunk to the BIG-IP system. must be 247 | // separated by a comma, i.e.: "1.4, 1.6, 1.8". 248 | func (b *BigIP) CreateTrunk(name, interfaces string, lacp bool) error { 249 | rawInts := strings.Split(interfaces, ",") 250 | ints := []string{} 251 | 252 | for _, i := range rawInts { 253 | ints = append(ints, strings.Trim(i, " ")) 254 | } 255 | 256 | config := &Trunk{ 257 | Name: name, 258 | Interfaces: ints, 259 | } 260 | 261 | if lacp { 262 | config.LACP = "enabled" 263 | } 264 | 265 | return b.post(config, uriNet, uriTrunk) 266 | } 267 | 268 | // DeleteTrunk removes a trunk. 269 | func (b *BigIP) DeleteTrunk(name string) error { 270 | return b.delete(uriNet, uriTrunk, name) 271 | } 272 | 273 | // ModifyTrunk allows you to change any attribute of a trunk. Fields that 274 | // can be modified are referenced in the Trunk struct. 275 | func (b *BigIP) ModifyTrunk(name string, config *Trunk) error { 276 | return b.put(config, uriNet, uriTrunk, name) 277 | } 278 | 279 | // Vlans returns a list of vlans. 280 | func (b *BigIP) Vlans() (*Vlans, error) { 281 | var vlans Vlans 282 | err, _ := b.getForEntity(&vlans, uriNet, uriVlan) 283 | 284 | if err != nil { 285 | return nil, err 286 | } 287 | 288 | return &vlans, nil 289 | } 290 | 291 | // CreateVlan adds a new VLAN to the BIG-IP system. 292 | func (b *BigIP) CreateVlan(name string, tag int) error { 293 | config := &Vlan{ 294 | Name: name, 295 | Tag: tag, 296 | } 297 | 298 | return b.post(config, uriNet, uriVlan) 299 | } 300 | 301 | // DeleteVlan removes a vlan. 302 | func (b *BigIP) DeleteVlan(name string) error { 303 | return b.delete(uriNet, uriVlan, name) 304 | } 305 | 306 | // ModifyVlan allows you to change any attribute of a VLAN. Fields that 307 | // can be modified are referenced in the Vlan struct. 308 | func (b *BigIP) ModifyVlan(name string, config *Vlan) error { 309 | return b.put(config, uriNet, uriVlan, name) 310 | } 311 | 312 | // Routes returns a list of routes. 313 | func (b *BigIP) Routes() (*Routes, error) { 314 | var routes Routes 315 | err, _ := b.getForEntity(&routes, uriNet, uriRoute) 316 | 317 | if err != nil { 318 | return nil, err 319 | } 320 | 321 | return &routes, nil 322 | } 323 | 324 | // CreateRoute adds a new static route to the BIG-IP system. must include the 325 | // subnet mask in CIDR notation, i.e.: "10.1.1.0/24". 326 | func (b *BigIP) CreateRoute(name, dest, gateway string) error { 327 | config := &Route{ 328 | Name: name, 329 | Network: dest, 330 | Gateway: gateway, 331 | } 332 | 333 | return b.post(config, uriNet, uriRoute) 334 | } 335 | 336 | // AddRoute adds a new static route to the BIG-IP system. 337 | func (b *BigIP) AddRoute(config *Route) error { 338 | return b.post(config, uriNet, uriRoute) 339 | } 340 | 341 | // GetRoute gets a static route. 342 | func (b *BigIP) GetRoute(name string) (*Route, error) { 343 | var route Route 344 | err, _ := b.getForEntity(&route, uriNet, uriRoute, name) 345 | 346 | if err != nil { 347 | return nil, err 348 | } 349 | 350 | return &route, nil 351 | } 352 | 353 | // DeleteRoute removes a static route. 354 | func (b *BigIP) DeleteRoute(name string) error { 355 | return b.delete(uriNet, uriRoute, name) 356 | } 357 | 358 | // ModifyRoute allows you to change any attribute of a static route. Fields that 359 | // can be modified are referenced in the Route struct. 360 | func (b *BigIP) ModifyRoute(name string, config *Route) error { 361 | return b.put(config, uriNet, uriRoute, name) 362 | } 363 | 364 | // RouteDomains returns a list of route domains. 365 | func (b *BigIP) RouteDomains() (*RouteDomains, error) { 366 | var rd RouteDomains 367 | err, _ := b.getForEntity(&rd, uriNet, uriRouteDomain) 368 | 369 | if err != nil { 370 | return nil, err 371 | } 372 | 373 | return &rd, nil 374 | } 375 | 376 | // CreateRouteDomain adds a new route domain to the BIG-IP system. must be separated 377 | // by a comma, i.e.: "vlan1010, vlan1020". 378 | func (b *BigIP) CreateRouteDomain(name string, id int, strict bool, vlans string) error { 379 | strictIsolation := "enabled" 380 | vlanMembers := []string{} 381 | rawVlans := strings.Split(vlans, ",") 382 | 383 | for _, v := range rawVlans { 384 | vlanMembers = append(vlanMembers, strings.Trim(v, " ")) 385 | } 386 | 387 | if !strict { 388 | strictIsolation = "disabled" 389 | } 390 | 391 | config := &RouteDomain{ 392 | Name: name, 393 | ID: id, 394 | Strict: strictIsolation, 395 | Vlans: vlanMembers, 396 | } 397 | 398 | return b.post(config, uriNet, uriRouteDomain) 399 | } 400 | 401 | // DeleteRouteDomain removes a route domain. 402 | func (b *BigIP) DeleteRouteDomain(name string) error { 403 | return b.delete(uriNet, uriRouteDomain, name) 404 | } 405 | 406 | // ModifyRouteDomain allows you to change any attribute of a route domain. Fields that 407 | // can be modified are referenced in the RouteDomain struct. 408 | func (b *BigIP) ModifyRouteDomain(name string, config *RouteDomain) error { 409 | return b.put(config, uriNet, uriRouteDomain, name) 410 | } 411 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/shared.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | const ( 9 | uriClientSSL = "client-ssl" 10 | uriDatagroup = "data-group" 11 | uriHttp = "http" 12 | uriHttpCompression = "http-compression" 13 | uriIRule = "rule" 14 | uriInternal = "internal" 15 | uriLtm = "ltm" 16 | uriMonitor = "monitor" 17 | uriNode = "node" 18 | uriOneConnect = "one-connect" 19 | uriPolicy = "policy" 20 | uriPool = "pool" 21 | uriPoolMember = "members" 22 | uriProfile = "profile" 23 | uriServerSSL = "server-ssl" 24 | uriSnatPool = "snatpool" 25 | uriTcp = "tcp" 26 | uriUdp = "udp" 27 | uriVirtual = "virtual" 28 | uriVirtualAddress = "virtual-address" 29 | uriGtm = "gtm" 30 | uriWideIp = "wideip" 31 | uriARecord = "a" 32 | uriAAAARecord = "aaaa" 33 | uriCNameRecord = "cname" 34 | uriMXRecord = "mx" 35 | uriNaptrRecord = "naptr" 36 | uriSrvRecord = "srv" 37 | uriPoolMembers = "members" 38 | ENABLED = "enable" 39 | DISABLED = "disable" 40 | CONTEXT_SERVER = "serverside" 41 | CONTEXT_CLIENT = "clientside" 42 | CONTEXT_ALL = "all" 43 | 44 | // Newer policy APIs have a draft-publish workflow that this library does not support. 45 | policyVersionSuffix = "?ver=11.5.1" 46 | ) 47 | 48 | var cidr = map[string]string{ 49 | "0": "0.0.0.0", 50 | "1": "128.0.0.0", 51 | "2": "192.0.0.0", 52 | "3": "224.0.0.0", 53 | "4": "240.0.0.0", 54 | "5": "248.0.0.0", 55 | "6": "252.0.0.0", 56 | "7": "254.0.0.0", 57 | "8": "255.0.0.0", 58 | "9": "255.128.0.0", 59 | "10": "255.192.0.0", 60 | "11": "255.224.0.0", 61 | "12": "255.240.0.0", 62 | "13": "255.248.0.0", 63 | "14": "255.252.0.0", 64 | "15": "255.254.0.0", 65 | "16": "255.255.0.0", 66 | "17": "255.255.128.0", 67 | "18": "255.255.192.0", 68 | "19": "255.255.224.0", 69 | "20": "255.255.240.0", 70 | "21": "255.255.248.0", 71 | "22": "255.255.252.0", 72 | "23": "255.255.254.0", 73 | "24": "255.255.255.0", 74 | "25": "255.255.255.128", 75 | "26": "255.255.255.192", 76 | "27": "255.255.255.224", 77 | "28": "255.255.255.240", 78 | "29": "255.255.255.248", 79 | "30": "255.255.255.252", 80 | "31": "255.255.255.254", 81 | "32": "255.255.255.255", 82 | } 83 | 84 | // GTMType handles the record types possible in the GTM as strings 85 | type GTMType string 86 | 87 | // GTM Record Types 88 | const ( 89 | ARecord GTMType = uriARecord 90 | AAAARecord GTMType = uriAAAARecord 91 | CNAMERecord GTMType = uriCNameRecord 92 | MXRecord GTMType = uriMXRecord 93 | NAPTRRecord GTMType = uriNaptrRecord 94 | SRVRecord GTMType = uriSrvRecord 95 | ) 96 | 97 | const ( 98 | uriShared = "shared" 99 | uriLicensing = "licensing" 100 | uriActivation = "activation" 101 | uriRegistration = "registration" 102 | 103 | activationComplete = "LICENSING_COMPLETE" 104 | activationInProgress = "LICENSING_ACTIVATION_IN_PROGRESS" 105 | activationFailed = "LICENSING_FAILED" 106 | activationNeedEula = "NEED_EULA_ACCEPT" 107 | ) 108 | 109 | // https://devcentral.f5.com/wiki/iControl.Licensing_resource_API.ashx 110 | type Activation struct { 111 | BaseRegKey string `json:"baseRegKey,omitempty"` 112 | AddOnKeys []string `json:"addOnKeys,omitempty"` 113 | IsAutomaticActivation bool `json:"isAutomaticActivation"` 114 | Status string `json:"status,omitempty"` 115 | LicenseText *string `json:"licenseText,omitempty"` 116 | ErrorText *string `json:"errorText,omitempty"` 117 | EulaText *string `json:"eulaText,omitempty"` 118 | } 119 | 120 | // https://devcentral.f5.com/wiki/iControl.Licensing_resource_API.ashx 121 | type LicenseState struct { 122 | Vendor string `json:"vendor"` 123 | 124 | LicensedDateTime string `json:"licensedDateTime"` 125 | LicensedVersion string `json:"licensedVersion"` 126 | LicenseEndDateTime string `json:"licenseEndDateTime"` 127 | LicenseStartDateTime string `json:"licenseStartDateTime"` 128 | 129 | RegistrationKey string `json:"registrationKey"` 130 | Dossier string `json:"dossier"` 131 | Authorization string `json:"authorization"` 132 | Usage string `json:"usage"` 133 | PlatformId string `json:"platformId"` 134 | AuthVers string `json:"authVers"` 135 | ServiceCheckDateTime string `json:"serviceCheckDateTime"` 136 | MachineId string `json:"machineId"` 137 | ExclusivePlatform []string `json:"exclusivePlatform"` 138 | 139 | ActiveModules []string `json:"activeModules"` 140 | OptionalModules []string `json:"optionalModules"` 141 | FeatureFlags []LicenseFeatureFlag `json:"featureFlags"` 142 | 143 | ExpiresInDays string `json:"expiresInDays"` 144 | ExpiresInDaysMessage string `json:"expiresInDaysMessage"` 145 | } 146 | 147 | // Describes feature flags that are defined in licenses. 148 | type LicenseFeatureFlag struct { 149 | FeatureName string `json:"featureName"` 150 | FeatureValue string `json:"featureValue"` 151 | } 152 | 153 | // Gets the current activation status. Use after calling Activate. See the docs for more: 154 | // https://devcentral.f5.com/wiki/iControl.Licensing_activation_APIs.ashx 155 | func (b *BigIP) GetActivationStatus() (*Activation, error) { 156 | var a Activation 157 | err, _ := b.getForEntity(&a, uriShared, uriLicensing, uriActivation) 158 | if err != nil { 159 | return nil, err 160 | } 161 | return &a, nil 162 | } 163 | 164 | // Sends the Activation to the activation endpoint. For documentation on how this works, see: 165 | // https://devcentral.f5.com/wiki/iControl.Licensing_activation_APIs.ashx 166 | func (b *BigIP) Activate(a Activation) error { 167 | return b.post(a, uriShared, uriLicensing, uriActivation) 168 | } 169 | 170 | // Returns the current license state. 171 | func (b *BigIP) GetLicenseState() (*LicenseState, error) { 172 | var l LicenseState 173 | err, _ := b.getForEntity(&l, uriShared, uriLicensing, uriRegistration) 174 | if err != nil { 175 | return nil, err 176 | } 177 | return &l, nil 178 | } 179 | 180 | // Installs the given license. 181 | func (b *BigIP) InstallLicense(licenseText string) error { 182 | r := map[string]string{"licenseText": licenseText} 183 | return b.put(r, uriShared, uriLicensing, uriRegistration) 184 | } 185 | 186 | // Automatically activate this registration key and install the resulting license. 187 | // The BIG-IP must have access to the activation server for this to work. 188 | func (b *BigIP) AutoLicense(regKey string, addOnKeys []string, timeout time.Duration) error { 189 | deadline := time.Now().Add(timeout) 190 | actreq := Activation{BaseRegKey: regKey, AddOnKeys: addOnKeys, IsAutomaticActivation: true} 191 | 192 | if err := b.Activate(actreq); err != nil { 193 | return err 194 | } 195 | 196 | loop: 197 | for time.Now().Before(deadline) { 198 | actresp, err := b.GetActivationStatus() 199 | if err != nil { 200 | return err 201 | } 202 | 203 | if actresp.Status == activationInProgress { 204 | time.Sleep(1 * time.Second) 205 | continue 206 | } 207 | 208 | switch actresp.Status { 209 | case activationComplete: 210 | return b.InstallLicense(*actresp.LicenseText) 211 | case activationFailed: 212 | return fmt.Errorf("Licensing failed: %s", *actresp.ErrorText) 213 | case activationNeedEula: 214 | eula := *actresp.EulaText 215 | actreq.EulaText = &eula 216 | break loop 217 | default: 218 | return fmt.Errorf("Unknown licensing status: %s", actresp.Status) 219 | } 220 | } 221 | 222 | if actreq.EulaText == nil { 223 | return fmt.Errorf("Timed out after %s", timeout) 224 | } 225 | 226 | // Proceed with EULA acceptance 227 | if err := b.Activate(actreq); err != nil { 228 | return err 229 | } 230 | 231 | for time.Now().Before(deadline) { 232 | actresp, err := b.GetActivationStatus() 233 | if err != nil { 234 | return err 235 | } 236 | 237 | if actresp.Status == activationInProgress { 238 | time.Sleep(1 * time.Second) 239 | continue 240 | } 241 | 242 | switch actresp.Status { 243 | case activationComplete: 244 | return b.InstallLicense(*actresp.LicenseText) 245 | case activationNeedEula: 246 | return fmt.Errorf("Tried to accept EULA, but status is: %s", *actresp.ErrorText) 247 | case activationFailed: 248 | return fmt.Errorf("Licensing failed: %s", *actresp.ErrorText) 249 | } 250 | return fmt.Errorf("Unknown licensing status: %s", actresp.Status) 251 | } 252 | 253 | return fmt.Errorf("Timed out after %s", timeout) 254 | } 255 | -------------------------------------------------------------------------------- /vendor/github.com/scottdware/go-bigip/sys.go: -------------------------------------------------------------------------------- 1 | package bigip 2 | 3 | import "encoding/json" 4 | 5 | const ( 6 | uriSys = "sys" 7 | uriFolder = "folder" 8 | uriSyslog = "syslog" 9 | uriSoftware = "software" 10 | uriVolume = "volume" 11 | uriHardware = "hardware" 12 | uriGlobalSettings = "global-settings" 13 | uriManagementIp = "management-ip" 14 | //uriPlatform = "?$select=platform" 15 | ) 16 | 17 | type Volumes struct { 18 | Volumes []Volume `json:"items,omitempty"` 19 | } 20 | 21 | type Volume struct { 22 | Name string `json:"items,omitempty"` 23 | FullPath string `json:"fullPath,omitempty"` 24 | Generation int `json:"generation,omitempty"` 25 | SelfLink string `json:"selfLink,omitempty"` 26 | Active bool `json:"active,omitempty"` 27 | BaseBuild string `json:"basebuild,omitempty"` 28 | Build string `json:"build,omitempty"` 29 | Product string `json:"product,omitempty"` 30 | Status string `json:"status,omitempty"` 31 | Version string `json:"version,omitempty"` 32 | } 33 | 34 | // Volumes returns a list of Software Volumes. 35 | func (b *BigIP) Volumes() (*Volumes, error) { 36 | var volumes Volumes 37 | err, _ := b.getForEntity(&volumes, uriSys, uriSoftware, uriVolume) 38 | if err != nil { 39 | return nil, err 40 | } 41 | 42 | return &volumes, nil 43 | } 44 | 45 | type ManagementIP struct { 46 | Addresses []ManagementIPAddress 47 | } 48 | 49 | type ManagementIPAddress struct { 50 | Name string `json:"items,omitempty"` 51 | FullPath string `json:"fullPath,omitempty"` 52 | Generation int `json:"generation,omitempty"` 53 | SelfLink string `json:"selfLink,omitempty"` 54 | } 55 | 56 | func (b *BigIP) ManagementIPs() (*ManagementIP, error) { 57 | var managementIP ManagementIP 58 | err, _ := b.getForEntity(&managementIP, uriSys, uriManagementIp) 59 | if err != nil { 60 | return nil, err 61 | } 62 | 63 | return &managementIP, nil 64 | } 65 | 66 | type SyslogRemoteServer struct { 67 | Name string `json:"name,omitempty"` 68 | Host string `json:"host,omitempty"` 69 | LocalIP string `json:"localIp,omitempty"` 70 | RemotePort int `json:"remotePort,omitempty"` 71 | } 72 | 73 | type Syslog struct { 74 | SelfLink string `json:"selfLink,omitempty"` 75 | RemoteServers []SyslogRemoteServer `json:"remoteServers,omitempty"` 76 | } 77 | 78 | func (b *BigIP) Syslog() (*Syslog, error) { 79 | var syslog Syslog 80 | 81 | err, _ := b.getForEntity(&syslog, uriSys, uriSyslog) 82 | if err != nil { 83 | return nil, err 84 | } 85 | 86 | return &syslog, nil 87 | } 88 | 89 | func (b *BigIP) SetSyslog(config Syslog) error { 90 | return b.put(config, uriSys, uriSyslog) 91 | } 92 | 93 | // Folders contains a list of every folder on the BIG-IP system. 94 | type Folders struct { 95 | Folders []Folder `json:"items"` 96 | } 97 | 98 | type folderDTO struct { 99 | Name string `json:"name,omitempty"` 100 | Partition string `json:"partition,omitempty"` 101 | SubPath string `json:"subPath,omitempty"` 102 | FullPath string `json:"fullPath,omitempty"` 103 | 104 | AppService string `json:"appService,omitempty"` 105 | Description string `json:"description,omitempty"` 106 | // Set to "default" to inherit or a device group name to control. You can also set it to "non-default" to pin its device group to its current setting and turn off inheritance. 107 | DeviceGroup string `json:"deviceGroup,omitempty"` 108 | Hidden string `json:"hidden,omitempty" bool:"true"` 109 | NoRefCheck string `json:"noRefCheck,omitempty" bool:"true"` 110 | // Set to "default" to inherit or a traffic group name to control. You can also set it to "non-default" to pin its traffic group to its current setting and turn off inheritance. 111 | TrafficGroup string `json:"trafficGroup,omitempty"` 112 | 113 | // Read-only property. Set DeviceGroup to control. 114 | InheritedDeviceGroup string `json:"inheritedDevicegroup,omitempty" bool:"true"` 115 | 116 | // Read-only property. Set TrafficGroup to control. 117 | InheritedTrafficGroup string `json:"inheritedTrafficGroup,omitempty" bool:"true"` 118 | } 119 | 120 | type Folder struct { 121 | Name string `json:"name,omitempty"` 122 | Partition string `json:"partition,omitempty"` 123 | SubPath string `json:"subPath,omitempty"` 124 | FullPath string `json:"fullPath,omitempty"` 125 | 126 | AppService string `json:"appService,omitempty"` 127 | Description string `json:"description,omitempty"` 128 | DeviceGroup string `json:"deviceGroup,omitempty"` 129 | Hidden *bool `json:"hidden,omitempty"` 130 | NoRefCheck *bool `json:"noRefCheck,omitempty"` 131 | TrafficGroup string `json:"trafficGroup,omitempty"` 132 | 133 | // Read-only property. Set DeviceGroup to "default" or "non-default" to control. 134 | InheritedDeviceGroup *bool `json:"inheritedDevicegroup,omitempty"` 135 | 136 | // Read-only property. Set TrafficGroup to "default" or "non-default" to control. 137 | InheritedTrafficGroup *bool `json:"inheritedTrafficGroup,omitempty"` 138 | } 139 | 140 | func (f *Folder) MarshalJSON() ([]byte, error) { 141 | var dto folderDTO 142 | marshal(&dto, f) 143 | return json.Marshal(dto) 144 | } 145 | 146 | func (f *Folder) UnmarshalJSON(b []byte) error { 147 | var dto folderDTO 148 | err := json.Unmarshal(b, &dto) 149 | if err != nil { 150 | return err 151 | } 152 | return marshal(f, &dto) 153 | } 154 | 155 | // Folders returns a list of folders. 156 | func (b *BigIP) Folders() (*Folders, error) { 157 | var folders Folders 158 | err, _ := b.getForEntity(&folders, uriSys, uriFolder) 159 | if err != nil { 160 | return nil, err 161 | } 162 | 163 | return &folders, nil 164 | } 165 | 166 | // CreateFolder adds a new folder to the BIG-IP system. 167 | func (b *BigIP) CreateFolder(name string) error { 168 | config := &Folder{ 169 | Name: name, 170 | } 171 | 172 | return b.post(config, uriSys, uriFolder) 173 | } 174 | 175 | // AddFolder adds a new folder by config to the BIG-IP system. 176 | func (b *BigIP) AddFolder(config *Folder) error { 177 | 178 | return b.post(config, uriSys, uriFolder) 179 | } 180 | 181 | // GetFolder retrieves a Folder by name. Returns nil if the folder does not exist 182 | func (b *BigIP) GetFolder(name string) (*Folder, error) { 183 | var folder Folder 184 | err, ok := b.getForEntity(&folder, uriSys, uriFolder, name) 185 | if err != nil { 186 | return nil, err 187 | } 188 | if !ok { 189 | return nil, nil 190 | } 191 | 192 | return &folder, nil 193 | } 194 | 195 | // DeleteFolder removes a folder. 196 | func (b *BigIP) DeleteFolder(name string) error { 197 | return b.delete(uriSys, uriFolder, name) 198 | } 199 | 200 | // ModifyFolder allows you to change any attribute of a folder. Fields that can 201 | // be modified are referenced in the Folder struct. This replaces the existing 202 | // configuration, so use PatchFolder if you want to change only particular 203 | // attributes. 204 | func (b *BigIP) ModifyFolder(name string, config *Folder) error { 205 | return b.put(config, uriSys, uriFolder, name) 206 | } 207 | 208 | // PatchFolder allows you to change any attribute of a folder. Fields that can 209 | // be modified are referenced in the Folder struct. This changes only the 210 | // attributes provided, so use ModifyFolder if you want to replace the existing 211 | // configuration. 212 | func (b *BigIP) PatchFolder(name string, config *Folder) error { 213 | return b.patch(config, uriSys, uriFolder, name) 214 | } 215 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell 2 | 3 | Please consider promoting this project if you find it useful. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 21 | OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 22 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/stretchr/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/stretchr/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/http_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/http/httptest" 7 | "net/url" 8 | "strings" 9 | ) 10 | 11 | // httpCode is a helper that returns HTTP code of the response. It returns -1 and 12 | // an error if building a new request fails. 13 | func httpCode(handler http.HandlerFunc, method, url string, values url.Values) (int, error) { 14 | w := httptest.NewRecorder() 15 | req, err := http.NewRequest(method, url, nil) 16 | if err != nil { 17 | return -1, err 18 | } 19 | req.URL.RawQuery = values.Encode() 20 | handler(w, req) 21 | return w.Code, nil 22 | } 23 | 24 | // HTTPSuccess asserts that a specified handler returns a success status code. 25 | // 26 | // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) 27 | // 28 | // Returns whether the assertion was successful (true) or not (false). 29 | func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { 30 | if h, ok := t.(tHelper); ok { 31 | h.Helper() 32 | } 33 | code, err := httpCode(handler, method, url, values) 34 | if err != nil { 35 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) 36 | return false 37 | } 38 | 39 | isSuccessCode := code >= http.StatusOK && code <= http.StatusPartialContent 40 | if !isSuccessCode { 41 | Fail(t, fmt.Sprintf("Expected HTTP success status code for %q but received %d", url+"?"+values.Encode(), code)) 42 | } 43 | 44 | return isSuccessCode 45 | } 46 | 47 | // HTTPRedirect asserts that a specified handler returns a redirect status code. 48 | // 49 | // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 50 | // 51 | // Returns whether the assertion was successful (true) or not (false). 52 | func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { 53 | if h, ok := t.(tHelper); ok { 54 | h.Helper() 55 | } 56 | code, err := httpCode(handler, method, url, values) 57 | if err != nil { 58 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) 59 | return false 60 | } 61 | 62 | isRedirectCode := code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect 63 | if !isRedirectCode { 64 | Fail(t, fmt.Sprintf("Expected HTTP redirect status code for %q but received %d", url+"?"+values.Encode(), code)) 65 | } 66 | 67 | return isRedirectCode 68 | } 69 | 70 | // HTTPError asserts that a specified handler returns an error status code. 71 | // 72 | // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 73 | // 74 | // Returns whether the assertion was successful (true) or not (false). 75 | func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { 76 | if h, ok := t.(tHelper); ok { 77 | h.Helper() 78 | } 79 | code, err := httpCode(handler, method, url, values) 80 | if err != nil { 81 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) 82 | return false 83 | } 84 | 85 | isErrorCode := code >= http.StatusBadRequest 86 | if !isErrorCode { 87 | Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code)) 88 | } 89 | 90 | return isErrorCode 91 | } 92 | 93 | // HTTPBody is a helper that returns HTTP body of the response. It returns 94 | // empty string if building a new request fails. 95 | func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string { 96 | w := httptest.NewRecorder() 97 | req, err := http.NewRequest(method, url+"?"+values.Encode(), nil) 98 | if err != nil { 99 | return "" 100 | } 101 | handler(w, req) 102 | return w.Body.String() 103 | } 104 | 105 | // HTTPBodyContains asserts that a specified handler returns a 106 | // body that contains a string. 107 | // 108 | // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 109 | // 110 | // Returns whether the assertion was successful (true) or not (false). 111 | func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { 112 | if h, ok := t.(tHelper); ok { 113 | h.Helper() 114 | } 115 | body := HTTPBody(handler, method, url, values) 116 | 117 | contains := strings.Contains(body, fmt.Sprint(str)) 118 | if !contains { 119 | Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) 120 | } 121 | 122 | return contains 123 | } 124 | 125 | // HTTPBodyNotContains asserts that a specified handler returns a 126 | // body that does not contain a string. 127 | // 128 | // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 129 | // 130 | // Returns whether the assertion was successful (true) or not (false). 131 | func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { 132 | if h, ok := t.(tHelper); ok { 133 | h.Helper() 134 | } 135 | body := HTTPBody(handler, method, url, values) 136 | 137 | contains := strings.Contains(body, fmt.Sprint(str)) 138 | if contains { 139 | Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) 140 | } 141 | 142 | return !contains 143 | } 144 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/doc.go: -------------------------------------------------------------------------------- 1 | // Package require implements the same assertions as the `assert` package but 2 | // stops test execution when a test fails. 3 | // 4 | // Example Usage 5 | // 6 | // The following is a complete example using require in a standard test function: 7 | // import ( 8 | // "testing" 9 | // "github.com/stretchr/testify/require" 10 | // ) 11 | // 12 | // func TestSomething(t *testing.T) { 13 | // 14 | // var a string = "Hello" 15 | // var b string = "Hello" 16 | // 17 | // require.Equal(t, a, b, "The two words should be the same.") 18 | // 19 | // } 20 | // 21 | // Assertions 22 | // 23 | // The `require` package have same global functions as in the `assert` package, 24 | // but instead of returning a boolean result they call `t.FailNow()`. 25 | // 26 | // Every assertion function also takes an optional string message as the final argument, 27 | // allowing custom error messages to be appended to the message the assertion method outputs. 28 | package require 29 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/forward_requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.Comment}} 2 | func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { 3 | if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } 4 | if h, ok := t.(tHelper); ok { h.Helper() } 5 | t.FailNow() 6 | } 7 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // TestingT is an interface wrapper around *testing.T 4 | type TestingT interface { 5 | Errorf(format string, args ...interface{}) 6 | FailNow() 7 | } 8 | 9 | type tHelper interface { 10 | Helper() 11 | } 12 | 13 | // ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful 14 | // for table driven tests. 15 | type ComparisonAssertionFunc func(TestingT, interface{}, interface{}, ...interface{}) 16 | 17 | // ValueAssertionFunc is a common function prototype when validating a single value. Can be useful 18 | // for table driven tests. 19 | type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) 20 | 21 | // BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful 22 | // for table driven tests. 23 | type BoolAssertionFunc func(TestingT, bool, ...interface{}) 24 | 25 | // ValuesAssertionFunc is a common function prototype when validating an error value. Can be useful 26 | // for table driven tests. 27 | type ErrorAssertionFunc func(TestingT, error, ...interface{}) 28 | 29 | //go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl -include-format-funcs 30 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/suite/doc.go: -------------------------------------------------------------------------------- 1 | // Package suite contains logic for creating testing suite structs 2 | // and running the methods on those structs as tests. The most useful 3 | // piece of this package is that you can create setup/teardown methods 4 | // on your testing suites, which will run before/after the whole suite 5 | // or individual tests (depending on which interface(s) you 6 | // implement). 7 | // 8 | // A testing suite is usually built by first extending the built-in 9 | // suite functionality from suite.Suite in testify. Alternatively, 10 | // you could reproduce that logic on your own if you wanted (you 11 | // just need to implement the TestingSuite interface from 12 | // suite/interfaces.go). 13 | // 14 | // After that, you can implement any of the interfaces in 15 | // suite/interfaces.go to add setup/teardown functionality to your 16 | // suite, and add any methods that start with "Test" to add tests. 17 | // Methods that do not match any suite interfaces and do not begin 18 | // with "Test" will not be run by testify, and can safely be used as 19 | // helper methods. 20 | // 21 | // Once you've built your testing suite, you need to run the suite 22 | // (using suite.Run from testify) inside any function that matches the 23 | // identity that "go test" is already looking for (i.e. 24 | // func(*testing.T)). 25 | // 26 | // Regular expression to select test suites specified command-line 27 | // argument "-run". Regular expression to select the methods 28 | // of test suites specified command-line argument "-m". 29 | // Suite object has assertion methods. 30 | // 31 | // A crude example: 32 | // // Basic imports 33 | // import ( 34 | // "testing" 35 | // "github.com/stretchr/testify/assert" 36 | // "github.com/stretchr/testify/suite" 37 | // ) 38 | // 39 | // // Define the suite, and absorb the built-in basic suite 40 | // // functionality from testify - including a T() method which 41 | // // returns the current testing context 42 | // type ExampleTestSuite struct { 43 | // suite.Suite 44 | // VariableThatShouldStartAtFive int 45 | // } 46 | // 47 | // // Make sure that VariableThatShouldStartAtFive is set to five 48 | // // before each test 49 | // func (suite *ExampleTestSuite) SetupTest() { 50 | // suite.VariableThatShouldStartAtFive = 5 51 | // } 52 | // 53 | // // All methods that begin with "Test" are run as tests within a 54 | // // suite. 55 | // func (suite *ExampleTestSuite) TestExample() { 56 | // assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) 57 | // suite.Equal(5, suite.VariableThatShouldStartAtFive) 58 | // } 59 | // 60 | // // In order for 'go test' to run this suite, we need to create 61 | // // a normal test function and pass our suite to suite.Run 62 | // func TestExampleTestSuite(t *testing.T) { 63 | // suite.Run(t, new(ExampleTestSuite)) 64 | // } 65 | package suite 66 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/suite/interfaces.go: -------------------------------------------------------------------------------- 1 | package suite 2 | 3 | import "testing" 4 | 5 | // TestingSuite can store and return the current *testing.T context 6 | // generated by 'go test'. 7 | type TestingSuite interface { 8 | T() *testing.T 9 | SetT(*testing.T) 10 | } 11 | 12 | // SetupAllSuite has a SetupSuite method, which will run before the 13 | // tests in the suite are run. 14 | type SetupAllSuite interface { 15 | SetupSuite() 16 | } 17 | 18 | // SetupTestSuite has a SetupTest method, which will run before each 19 | // test in the suite. 20 | type SetupTestSuite interface { 21 | SetupTest() 22 | } 23 | 24 | // TearDownAllSuite has a TearDownSuite method, which will run after 25 | // all the tests in the suite have been run. 26 | type TearDownAllSuite interface { 27 | TearDownSuite() 28 | } 29 | 30 | // TearDownTestSuite has a TearDownTest method, which will run after 31 | // each test in the suite. 32 | type TearDownTestSuite interface { 33 | TearDownTest() 34 | } 35 | 36 | // BeforeTest has a function to be executed right before the test 37 | // starts and receives the suite and test names as input 38 | type BeforeTest interface { 39 | BeforeTest(suiteName, testName string) 40 | } 41 | 42 | // AfterTest has a function to be executed right after the test 43 | // finishes and receives the suite and test names as input 44 | type AfterTest interface { 45 | AfterTest(suiteName, testName string) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/suite/suite.go: -------------------------------------------------------------------------------- 1 | package suite 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "reflect" 8 | "regexp" 9 | "testing" 10 | 11 | "github.com/stretchr/testify/assert" 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | var allTestsFilter = func(_, _ string) (bool, error) { return true, nil } 16 | var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run") 17 | 18 | // Suite is a basic testing suite with methods for storing and 19 | // retrieving the current *testing.T context. 20 | type Suite struct { 21 | *assert.Assertions 22 | require *require.Assertions 23 | t *testing.T 24 | } 25 | 26 | // T retrieves the current *testing.T context. 27 | func (suite *Suite) T() *testing.T { 28 | return suite.t 29 | } 30 | 31 | // SetT sets the current *testing.T context. 32 | func (suite *Suite) SetT(t *testing.T) { 33 | suite.t = t 34 | suite.Assertions = assert.New(t) 35 | suite.require = require.New(t) 36 | } 37 | 38 | // Require returns a require context for suite. 39 | func (suite *Suite) Require() *require.Assertions { 40 | if suite.require == nil { 41 | suite.require = require.New(suite.T()) 42 | } 43 | return suite.require 44 | } 45 | 46 | // Assert returns an assert context for suite. Normally, you can call 47 | // `suite.NoError(expected, actual)`, but for situations where the embedded 48 | // methods are overridden (for example, you might want to override 49 | // assert.Assertions with require.Assertions), this method is provided so you 50 | // can call `suite.Assert().NoError()`. 51 | func (suite *Suite) Assert() *assert.Assertions { 52 | if suite.Assertions == nil { 53 | suite.Assertions = assert.New(suite.T()) 54 | } 55 | return suite.Assertions 56 | } 57 | 58 | // Run takes a testing suite and runs all of the tests attached 59 | // to it. 60 | func Run(t *testing.T, suite TestingSuite) { 61 | suite.SetT(t) 62 | 63 | if setupAllSuite, ok := suite.(SetupAllSuite); ok { 64 | setupAllSuite.SetupSuite() 65 | } 66 | defer func() { 67 | if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { 68 | tearDownAllSuite.TearDownSuite() 69 | } 70 | }() 71 | 72 | methodFinder := reflect.TypeOf(suite) 73 | tests := []testing.InternalTest{} 74 | for index := 0; index < methodFinder.NumMethod(); index++ { 75 | method := methodFinder.Method(index) 76 | ok, err := methodFilter(method.Name) 77 | if err != nil { 78 | fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err) 79 | os.Exit(1) 80 | } 81 | if ok { 82 | test := testing.InternalTest{ 83 | Name: method.Name, 84 | F: func(t *testing.T) { 85 | parentT := suite.T() 86 | suite.SetT(t) 87 | if setupTestSuite, ok := suite.(SetupTestSuite); ok { 88 | setupTestSuite.SetupTest() 89 | } 90 | if beforeTestSuite, ok := suite.(BeforeTest); ok { 91 | beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name) 92 | } 93 | defer func() { 94 | if afterTestSuite, ok := suite.(AfterTest); ok { 95 | afterTestSuite.AfterTest(methodFinder.Elem().Name(), method.Name) 96 | } 97 | if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok { 98 | tearDownTestSuite.TearDownTest() 99 | } 100 | suite.SetT(parentT) 101 | }() 102 | method.Func.Call([]reflect.Value{reflect.ValueOf(suite)}) 103 | }, 104 | } 105 | tests = append(tests, test) 106 | } 107 | } 108 | runTests(t, tests) 109 | } 110 | 111 | func runTests(t testing.TB, tests []testing.InternalTest) { 112 | r, ok := t.(runner) 113 | if !ok { // backwards compatibility with Go 1.6 and below 114 | if !testing.RunTests(allTestsFilter, tests) { 115 | t.Fail() 116 | } 117 | return 118 | } 119 | 120 | for _, test := range tests { 121 | r.Run(test.Name, test.F) 122 | } 123 | } 124 | 125 | // Filtering method according to set regular expression 126 | // specified command-line argument -m 127 | func methodFilter(name string) (bool, error) { 128 | if ok, _ := regexp.MatchString("^Test", name); !ok { 129 | return false, nil 130 | } 131 | return regexp.MatchString(*matchMethod, name) 132 | } 133 | 134 | type runner interface { 135 | Run(name string, f func(t *testing.T)) bool 136 | } 137 | --------------------------------------------------------------------------------