Skip to content

Commit

Permalink
Merge pull request #1985 from PG2000/master
Browse files Browse the repository at this point in the history
feat: move from dynectsoap to dynsoap
  • Loading branch information
k8s-ci-robot authored May 2, 2021
2 parents 5806e34 + 73c6fc9 commit 399fc75
Show file tree
Hide file tree
Showing 5 changed files with 32,944 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/google/go-cmp v0.4.1
github.com/gophercloud/gophercloud v0.1.0
github.com/gorilla/mux v1.7.4 // indirect
github.com/hooklift/gowsdl v0.4.0
github.com/infobloxopen/infoblox-go-client v0.0.0-20180606155407-61dc5f9b0a65
github.com/linki/instrumented_http v0.2.0
github.com/linode/linodego v0.19.0
Expand All @@ -44,7 +45,6 @@ require (
github.com/pkg/errors v0.9.1
github.com/projectcontour/contour v1.5.0
github.com/prometheus/client_golang v1.7.1
github.com/sanyu/dynectsoap v0.0.0-20181203081243-b83de5edc4e0
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f
github.com/sirupsen/logrus v1.6.0
github.com/smartystreets/gunit v1.3.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hooklift/gowsdl v0.4.0 h1:luskQG8h3M0CYrcSFl9ObpWs3pzIsEfYou1cuSwKiCk=
github.com/hooklift/gowsdl v0.4.0/go.mod h1:TYmt7jpe3F5zLlMtKGetjHLwUBIAF5JCd+NYq+mQ/Zk=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
Expand Down Expand Up @@ -784,8 +786,6 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sanyu/dynectsoap v0.0.0-20181203081243-b83de5edc4e0 h1:vOcHdR1nu7DO4BAx1rwzdHV7jQTzW3gqcBT5qxHSc6A=
github.com/sanyu/dynectsoap v0.0.0-20181203081243-b83de5edc4e0/go.mod h1:FeplEtXXejBYC4NPAFTrs5L7KuK+5RL9bf5nB2vZe9o=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f h1:WSnaD0/cvbKJgSTYbjAPf4RJXVvNNDAwVm+W8wEmnGE=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
Expand Down
51 changes: 32 additions & 19 deletions provider/dyn/dyn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
log "github.com/sirupsen/logrus"

"github.com/nesv/go-dynect/dynect"
"github.com/sanyu/dynectsoap/dynectsoap"

"sigs.k8s.io/external-dns/endpoint"
"sigs.k8s.io/external-dns/plan"
"sigs.k8s.io/external-dns/provider"
dynsoap "sigs.k8s.io/external-dns/provider/dyn/soap"
)

const (
Expand Down Expand Up @@ -250,7 +250,7 @@ func apiRetryLoop(f func() error) error {
return err
}

func (d *dynProviderState) allRecordsToEndpoints(records *dynectsoap.GetAllRecordsResponseType) []*endpoint.Endpoint {
func (d *dynProviderState) allRecordsToEndpoints(records *dynsoap.GetAllRecordsResponseType) []*endpoint.Endpoint {
result := []*endpoint.Endpoint{}
//Convert each record to an endpoint

Expand Down Expand Up @@ -330,20 +330,23 @@ func (d *dynProviderState) fetchZoneSerial(client *dynect.Client, zone string) (
}

//Use SOAP to fetch all records with a single call
func (d *dynProviderState) fetchAllRecordsInZone(zone string) (*dynectsoap.GetAllRecordsResponseType, error) {
func (d *dynProviderState) fetchAllRecordsInZone(zone string) (*dynsoap.GetAllRecordsResponseType, error) {
var err error
client := dynectsoap.NewClient("https://api2.dynect.net/SOAP/")
service := dynectsoap.NewDynect(client)

sessionRequest := dynectsoap.SessionLoginRequestType{
service := dynsoap.NewDynectClient("https://api2.dynect.net/SOAP/")

sessionRequest := dynsoap.SessionLoginRequestType{
Customer_name: d.CustomerName,
User_name: d.Username,
Password: d.Password,
Fault_incompat: 0,
}
resp := dynectsoap.SessionLoginResponseType{}

var resp *dynsoap.SessionLoginResponseType

err = apiRetryLoop(func() error {
return service.Do(&sessionRequest, &resp)
resp, err = service.SessionLogin(&sessionRequest)
return err
})

if err != nil {
Expand All @@ -352,46 +355,56 @@ func (d *dynProviderState) fetchAllRecordsInZone(zone string) (*dynectsoap.GetAl

token := resp.Data.Token

logoutRequest := dynectsoap.SessionLogoutRequestType{
logoutRequest := &dynsoap.SessionLogoutRequestType{
Token: token,
Fault_incompat: 0,
}
logoutResponse := dynectsoap.SessionLogoutResponseType{}
defer service.Do(&logoutRequest, &logoutResponse)

req := dynectsoap.GetAllRecordsRequestType{
defer service.SessionLogout(logoutRequest)

req := dynsoap.GetAllRecordsRequestType{
Token: token,
Zone: zone,
Fault_incompat: 0,
}
records := dynectsoap.GetAllRecordsResponseType{}

var records = &dynsoap.GetAllRecordsResponseType{}

err = apiRetryLoop(func() error {
return service.Do(&req, &records)
records, err = service.GetAllRecords(&req)
return err
})

if err != nil {
return nil, err
}

log.Debugf("Got all Records, status is %s", records.Status)

if strings.ToLower(records.Status) == "incomplete" {
jobRequest := dynectsoap.GetJobRequestType{
jobRequest := dynsoap.GetJobRequestType{
Token: token,
Job_id: records.Job_id,
Fault_incompat: 0,
}

jobResults := dynectsoap.GetJobResponseType{}
var jobResults = dynsoap.GetJobResponseType{}
err = apiRetryLoop(func() error {
return service.GetJobRetry(&jobRequest, &jobResults)
jobResults, err := service.GetJob(&jobRequest)
if strings.ToLower(jobResults.Status) == "incomplete" {
return fmt.Errorf("job is incomplete")
}
return err
})

if err != nil {
return nil, err
}
return jobResults.Data.(*dynectsoap.GetAllRecordsResponseType), nil

return jobResults.Data.(*dynsoap.GetAllRecordsResponseType), nil
}

return &records, nil
return records, nil
}

// buildLinkToRecord build a resource link. The symmetry of the dyn API is used to save
Expand Down
44 changes: 44 additions & 0 deletions provider/dyn/soap/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2020 The Kubernetes Authors.
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 dynsoap

import (
"net/http"
"time"

"github.com/hooklift/gowsdl/soap"
)

// NewDynectClient returns a client with a configured http.Client
// The default settings for the http.client are a timeout of
// 10 seconds and reading proxy variables from http.ProxyFromEnvironment
func NewDynectClient(url string) Dynect {
client := &http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
},
}
soapClient := soap.NewClient(url, soap.WithHTTPClient(client))
return NewDynect(soapClient)
}

// NewCustomDynectClient returns a client without a configured http.Client
func NewCustomDynectClient(url string, client http.Client) Dynect {
soapClient := soap.NewClient(url, soap.WithHTTPClient(&client))
return NewDynect(soapClient)
}
Loading

0 comments on commit 399fc75

Please sign in to comment.