Skip to content

Commit

Permalink
Merge pull request #16 from martin-helmich/feature/add-basic-auth
Browse files Browse the repository at this point in the history
Add option for HTTP basic auth
  • Loading branch information
hensur authored Jul 13, 2022
2 parents 225d1a8 + d5f29fe commit bb2c46f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ func WithAPIKeyAuthentication(key string) ClientOption {
}
}

// WithBasicAuthentication adds basic authentication to the PowerDNS client.
func WithBasicAuthentication(username string, password string) ClientOption {
return func(c *client) error {
c.authenticator = &pdnshttp.BasicAuthenticator{
Username: username,
Password: password,
}

return nil
}
}

// WithTLSAuthentication configures TLS-based authentication for the PowerDNS client.
// This is not a feature that is provided by PowerDNS natively, but might be implemented
// when the PowerDNS API is run behind a reverse proxy.
Expand Down
17 changes: 17 additions & 0 deletions pdnshttp/auth_basic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package pdnshttp

import "net/http"

type BasicAuthenticator struct {
Username string
Password string
}

func (a *BasicAuthenticator) OnRequest(r *http.Request) error {
r.SetBasicAuth(a.Username, a.Password)
return nil
}

func (a *BasicAuthenticator) OnConnect(*http.Client) error {
return nil
}

0 comments on commit bb2c46f

Please sign in to comment.