Skip to content

Commit 8ae9eea

Browse files
authored
Merge pull request #976 from lib/lint
gss linting
2 parents 65babff + 7f4d661 commit 8ae9eea

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

auth/kerberos/krb_unix.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import (
1919
* implementation
2020
*/
2121

22-
// Implements the pq.Gss interface
23-
type Gss struct {
22+
// GSS implements the pq.GSS interface.
23+
type GSS struct {
2424
cli *client.Client
2525
}
2626

27-
func NewGSS() (*Gss, error) {
28-
g := &Gss{}
27+
// NewGSS creates a new GSS provider.
28+
func NewGSS() (*GSS, error) {
29+
g := &GSS{}
2930
err := g.init()
3031

3132
if err != nil {
@@ -35,7 +36,7 @@ func NewGSS() (*Gss, error) {
3536
return g, nil
3637
}
3738

38-
func (g *Gss) init() error {
39+
func (g *GSS) init() error {
3940
cfgPath, ok := os.LookupEnv("KRB5_CONFIG")
4041
if !ok {
4142
cfgPath = "/etc/krb5.conf"
@@ -75,7 +76,8 @@ func (g *Gss) init() error {
7576
return nil
7677
}
7778

78-
func (g *Gss) GetInitToken(host string, service string) ([]byte, error) {
79+
// GetInitToken implements the GSS interface.
80+
func (g *GSS) GetInitToken(host string, service string) ([]byte, error) {
7981

8082
// Resolve the hostname down to an 'A' record, if required (usually, it is)
8183
if g.cli.Config.LibDefaults.DNSCanonicalizeHostname {
@@ -91,7 +93,8 @@ func (g *Gss) GetInitToken(host string, service string) ([]byte, error) {
9193
return g.GetInitTokenFromSpn(spn)
9294
}
9395

94-
func (g *Gss) GetInitTokenFromSpn(spn string) ([]byte, error) {
96+
// GetInitTokenFromSpn implements the GSS interface.
97+
func (g *GSS) GetInitTokenFromSpn(spn string) ([]byte, error) {
9598
s := spnego.SPNEGOClient(g.cli, spn)
9699

97100
st, err := s.InitSecContext()
@@ -107,7 +110,8 @@ func (g *Gss) GetInitTokenFromSpn(spn string) ([]byte, error) {
107110
return b, nil
108111
}
109112

110-
func (g *Gss) Continue(inToken []byte) (done bool, outToken []byte, err error) {
113+
// Continue implements the GSS interface.
114+
func (g *GSS) Continue(inToken []byte) (done bool, outToken []byte, err error) {
111115
t := &spnego.SPNEGOToken{}
112116
err = t.Unmarshal(inToken)
113117
if err != nil {

auth/kerberos/krb_windows.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"github.com/alexbrainman/sspi/negotiate"
88
)
99

10-
// Implements the pq.Gss interface
10+
// GSS implements the pq.GSS interface.
1111
type Gss struct {
1212
creds *sspi.Credentials
1313
ctx *negotiate.ClientContext
1414
}
1515

16-
func NewGSS() (*Gss, error) {
17-
g := &Gss{}
16+
// NewGSS creates a new GSS provider.
17+
func NewGSS() (*GSS, error) {
18+
g := &GSS{}
1819
err := g.init()
1920

2021
if err != nil {
@@ -24,7 +25,7 @@ func NewGSS() (*Gss, error) {
2425
return g, nil
2526
}
2627

27-
func (g *Gss) init() error {
28+
func (g *GSS) init() error {
2829
creds, err := negotiate.AcquireCurrentUserCredentials()
2930
if err != nil {
3031
return err
@@ -34,7 +35,8 @@ func (g *Gss) init() error {
3435
return nil
3536
}
3637

37-
func (g *Gss) GetInitToken(host string, service string) ([]byte, error) {
38+
// GetInitToken implements the GSS interface.
39+
func (g *GSS) GetInitToken(host string, service string) ([]byte, error) {
3840

3941
host, err := canonicalizeHostname(host)
4042
if err != nil {
@@ -46,7 +48,8 @@ func (g *Gss) GetInitToken(host string, service string) ([]byte, error) {
4648
return g.GetInitTokenFromSpn(spn)
4749
}
4850

49-
func (g *Gss) GetInitTokenFromSpn(spn string) ([]byte, error) {
51+
// GetInitTokenFromSpn implements the GSS interface.
52+
func (g *GSS) GetInitTokenFromSpn(spn string) ([]byte, error) {
5053
ctx, token, err := negotiate.NewClientContext(g.creds, spn)
5154
if err != nil {
5255
return nil, err
@@ -57,6 +60,7 @@ func (g *Gss) GetInitTokenFromSpn(spn string) ([]byte, error) {
5760
return token, nil
5861
}
5962

60-
func (g *Gss) Continue(inToken []byte) (done bool, outToken []byte, err error) {
63+
// Continue implements the GSS interface.
64+
func (g *GSS) Continue(inToken []byte) (done bool, outToken []byte, err error) {
6165
return g.ctx.Update(inToken)
6266
}

conn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ type conn struct {
157157
notificationHandler func(*Notification)
158158

159159
// GSSAPI context
160-
gss Gss
160+
gss GSS
161161
}
162162

163163
// Handle driver-side settings in parsed connection string.

krb.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package pq
22

3-
// A function that creates a GSS authentication provider,
4-
// for use with RegisterGSSProvider.
5-
type NewGSSFunc func() (Gss, error)
3+
// NewGSSFunc creates a GSS authentication provider, for use with
4+
// RegisterGSSProvider.
5+
type NewGSSFunc func() (GSS, error)
66

77
var newGss NewGSSFunc
88

9-
// Register the function for creating a GSS authentication provider.
10-
// For example, if you need to use Kerberos to authenticate with your server,
11-
// add this to your main package:
9+
// RegisterGSSProvider registers a GSS authentication provider. For example, if
10+
// you need to use Kerberos to authenticate with your server, add this to your
11+
// main package:
1212
//
1313
// import "github.com/lib/pq/auth/kerberos"
14-
//
14+
//
1515
// func init() {
16-
// pq.RegisterGSSProvider(func() (pq.Gss, error) { return kerberos.NewGSS() })
16+
// pq.RegisterGSSProvider(func() (pq.GSS, error) { return kerberos.NewGSS() })
1717
// }
1818
func RegisterGSSProvider(newGssArg NewGSSFunc) {
1919
newGss = newGssArg
2020
}
2121

22-
// An interface for providing GSSAPI authentication (e.g. Kerberos).
23-
// You only need to care about this interface if you are writing a
24-
// GSS authentication provider.
25-
type Gss interface {
22+
// GSS provides GSSAPI authentication (e.g., Kerberos).
23+
type GSS interface {
2624
GetInitToken(host string, service string) ([]byte, error)
2725
GetInitTokenFromSpn(spn string) ([]byte, error)
2826
Continue(inToken []byte) (done bool, outToken []byte, err error)

0 commit comments

Comments
 (0)