mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-24 23:53:01 +08:00
Oracle: Use SDK v65 and default retry policy (#3094)
This commit is contained in:
parent
0de789f381
commit
a3b194fd92
3 changed files with 22 additions and 68 deletions
4
go.mod
4
go.mod
|
@ -39,7 +39,6 @@ require (
|
|||
github.com/mittwald/go-powerdns v0.6.4
|
||||
github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04
|
||||
github.com/nrdcg/goinwx v0.10.0
|
||||
github.com/oracle/oci-go-sdk/v32 v32.0.0
|
||||
github.com/ovh/go-ovh v1.4.3
|
||||
github.com/philhug/opensrs-go v0.0.0-20171126225031-9dfa7433020d
|
||||
github.com/pkg/errors v0.9.1
|
||||
|
@ -69,6 +68,7 @@ require (
|
|||
github.com/juju/errors v1.0.0
|
||||
github.com/kylelemons/godebug v1.1.0
|
||||
github.com/mattn/go-isatty v0.0.20
|
||||
github.com/oracle/oci-go-sdk/v65 v65.72.0
|
||||
github.com/vultr/govultr/v2 v2.17.2
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||
golang.org/x/text v0.17.0
|
||||
|
@ -106,6 +106,7 @@ require (
|
|||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-test/deep v1.0.3 // indirect
|
||||
github.com/goccy/go-json v0.10.3 // indirect
|
||||
github.com/gofrs/flock v0.8.1 // indirect
|
||||
github.com/gofrs/uuid v4.0.0+incompatible // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
|
@ -143,6 +144,7 @@ require (
|
|||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/smartystreets/assertions v1.2.0 // indirect
|
||||
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
|
||||
github.com/sony/gobreaker v0.5.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -158,6 +158,8 @@ github.com/gobwas/glob v0.2.4-0.20181002190808-e7a84e9525fe/go.mod h1:d3Ez4x06l9
|
|||
github.com/goccy/go-json v0.7.8/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
|
||||
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
|
||||
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
|
@ -329,8 +331,8 @@ github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY
|
|||
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
|
||||
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
|
||||
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
|
||||
github.com/oracle/oci-go-sdk/v32 v32.0.0 h1:SSbzrQO3WRcPJEZ8+b3SFPYsPtkFM96clqrp03lrwbU=
|
||||
github.com/oracle/oci-go-sdk/v32 v32.0.0/go.mod h1:aZc4jC59IuNP3cr5y1nj555QvwojMX2nMJaBiozuuEs=
|
||||
github.com/oracle/oci-go-sdk/v65 v65.72.0 h1:gPCb5fBUsZMyafIilPPB2B36yqjkKnnwwiJT4xexUMg=
|
||||
github.com/oracle/oci-go-sdk/v65 v65.72.0/go.mod h1:IBEV9l1qBzUpo7zgGaRUhbB05BVfcDGYRFBCPlTcPp0=
|
||||
github.com/ovh/go-ovh v1.4.3 h1:Gs3V823zwTFpzgGLZNI6ILS4rmxZgJwJCz54Er9LwD0=
|
||||
github.com/ovh/go-ovh v1.4.3/go.mod h1:AkPXVtgwB6xlKblMjRKJJmjRp+ogrE7fz2lVgcQY8SY=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||
|
@ -381,6 +383,8 @@ github.com/softlayer/softlayer-go v1.1.5 h1:UFFtgKxiw0yIuUw93XBCFIiIMYR5eLgmm4a5
|
|||
github.com/softlayer/softlayer-go v1.1.5/go.mod h1:WeJrBLoTJcaT8nO1azeyHyNpo/fDLtbpbvh+pzts+Qw=
|
||||
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e h1:3OgWYFw7jxCZPcvAg+4R8A50GZ+CCkARF10lxu2qDsQ=
|
||||
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e/go.mod h1:fKZCUVdirrxrBpwd9wb+lSoVixvpwAu8eHzbQB2tums=
|
||||
github.com/sony/gobreaker v0.5.0 h1:dRCvqm0P490vZPmy7ppEk2qCnCieBooFJ+YoXGYB+yg=
|
||||
github.com/sony/gobreaker v0.5.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
|
|
|
@ -3,7 +3,6 @@ package oracle
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -11,9 +10,9 @@ import (
|
|||
"github.com/StackExchange/dnscontrol/v4/pkg/diff"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
|
||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||
"github.com/oracle/oci-go-sdk/v32/common"
|
||||
"github.com/oracle/oci-go-sdk/v32/dns"
|
||||
"github.com/oracle/oci-go-sdk/v32/example/helpers"
|
||||
"github.com/oracle/oci-go-sdk/v65/common"
|
||||
"github.com/oracle/oci-go-sdk/v65/dns"
|
||||
"github.com/oracle/oci-go-sdk/v65/example/helpers"
|
||||
)
|
||||
|
||||
var features = providers.DocumentationNotes{
|
||||
|
@ -65,6 +64,12 @@ func New(settings map[string]string, _ json.RawMessage) (providers.DNSServicePro
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Set default retry policy to handle 429 automatically
|
||||
defaultRetryPolicy := common.DefaultRetryPolicy()
|
||||
client.SetCustomClientConfiguration(common.CustomClientConfiguration{
|
||||
RetryPolicy: &defaultRetryPolicy,
|
||||
})
|
||||
|
||||
return &oracleProvider{
|
||||
client: client,
|
||||
compartment: settings["compartment"],
|
||||
|
@ -76,15 +81,10 @@ func (o *oracleProvider) ListZones() ([]string, error) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
waitTime = 1
|
||||
retry:
|
||||
listResp, err := o.client.ListZones(ctx, dns.ListZonesRequest{
|
||||
CompartmentId: &o.compartment,
|
||||
})
|
||||
if err != nil {
|
||||
if pauseAndRetry(listResp.HTTPResponse()) {
|
||||
goto retry
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -100,8 +100,6 @@ func (o *oracleProvider) EnsureZoneExists(domain string) error {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
waitTime = 1
|
||||
retryFirstGetZone:
|
||||
getResp, err := o.client.GetZone(ctx, dns.GetZoneRequest{
|
||||
ZoneNameOrId: &domain,
|
||||
CompartmentId: &o.compartment,
|
||||
|
@ -109,18 +107,11 @@ retryFirstGetZone:
|
|||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
if pauseAndRetry(getResp.HTTPResponse()) {
|
||||
goto retryFirstGetZone
|
||||
}
|
||||
if getResp.RawResponse.StatusCode != 404 {
|
||||
return err
|
||||
}
|
||||
if getResp.RawResponse.StatusCode != 404 {
|
||||
return err
|
||||
}
|
||||
|
||||
waitTime = 1
|
||||
retryCreate:
|
||||
createResp, err := o.client.CreateZone(ctx, dns.CreateZoneRequest{
|
||||
_, err = o.client.CreateZone(ctx, dns.CreateZoneRequest{
|
||||
CreateZoneDetails: dns.CreateZoneDetails{
|
||||
CompartmentId: &o.compartment,
|
||||
Name: &domain,
|
||||
|
@ -128,14 +119,9 @@ retryCreate:
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
if pauseAndRetry(createResp.HTTPResponse()) {
|
||||
goto retryCreate
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
waitTime = 1
|
||||
retrySecondGetZone:
|
||||
// poll until the zone is ready
|
||||
pollUntilAvailable := func(r common.OCIOperationResponse) bool {
|
||||
if converted, ok := r.Response.(dns.GetZoneResponse); ok {
|
||||
|
@ -148,11 +134,6 @@ retrySecondGetZone:
|
|||
CompartmentId: &o.compartment,
|
||||
RequestMetadata: helpers.GetRequestMetadataWithCustomizedRetryPolicy(pollUntilAvailable),
|
||||
})
|
||||
if err != nil {
|
||||
if pauseAndRetry(createResp.HTTPResponse()) {
|
||||
goto retrySecondGetZone
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -161,16 +142,11 @@ func (o *oracleProvider) GetNameservers(domain string) ([]*models.Nameserver, er
|
|||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
waitTime = 1
|
||||
retry:
|
||||
getResp, err := o.client.GetZone(ctx, dns.GetZoneRequest{
|
||||
ZoneNameOrId: &domain,
|
||||
CompartmentId: &o.compartment,
|
||||
})
|
||||
if err != nil {
|
||||
if pauseAndRetry(getResp.HTTPResponse()) {
|
||||
goto retry
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -194,13 +170,8 @@ func (o *oracleProvider) GetZoneRecords(zone string, meta map[string]string) (mo
|
|||
}
|
||||
|
||||
for {
|
||||
waitTime = 1
|
||||
retry:
|
||||
getResp, err := o.client.GetZoneRecords(ctx, request)
|
||||
if err != nil {
|
||||
if pauseAndRetry(getResp.HTTPResponse()) {
|
||||
goto retry
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -345,13 +316,8 @@ func (o *oracleProvider) patch(createRecords, deleteRecords models.Records, doma
|
|||
}
|
||||
patchReq.Items = ops[batchStart:batchEnd]
|
||||
|
||||
waitTime = 1
|
||||
retry:
|
||||
response, err := o.client.PatchZoneRecords(ctx, patchReq)
|
||||
_, err := o.client.PatchZoneRecords(ctx, patchReq)
|
||||
if err != nil {
|
||||
if pauseAndRetry(response.HTTPResponse()) {
|
||||
goto retry
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -380,21 +346,3 @@ func convertToRecordOperation(rec *models.RecordConfig, op dns.RecordOperationOp
|
|||
Operation: op,
|
||||
}
|
||||
}
|
||||
|
||||
// waitTime is the amount of time to sleep if a 429 is received.
|
||||
// Must be reset before every query
|
||||
var waitTime = 1
|
||||
|
||||
func pauseAndRetry(resp *http.Response) bool {
|
||||
if resp.StatusCode == 429 {
|
||||
waitTime = waitTime * 2
|
||||
if waitTime > 300 {
|
||||
printer.Printf("Oracle: max wait for rate-limit reached.\n")
|
||||
return false
|
||||
}
|
||||
printer.Printf("Oracle: API rate-limit hit, pause for %v seconds.\n", waitTime)
|
||||
time.Sleep(time.Duration(waitTime+1) * time.Second)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue