Skip to content

Commit

Permalink
ttl of TXT and CNAME record, added ProxyUrl to TransportConfig, Recor…
Browse files Browse the repository at this point in the history
…dNS (#102)
  • Loading branch information
MartinWeindel authored May 18, 2021
1 parent fec9794 commit 8bc4db1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
5 changes: 5 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type TransportConfig struct {
certPool *x509.CertPool
HttpRequestTimeout time.Duration // in seconds
HttpPoolConnections int
ProxyUrl *url.URL
}

func NewTransportConfig(sslVerify string, httpRequestTimeout int, httpPoolConnections int) (cfg TransportConfig) {
Expand Down Expand Up @@ -134,6 +135,10 @@ func (whr *WapiHttpRequestor) Init(cfg TransportConfig) {
MaxIdleConnsPerHost: cfg.HttpPoolConnections,
}

if cfg.ProxyUrl != nil {
tr.Proxy = http.ProxyURL(cfg.ProxyUrl)
}

// All users of cookiejar should import "golang.org/x/net/publicsuffix"
jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,13 @@ func (objMgr *ObjectManager) DeleteCNAMERecord(ref string) (string, error) {
}

// Creates TXT Record. Use TTL of 0 to inherit TTL from the Zone
func (objMgr *ObjectManager) CreateTXTRecord(recordname string, text string, ttl int, dnsview string) (*RecordTXT, error) {
func (objMgr *ObjectManager) CreateTXTRecord(recordname string, text string, ttl uint, dnsview string) (*RecordTXT, error) {

recordTXT := NewRecordTXT(RecordTXT{
View: dnsview,
Name: recordname,
Text: text,
TTL: ttl,
Ttl: ttl,
})

ref, err := objMgr.connector.CreateObject(recordTXT)
Expand Down
7 changes: 4 additions & 3 deletions object_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,14 +936,14 @@ var _ = Describe("Object Manager", func() {
text := "test-text"
dnsView := "default"
recordName := "test"
ttl := 30
ttl := uint(30)
fakeRefReturn := fmt.Sprintf("record:txt/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)

aniFakeConnector := &fakeConnector{
createObjectObj: NewRecordTXT(RecordTXT{
Name: recordName,
Text: text,
TTL: ttl,
Ttl: ttl,
View: dnsView,
}),
getObjectRef: fakeRefReturn,
Expand All @@ -952,12 +952,13 @@ var _ = Describe("Object Manager", func() {
Text: text,
View: dnsView,
Ref: fakeRefReturn,
Ttl: ttl,
}),
resultObject: NewRecordTXT(RecordTXT{
Name: recordName,
Text: text,
View: dnsView,
TTL: ttl,
Ttl: ttl,
Ref: fakeRefReturn,
}),
fakeRefReturn: fakeRefReturn,
Expand Down
9 changes: 6 additions & 3 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,14 @@ type RecordCNAME struct {
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
Ea EA `json:"extattrs,omitempty"`
Ttl uint `json:"ttl,omitempty"`
UseTtl bool `json:"use_ttl,omitempty"`
}

func NewRecordCNAME(rc RecordCNAME) *RecordCNAME {
res := rc
res.objectType = "record:cname"
res.returnFields = []string{"extattrs", "canonical", "name", "view", "zone"}
res.returnFields = []string{"extattrs", "canonical", "name", "view", "zone", "ttl", "use_ttl"}

return &res
}
Expand Down Expand Up @@ -447,16 +449,17 @@ type RecordTXT struct {
Ref string `json:"_ref,omitempty"`
Name string `json:"name,omitempty"`
Text string `json:"text,omitempty"`
TTL int `json:"ttl,omitempty"`
Ttl uint `json:"ttl,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
Ea EA `json:"extattrs,omitempty"`
UseTtl bool `json:"use_ttl,omitempty"`
}

func NewRecordTXT(rt RecordTXT) *RecordTXT {
res := rt
res.objectType = "record:txt"
res.returnFields = []string{"extattrs", "name", "text", "view", "zone"}
res.returnFields = []string{"extattrs", "name", "text", "view", "zone", "ttl", "use_ttl"}

return &res
}
Expand Down
4 changes: 2 additions & 2 deletions objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ var _ = Describe("Objects", func() {

It("should set base fields correctly", func() {
Expect(rc.ObjectType()).To(Equal("record:cname"))
Expect(rc.ReturnFields()).To(ConsistOf("extattrs", "canonical", "name", "view", "zone"))
Expect(rc.ReturnFields()).To(ConsistOf("extattrs", "canonical", "name", "view", "zone", "ttl", "use_ttl"))
})
})

Expand Down Expand Up @@ -456,7 +456,7 @@ var _ = Describe("Objects", func() {

It("should set base fields correctly", func() {
Expect(rt.ObjectType()).To(Equal("record:txt"))
Expect(rt.ReturnFields()).To(ConsistOf("extattrs", "name", "text", "view", "zone"))
Expect(rt.ReturnFields()).To(ConsistOf("extattrs", "name", "text", "view", "zone", "ttl", "use_ttl"))
})
})

Expand Down
23 changes: 23 additions & 0 deletions record_ns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ibclient

type RecordNS struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Addresses []ZoneNameServer `json:"addresses,omitempty"`
Name string `json:"name,omitempty"`
Nameserver string `json:"nameserver,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
}

func NewRecordNS(rc RecordNS) *RecordNS {
res := rc
res.objectType = "record:ns"
res.returnFields = []string{"addresses", "name", "nameserver", "view", "zone"}

return &res
}

type ZoneNameServer struct {
Address string `json:"address,omitempty"`
}

0 comments on commit 8bc4db1

Please sign in to comment.