Commit 1a721ac5 authored by David Schneider's avatar David Schneider
Browse files

Add --infoblox-max-results setting

The number of objects returned by the infoblox api is limited to 1000 objects
(see https://ipam.illinois.edu/wapidoc). If there are more then 1000 objects
the API returns an error. By setting max-results one can raise the limit.
parent c0477573
......@@ -154,6 +154,7 @@ func main() {
Version: cfg.InfobloxWapiVersion,
SSLVerify: cfg.InfobloxSSLVerify,
View: cfg.InfobloxView,
MaxResults: cfg.InfobloxMaxResults,
DryRun: cfg.DryRun,
},
)
......
......@@ -76,6 +76,7 @@ type Config struct {
InfobloxWapiVersion string
InfobloxSSLVerify bool
InfobloxView string
InfobloxMaxResults int
DynCustomerName string
DynUsername string
DynPassword string `secure:"yes"`
......@@ -153,6 +154,7 @@ var defaultConfig = &Config{
InfobloxWapiVersion: "2.3.1",
InfobloxSSLVerify: true,
InfobloxView: "",
InfobloxMaxResults: 0,
OCIConfigFile: "/etc/kubernetes/oci.yaml",
InMemoryZones: []string{},
PDNSServer: "http://localhost:8081",
......@@ -277,6 +279,7 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("infoblox-wapi-version", "When using the Infoblox provider, specify the WAPI version (default: 2.3.1)").Default(defaultConfig.InfobloxWapiVersion).StringVar(&cfg.InfobloxWapiVersion)
app.Flag("infoblox-ssl-verify", "When using the Infoblox provider, specify whether to verify the SSL certificate (default: true, disable with --no-infoblox-ssl-verify)").Default(strconv.FormatBool(defaultConfig.InfobloxSSLVerify)).BoolVar(&cfg.InfobloxSSLVerify)
app.Flag("infoblox-view", "DNS view (default: \"\")").Default(defaultConfig.InfobloxView).StringVar(&cfg.InfobloxView)
app.Flag("infoblox-max-results", "Add _max_results as query parameter to the url on all api requests. the default is 0 which means _max_results is not set and the default of the server is used.").Default(strconv.Itoa(defaultConfig.InfobloxMaxResults)).IntVar(&cfg.InfobloxMaxResults)
app.Flag("dyn-customer-name", "When using the Dyn provider, specify the Customer Name").Default("").StringVar(&cfg.DynCustomerName)
app.Flag("dyn-username", "When using the Dyn provider, specify the Username").Default("").StringVar(&cfg.DynUsername)
app.Flag("dyn-password", "When using the Dyn provider, specify the pasword").Default("").StringVar(&cfg.DynPassword)
......
......@@ -60,6 +60,7 @@ var (
InfobloxWapiVersion: "2.3.1",
InfobloxView: "",
InfobloxSSLVerify: true,
InfobloxMaxResults: 0,
OCIConfigFile: "/etc/kubernetes/oci.yaml",
InMemoryZones: []string{""},
PDNSServer: "http://localhost:8081",
......@@ -117,6 +118,7 @@ var (
InfobloxWapiVersion: "2.6.1",
InfobloxView: "internal",
InfobloxSSLVerify: false,
InfobloxMaxResults: 2000,
OCIConfigFile: "oci.yaml",
InMemoryZones: []string{"example.org", "company.com"},
PDNSServer: "http://ns.example.com:8081",
......@@ -245,6 +247,7 @@ func TestParseFlags(t *testing.T) {
"--infoblox-wapi-password=infoblox",
"--infoblox-wapi-version=2.6.1",
"--infoblox-view=internal",
"--infoblox-max-results=2000",
"--inmemory-zone=example.org",
"--inmemory-zone=company.com",
"--pdns-server=http://ns.example.com:8081",
......@@ -314,6 +317,7 @@ func TestParseFlags(t *testing.T) {
"EXTERNAL_DNS_INFOBLOX_WAPI_VERSION": "2.6.1",
"EXTERNAL_DNS_INFOBLOX_VIEW": "internal",
"EXTERNAL_DNS_INFOBLOX_SSL_VERIFY": "0",
"EXTERNAL_DNS_INFOBLOX_MAX_RESULTS": "2000",
"EXTERNAL_DNS_OCI_CONFIG_FILE": "oci.yaml",
"EXTERNAL_DNS_INMEMORY_ZONE": "example.org\ncompany.com",
"EXTERNAL_DNS_DOMAIN_FILTER": "example.org\ncompany.com",
......
......@@ -18,6 +18,7 @@ package provider
import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
......@@ -40,6 +41,7 @@ type InfobloxConfig struct {
SSLVerify bool
DryRun bool
View string
MaxResults int
}
// InfobloxProvider implements the DNS provider for Infoblox.
......@@ -56,6 +58,33 @@ type infobloxRecordSet struct {
res interface{}
}
// CustomQueryRequestBuilder implements a HttpRequestBuilder which supports to
// pass query paramters with each request
type CustomQueryRequestBuilder struct {
queryParams map[string]string
ibclient.WapiRequestBuilder
}
// NewCustomQueryRequestBuilder returns a CustomQueryRequestBuilder which adds
// queryParams to all requests
func NewCustomQueryRequestBuilder(queryParams map[string]string) *CustomQueryRequestBuilder {
return &CustomQueryRequestBuilder{
queryParams: queryParams,
}
}
// BuildRequest prepares the api request. it uses BuildRequest of
// WapiRequestBuilder and then add all queryParams
func (cqb *CustomQueryRequestBuilder) BuildRequest(t ibclient.RequestType, obj ibclient.IBObject, ref string, queryParams ibclient.QueryParams) (req *http.Request, err error) {
req, err = cqb.WapiRequestBuilder.BuildRequest(t, obj, ref, queryParams)
query := req.URL.Query()
for key, value := range cqb.queryParams {
query.Set(key, value)
}
req.URL.RawQuery = query.Encode()
return
}
// NewInfobloxProvider creates a new Infoblox provider.
func NewInfobloxProvider(infobloxConfig InfobloxConfig) (*InfobloxProvider, error) {
hostConfig := ibclient.HostConfig{
......@@ -75,7 +104,18 @@ func NewInfobloxProvider(infobloxConfig InfobloxConfig) (*InfobloxProvider, erro
httpPoolConnections,
)
requestBuilder := &ibclient.WapiRequestBuilder{}
var requestBuilder ibclient.HttpRequestBuilder
if infobloxConfig.MaxResults != 0 {
// use our own HttpRequestBuilder which allows to set additional query parameters
query := map[string]string{
"_max_results": strconv.Itoa(infobloxConfig.MaxResults),
}
requestBuilder = NewCustomQueryRequestBuilder(query)
} else {
// use the default HttpRequestBuilder of the infoblox client
requestBuilder = &ibclient.WapiRequestBuilder{}
}
requestor := &ibclient.WapiHttpRequestor{}
client, err := ibclient.NewConnector(hostConfig, transportConfig, requestBuilder, requestor)
......
......@@ -495,3 +495,22 @@ func TestInfobloxZones(t *testing.T) {
assert.Equal(t, provider.findZone(zones, "lvl2-2.lvl1-1.example.com").Fqdn, "lvl1-1.example.com")
assert.Equal(t, provider.findZone(zones, "lvl2-2.lvl1-2.example.com").Fqdn, "example.com")
}
func TestCustomQueryRequestBuilder(t *testing.T) {
hostConfig := ibclient.HostConfig{
Host: "localhost",
Port: "8080",
Username: "user",
Password: "abcd",
Version: "2.3.1",
}
requestBuilder := NewCustomQueryRequestBuilder(map[string]string{"myKey": "myValue"})
requestBuilder.Init(hostConfig)
obj := ibclient.NewRecordCNAME(ibclient.RecordCNAME{Zone: "foo.bar.com"})
req, _ := requestBuilder.BuildRequest(ibclient.GET, obj, "", ibclient.QueryParams{})
assert.True(t, req.URL.Query().Get("myKey") == "myValue")
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment