Skip to content

Commit

Permalink
style: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Apr 3, 2024
1 parent 7376f45 commit 7ef6276
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/serve/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func serveS3(f fs.Fs) (testURL string, keyid string, keysec string, w *Server) {
router := w.server.Router()

w.Bind(router)
w.Serve()
_ = w.Serve()
testURL = w.server.URLs()[0]

return
Expand Down Expand Up @@ -286,7 +286,7 @@ func testListBuckets(t *testing.T, useProxy bool) {
for _, tt := range testdata.files {
file := path.Join(tt.path, tt.filename)

var found bool = false
found := false
for object := range objects {
if file == object.Key {
found = true
Expand Down
17 changes: 9 additions & 8 deletions cmd/serve/s3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
type ctxKey int

const (
ctxKeyId ctxKey = iota
ctxKeyID ctxKey = iota
)

// Options contains options for the http Server
Expand Down Expand Up @@ -109,7 +109,7 @@ func (w *Server) getVFS(ctx context.Context) (VFS *vfs.VFS, err error) {
return w._vfs, nil
}

value := ctx.Value(ctxKeyId)
value := ctx.Value(ctxKeyID)
if value == nil {
return nil, errors.New("no VFS found in context")
}
Expand All @@ -122,8 +122,8 @@ func (w *Server) getVFS(ctx context.Context) (VFS *vfs.VFS, err error) {
}

// auth does proxy authorization
func (w *Server) auth(accessKeyId string) (value interface{}, err error) {
VFS, _, err := w.proxy.Call(stringToMd5Hash(accessKeyId), accessKeyId, false)
func (w *Server) auth(accessKeyID string) (value interface{}, err error) {
VFS, _, err := w.proxy.Call(stringToMd5Hash(accessKeyID), accessKeyID, false)
if err != nil {
return nil, err
}
Expand All @@ -135,6 +135,7 @@ func (w *Server) Bind(router chi.Router) {
router.Handle("/*", w.handler)
}

// Serve serves the s3 server
func (w *Server) Serve() error {
w.server.Serve()
fs.Logf(w.f, "Starting s3 server on %s", w.server.URLs())
Expand All @@ -143,7 +144,7 @@ func (w *Server) Serve() error {

func authPairMiddleware(next http.Handler, ws *Server) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accessKey, _ := parseAccessKeyId(r)
accessKey, _ := parseAccessKeyID(r)
// set the auth pair
authPair := map[string]string{
accessKey: ws.s3Secret,
Expand All @@ -155,20 +156,20 @@ func authPairMiddleware(next http.Handler, ws *Server) http.Handler {

func proxyAuthMiddleware(next http.Handler, ws *Server) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accessKey, _ := parseAccessKeyId(r)
accessKey, _ := parseAccessKeyID(r)
value, err := ws.auth(accessKey)
if err != nil {
fs.Infof(r.URL.Path, "%s: Auth failed: %v", r.RemoteAddr, err)
}
if value != nil {
r = r.WithContext(context.WithValue(r.Context(), ctxKeyId, value))
r = r.WithContext(context.WithValue(r.Context(), ctxKeyID, value))
}

next.ServeHTTP(w, r)
})
}

func parseAccessKeyId(r *http.Request) (accessKey string, error signature.ErrorCode) {
func parseAccessKeyID(r *http.Request) (accessKey string, error signature.ErrorCode) {
v4Auth := r.Header.Get("Authorization")
req, err := signature.ParseSignV4(v4Auth)
if err != signature.ErrNone {
Expand Down

0 comments on commit 7ef6276

Please sign in to comment.