// 2020 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package mydp import ( "encoding/json" "fmt" "net/url" "strconv" "github.com/kolo/xmlrpc" ) type ( // Firewall type is a specific device identifier used to provide more specific // information about the firewall type in admin.mydatapipe. // Using pointers to handle nullable strings in json response. Firewall struct { ActivationKey *string `xmlrpc:"activation_key" json:"activation_key"` AdaptSysid *string `xmlrpc:"AdaptSysid" json:"AdaptSysid"` AuthenticationKey *string `xmlrpc:"authentication_key" json:"authentication_key"` AXDeviceID *string `xmlrpc:"AXDeviceID" json:"AXDeviceID"` ChassisSerial *string `xmlrpc:"chassis_serial" json:"chassis_serial"` Colo *string `xmlrpc:"-" json:"colo"` ContractNotes *string `xmlrpc:"ContractNotes" json:"ContractNotes"` CustomerID *string `xmlrpc:"CustomerID" json:"CustomerID"` DateCreated *string `xmlrpc:"-" json:"DateCreated"` DateLastModified *string `xmlrpc:"-" json:"DateLastModified"` DeviceID *string `xmlrpc:"DeviceID" json:"DeviceID"` DeviceName *string `xmlrpc:"Device_Name" json:"Device_Name"` DevicePrimaryIP *string `xmlrpc:"Device_PrimaryIP" json:"Device_PrimaryIP"` Disabled *string `xmlrpc:"-" json:"disabled"` EncryptionKey *string `xmlrpc:"encryption_key" json:"encryption_key"` EndSupportContract *string `xmlrpc:"EndSupportContract" json:"EndSupportContract"` ERPDeviceID *string `xmlrpc:"ERPDeviceID" json:"ERPDeviceID"` FailoverPartner *string `xmlrpc:"failover_partner" json:"failover_partner"` FirewallParent *string `xmlrpc:"fw_parent" json:"fw_parent"` LocationTitle *string `xmlrpc:"Location_Title" json:"Location_Title"` Manufacturer *string `xmlrpc:"manufacturer" json:"manufacturer"` Model *string `xmlrpc:"model" json:"model"` NetworkZoneID *string `xmlrpc:"NetworkZoneID" json:"NetworkZoneID"` NetworkZoneTitle *string `xmlrpc:"NetworkZoneTitle" json:"NetworkZoneTitle"` RackID *string `xmlrpc:"RackID" json:"RackID"` RackTitle *string `xmlrpc:"RackTitle" json:"RackTitle"` RackU *string `xmlrpc:"RackU" json:"RackU"` RSPlatform *string `xmlrpc:"-" json:"rs_platform"` Serial *string `xmlrpc:"serial" json:"serial"` StartSupportContract *string `xmlrpc:"StartSupportContract" json:"StartSupportContract"` TypeID *string `xmlrpc:"type" json:"type"` Version *string `xmlrpc:"version" json:"version"` } ) // GetFirewall method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.firewall.Get func (c *Client) GetFirewall(firewallID int) (*Firewall, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/firewall.php"), nil) if err != nil { return nil, err } var result Firewall err = client.Call("mydatapipe.firewall.Get", firewallID, &result) return &result, err } // GetFirewallJSON uses the *mydp.Client to invoke a JSON call to the /json/Firewall.php endpoint // requires *device ID* (not specific ID) // doc: https://one.rackspace.com/pages/viewpage.action?pageId=586744870#MyDatapipeAPI-GET/json/Firewall.php?DeviceID=DeviceID func (c *Client) GetFirewallJSON(deviceID int) (*Firewall, error) { response := new(Firewall) res, err := c.get("json/Firewall.php", url.Values{"DeviceID": []string{strconv.Itoa(deviceID)}}) if err != nil { return response, err } if res != nil { defer func() { if defErr := res.Body.Close(); defErr != nil { err = fmt.Errorf("%s::%s", err, defErr) } }() } err = json.NewDecoder(res.Body).Decode(response) return response, err } // FirewallList method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.firewall.List func (c *Client) FirewallList(offset int) ([]Firewall, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/firewall.php"), nil) if err != nil { return nil, err } var result []Firewall tst := new([]interface{}) err = client.Call("mydatapipe.firewall.List", offset, tst) return result, err }