github.com/vmware/govmomi@v0.51.0/vapi/appliance/networking/proxy.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package networking 6 7 import ( 8 "context" 9 "net/http" 10 11 "github.com/vmware/govmomi/vapi/rest" 12 ) 13 14 const applianceProxyConfigPath = "/appliance/networking/proxy" 15 const applianceNoProxyConfigPath = "/appliance/networking/noproxy" 16 17 // Manager provides convenience methods to configure appliance proxy. 18 type Manager struct { 19 *rest.Client 20 } 21 22 // NewManager creates a new Manager with the given client 23 func NewManager(client *rest.Client) *Manager { 24 return &Manager{ 25 Client: client, 26 } 27 } 28 29 // Proxy represents configuration for specific proxy - ftp, http, https. 30 type Proxy struct { 31 Server string `json:"server,omitempty"` 32 Port int `json:"port,omitempty"` 33 Username string `json:"username,omitempty"` 34 Password string `json:"password,omitempty"` 35 Enabled bool `json:"enabled,omitempty"` 36 } 37 38 // ProxyList represents configuration for vcenter proxy. 39 type ProxyList struct { 40 Ftp Proxy `json:"ftp,omitempty"` 41 Http Proxy `json:"http,omitempty"` 42 Https Proxy `json:"https,omitempty"` 43 } 44 45 // ProxyList returns all Proxy configuration. 46 func (m *Manager) ProxyList(ctx context.Context) (*ProxyList, error) { 47 var res ProxyList 48 var rawRes []struct { 49 Key string 50 Value Proxy 51 } 52 53 r := m.Resource(applianceProxyConfigPath) 54 err := m.Do(ctx, r.Request(http.MethodGet), &rawRes) 55 if err != nil { 56 return &res, err 57 } 58 59 for _, c := range rawRes { 60 switch c.Key { 61 case "http": 62 res.Http = c.Value 63 case "https": 64 res.Https = c.Value 65 case "ftp": 66 res.Ftp = c.Value 67 } 68 } 69 70 return &res, nil 71 } 72 73 // NoProxy returns all excluded servers for proxying. 74 func (m *Manager) NoProxy(ctx context.Context) ([]string, error) { 75 r := m.Resource(applianceNoProxyConfigPath) 76 var res []string 77 return res, m.Do(ctx, r.Request(http.MethodGet), &res) 78 }