Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gofakes3.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type GoFakeS3 struct {
autoBucket bool
uploader *uploader
log Logger
baseURL string

// simple v4 signature
mu sync.RWMutex // protects vAuthPair map only
Expand All @@ -56,6 +57,7 @@ func New(backend Backend, options ...Option) *GoFakeS3 {
integrityCheck: true,
uploader: newUploader(),
requestID: 0,
baseURL: "",
}

// versioned MUST be set before options as one of the options disables it:
Expand Down Expand Up @@ -123,7 +125,11 @@ func (g *GoFakeS3) authMiddleware(handler http.Handler) http.Handler {
haveAuth := len(g.v4AuthPair) > 0
g.mu.RUnlock()
if haveAuth {
if result := signature.V4SignVerify(rq); result != signature.ErrNone {
authReq := rq
if g.baseURL != "" {
authReq.URL.Path = g.baseURL + rq.URL.Path
}
if result := signature.V4SignVerify(authReq); result != signature.ErrNone {
g.log.Print(LogWarn, "Access Denied:", rq.RemoteAddr, "=>", rq.URL)

resp := signature.GetAPIError(result)
Expand Down
4 changes: 4 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ func WithUnimplementedPageError() Option {
func WithAutoBucket(enabled bool) Option {
return func(g *GoFakeS3) { g.autoBucket = true }
}

func WithBaseURL(baseURL string) Option {
return func(g *GoFakeS3) { g.baseURL = baseURL }
}
Loading