/
objects.go
96 lines (88 loc) · 3.17 KB
/
objects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package twclient
import (
"strings"
"strconv"
)
// Payload hold request payload
type Payload struct {
Method string
Path string
Params map[string]string
Body interface{}
}
// Base base object
type Base struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Organization string `json:"organization_name,omitempty"`
OrganizationID int `json:"organization_id,omitempty"`
Addr1 int `json:"addr1"`
Addr2 int `json:"addr2"`
Addr3 int `json:"addr3"`
Addr4 int `json:"addr4"`
Address string `json:"address,omitempty"`
}
// Network Represents IPV4 network
type Network struct {
Base
MaskLen int `json:"mask_length,omitempty"`
DMZVisible string `json:"dmzVisible,omitempty"`
DNSSecEnable string `json:"dnssec_enable,omitempty"`
Discovery string `json:"enable_discovery,omitempty"`
}
// Subnet Represents IPV4 network
type Subnet struct {
Base
MaskLen int `json:"mask_length,omitempty"`
RouterAddr string `json:"routerAddress,omitempty"`
NetworkAddr string `json:"network_address,omitempty"`
PrimaryDomain string `json:"primary_domain,omitempty"`
SubnetAddress string `json:"fullAddress,omitempty"`
NetworkMask int `json:"network_mask,omitempty"`
}
// IPObject to create IP Address
type IPObject struct {
Base
AllocType int `json:"alloc_type"`
Class string `json:"class_code,omitempty"`
Domain string `json:"domain_name,omitempty"`
SubnetAddr string `json:"subnet_address,omitempty"`
UpdateNaA bool `json:"update_ns_a,omitempty"`
UpdateNsPtr bool `json:"update_ns_ptr,omitempty"`
DynUpdRrsA bool `json:"dyn_update_rrs_a,omitempty"`
DynUpdRrsPtr bool `json:"dyn_update_rrs_ptr,omitempty"`
DynUpdRrsCName bool `json:"dyn_update_rrs_cname,omitempty"`
DynUpdRrsMx bool `json:"dyn_update_rrs_mx,omitempty"`
}
// NewIPObject creates new instance of Ip object
func NewIPObject(ipAddr string, subnet string, domain string, org string, name string)(*IPObject){
ipSlice := strings.Split(ipAddr, ".")
ipObj := &IPObject{AllocType:1, Class:"Others", UpdateNaA:true,
UpdateNsPtr:true, DynUpdRrsA:true, DynUpdRrsPtr:true,
DynUpdRrsCName:true, DynUpdRrsMx:true}
ipObj.Name = name
ipObj.Domain = domain
ipObj.Organization = org
ipObj.SubnetAddr = subnet
adr, _ := strconv.Atoi(ipSlice[0])
ipObj.Addr1 = adr
adr1, _ := strconv.Atoi(ipSlice[1])
ipObj.Addr2 = adr1
adr2, _ := strconv.Atoi(ipSlice[2])
ipObj.Addr3 = adr2
adr3, _ := strconv.Atoi(ipSlice[3])
ipObj.Addr4 = adr3
return ipObj
}
// ErrorResp custom response
type ErrorResp struct {
Status string
ErrorMsg string
StatusCode int
}
// IPObjDel for deleting IP Address
type IPObjDel struct {
Addresses []string `json:"addressArray,omitempty"`
Org string `json:"organization_name,omitempty"`
DelRRSChked uint `json:"isDeleterrsChecked"`
}