Skip to content

Commit

Permalink
Merge pull request #57 from bodgit/logging
Browse files Browse the repository at this point in the history
Add ability to set logger in GSS-TSIG constructor
  • Loading branch information
bodgit committed Oct 31, 2021
2 parents f30d8a6 + 1e212ef commit e108be2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/bodgit/tsig
require (
github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5
github.com/enceve/crypto v0.0.0-20160707101852-34d48bb93815
github.com/go-logr/logr v1.2.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jcmturner/gokrb5/v8 v8.4.2
github.com/jinzhu/copier v0.3.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/enceve/crypto v0.0.0-20160707101852-34d48bb93815 h1:D22EM5TeYZJp43hGDx6dUng8mvtyYbB9BnE3+BmJR1Q=
github.com/enceve/crypto v0.0.0-20160707101852-34d48bb93815/go.mod h1:wYFFK4LYXbX7j+76mOq7aiC/EAw2S22CrzPHqgsisPw=
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
Expand Down
3 changes: 3 additions & 0 deletions gss/apcera.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/bodgit/tsig"
"github.com/bodgit/tsig/internal/util"
"github.com/go-logr/logr"
multierror "github.com/hashicorp/go-multierror"
"github.com/miekg/dns"
"github.com/openshift/gssapi"
Expand All @@ -23,6 +24,7 @@ type Client struct {
lib *gssapi.Lib
client *dns.Client
ctx map[string]*gssapi.CtxId
logger logr.Logger
}

// WithConfig sets the Kerberos configuration used
Expand Down Expand Up @@ -53,6 +55,7 @@ func NewClient(dnsClient *dns.Client, options ...func(*Client) error) (*Client,
lib: lib,
client: client,
ctx: make(map[string]*gssapi.CtxId),
logger: logr.Discard(),
}

if err := c.setOption(options...); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions gss/gokrb5.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/bodgit/tsig"
"github.com/bodgit/tsig/internal/util"
"github.com/go-logr/logr"
"github.com/jcmturner/gokrb5/v8/client"
"github.com/jcmturner/gokrb5/v8/config"
"github.com/jcmturner/gokrb5/v8/credentials"
Expand Down Expand Up @@ -117,6 +118,7 @@ type Client struct {
client *dns.Client
config string
ctx map[string]context
logger logr.Logger
}

// WithConfig sets the Kerberos configuration used
Expand All @@ -142,6 +144,7 @@ func NewClient(dnsClient *dns.Client, options ...func(*Client) error) (*Client,
c := &Client{
client: client,
ctx: make(map[string]context),
logger: logr.Discard(),
}

if err := c.setOption(options...); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions gss/gss.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import (
"time"

"github.com/bodgit/tsig"
"github.com/go-logr/logr"
multierror "github.com/hashicorp/go-multierror"
"github.com/miekg/dns"
)
Expand Down Expand Up @@ -155,3 +156,16 @@ func (c *Client) setOption(options ...func(*Client) error) error {
func (c *Client) SetConfig(config string) error {
return c.setOption(WithConfig(config))
}

// WithLogger sets the logger used
func WithLogger(logger logr.Logger) func(*Client) error {
return func(c *Client) error {
c.logger = logger
return nil
}
}

// SetLogger sets the logger used by c
func (c *Client) SetLogger(logger logr.Logger) error {
return c.setOption(WithLogger(logger))
}
6 changes: 6 additions & 0 deletions gss/gss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/bodgit/tsig"
"github.com/go-logr/logr"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -174,3 +175,8 @@ func testExchangeKeytab(t *testing.T) error {
func TestExchange(t *testing.T) {
assert.Nil(t, testExchange(t))
}

func TestNewClientWithLogger(t *testing.T) {
_, err := NewClient(new(dns.Client), WithLogger(logr.Discard()))
assert.Nil(t, err)
}
3 changes: 3 additions & 0 deletions gss/sspi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/alexbrainman/sspi/negotiate"
"github.com/bodgit/tsig"
"github.com/bodgit/tsig/internal/util"
"github.com/go-logr/logr"
multierror "github.com/hashicorp/go-multierror"
"github.com/miekg/dns"
)
Expand All @@ -23,6 +24,7 @@ type Client struct {
m sync.RWMutex
client *dns.Client
ctx map[string]*negotiate.ClientContext
logger logr.Logger
}

// WithConfig sets the Kerberos configuration used
Expand All @@ -47,6 +49,7 @@ func NewClient(dnsClient *dns.Client, options ...func(*Client) error) (*Client,
c := &Client{
client: client,
ctx: make(map[string]*negotiate.ClientContext),
logger: logr.Discard(),
}

if err := c.setOption(options...); err != nil {
Expand Down

0 comments on commit e108be2

Please sign in to comment.