Skip to content

Commit

Permalink
Merge pull request #28 from SiaFoundation/chris/fix-authentication
Browse files Browse the repository at this point in the history
backend: fix authentication backend up into 2 methods
  • Loading branch information
ChrisSchinnerl authored Jun 24, 2024
2 parents 8e1ef63 + 60f57d3 commit 465d2f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ type MultipartBackend interface {
}

type AuthenticatedBackend interface {
AuthenticateRequest(w http.ResponseWriter, r *http.Request, bucket string) bool
IsAuthenticated(w http.ResponseWriter, r *http.Request, bucket string) bool
AuthenticationMiddleware(handler http.Handler) http.Handler
}

// CopyObject is a helper function useful for quickly implementing CopyObject on
Expand Down
4 changes: 4 additions & 0 deletions gofakes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (g *GoFakeS3) Server() http.Handler {
} else if g.hostBucket {
handler = g.hostBucketMiddleware(handler)
}

if ab, ok := g.storage.(AuthenticatedBackend); ok {
handler = ab.AuthenticationMiddleware(handler)
}
return handler
}

Expand Down
2 changes: 1 addition & 1 deletion routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (g *GoFakeS3) routeBase(w http.ResponseWriter, r *http.Request) {
// perform authentication if necessary
ab, ok := g.storage.(AuthenticatedBackend)
if ok {
if !ab.AuthenticateRequest(w, r, bucket) {
if !ab.IsAuthenticated(w, r, bucket) {
return // unable to authenticate
}
}
Expand Down

0 comments on commit 465d2f5

Please sign in to comment.