mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-09 21:55:57 +08:00
MYTHICBEASTS: Performance improvement: Use the OAuth2 client credentials protocol (#3629)
This commit is contained in:
parent
1f8b7d01b6
commit
e5eab4f828
1 changed files with 12 additions and 7 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
package mythicbeasts
|
package mythicbeasts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -15,6 +16,8 @@ import (
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
|
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
|
||||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/clientcredentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mythicBeastsDefaultNS lists the default nameservers, per https://www.mythic-beasts.com/support/domains/nameservers.
|
// mythicBeastsDefaultNS lists the default nameservers, per https://www.mythic-beasts.com/support/domains/nameservers.
|
||||||
|
|
@ -25,8 +28,6 @@ var mythicBeastsDefaultNS = []string{
|
||||||
|
|
||||||
// mythicBeastsProvider is the handle for this provider.
|
// mythicBeastsProvider is the handle for this provider.
|
||||||
type mythicBeastsProvider struct {
|
type mythicBeastsProvider struct {
|
||||||
secret string
|
|
||||||
keyID string
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,10 +66,16 @@ func newDsp(conf map[string]string, metadata json.RawMessage) (providers.DNSServ
|
||||||
if conf["secret"] == "" {
|
if conf["secret"] == "" {
|
||||||
return nil, errors.New("missing Mythic Beasts auth secret")
|
return nil, errors.New("missing Mythic Beasts auth secret")
|
||||||
}
|
}
|
||||||
|
// Use https://www.mythic-beasts.com/support/api/auth
|
||||||
|
cfg := clientcredentials.Config{
|
||||||
|
ClientID: conf["keyID"],
|
||||||
|
ClientSecret: conf["secret"],
|
||||||
|
TokenURL: "https://auth.mythic-beasts.com/login",
|
||||||
|
Scopes: []string{"client_credentials"},
|
||||||
|
AuthStyle: oauth2.AuthStyleInHeader,
|
||||||
|
}
|
||||||
return &mythicBeastsProvider{
|
return &mythicBeastsProvider{
|
||||||
keyID: conf["keyID"],
|
client: cfg.Client(context.Background()),
|
||||||
secret: conf["secret"],
|
|
||||||
client: &http.Client{},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,8 +84,6 @@ func (n *mythicBeastsProvider) httpRequest(method, url string, body io.Reader) (
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// https://www.mythic-beasts.com/support/api/auth
|
|
||||||
req.SetBasicAuth(n.keyID, n.secret)
|
|
||||||
req.Header.Add("Content-Type", "text/dns")
|
req.Header.Add("Content-Type", "text/dns")
|
||||||
req.Header.Add("Accept", "text/dns")
|
req.Header.Add("Accept", "text/dns")
|
||||||
return n.client.Do(req)
|
return n.client.Do(req)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue