Skip to content

Commit 90691e3

Browse files
committed
Fix golint errors in basic.go
1 parent 725e695 commit 90691e3

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

basic.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ var (
4747
}
4848
)
4949

50+
// BasicAuth is an authenticator implementation for 'Basic' HTTP
51+
// Authentication scheme (RFC 7617).
5052
type BasicAuth struct {
5153
Realm string
5254
Secrets SecretProvider
@@ -58,13 +60,9 @@ type BasicAuth struct {
5860
// check that BasicAuth implements AuthenticatorInterface
5961
var _ = (AuthenticatorInterface)((*BasicAuth)(nil))
6062

61-
/*
62-
Checks the username/password combination from the request. Returns
63-
either an empty string (authentication failed) or the name of the
64-
authenticated user.
65-
66-
Supports MD5 and SHA1 password entries
67-
*/
63+
// CheckAuth checks the username/password combination from the
64+
// request. Returns either an empty string (authentication failed) or
65+
// the name of the authenticated user.
6866
func (a *BasicAuth) CheckAuth(r *http.Request) string {
6967
user, password, ok := r.BasicAuth()
7068
if !ok {
@@ -83,6 +81,8 @@ func (a *BasicAuth) CheckAuth(r *http.Request) string {
8381
return user
8482
}
8583

84+
// CheckSecret returns true if the password matches the encrypted
85+
// secret.
8686
func CheckSecret(secret, password string) bool {
8787
compare := compareFuncs[0].compare
8888
for _, cmp := range compareFuncs[1:] {
@@ -116,24 +116,21 @@ func compareMD5HashAndPassword(hashedPassword, password []byte) error {
116116
return nil
117117
}
118118

119-
/*
120-
http.Handler for BasicAuth which initiates the authentication process
121-
(or requires reauthentication).
122-
*/
119+
// RequireAuth is an http.HandlerFunc for BasicAuth which initiates
120+
// the authentication process (or requires reauthentication).
123121
func (a *BasicAuth) RequireAuth(w http.ResponseWriter, r *http.Request) {
124122
w.Header().Set(contentType, a.Headers.V().UnauthContentType)
125123
w.Header().Set(a.Headers.V().Authenticate, `Basic realm="`+a.Realm+`"`)
126124
w.WriteHeader(a.Headers.V().UnauthCode)
127125
w.Write([]byte(a.Headers.V().UnauthResponse))
128126
}
129127

130-
/*
131-
BasicAuthenticator returns a function, which wraps an
132-
AuthenticatedHandlerFunc converting it to http.HandlerFunc. This
133-
wrapper function checks the authentication and either sends back
134-
required authentication headers, or calls the wrapped function with
135-
authenticated username in the AuthenticatedRequest.
136-
*/
128+
// Wrap returns an http.HandlerFunc, which wraps
129+
// AuthenticatedHandlerFunc with this BasicAuth authenticator's
130+
// authentication checks. Once the request contains valid credentials,
131+
// it calls wrapped AuthenticatedHandlerFunc.
132+
//
133+
// Deprecated: new code should use NewContext instead.
137134
func (a *BasicAuth) Wrap(wrapped AuthenticatedHandlerFunc) http.HandlerFunc {
138135
return func(w http.ResponseWriter, r *http.Request) {
139136
if username := a.CheckAuth(r); username == "" {
@@ -155,6 +152,10 @@ func (a *BasicAuth) NewContext(ctx context.Context, r *http.Request) context.Con
155152
return context.WithValue(ctx, infoKey, info)
156153
}
157154

155+
// NewBasicAuthenticator returns a BasicAuth initialized with provided
156+
// realm and secrets.
157+
//
158+
// Deprecated: new code should construct BasicAuth values directly.
158159
func NewBasicAuthenticator(realm string, secrets SecretProvider) *BasicAuth {
159160
return &BasicAuth{Realm: realm, Secrets: secrets}
160161
}

0 commit comments

Comments
 (0)