Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: read-write v4AuthPair map with lock #8

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
refactor: lock read-write of v4AuthPair map
saw-jan committed Jul 16, 2024
commit 9ff0af7626253e118ed7d8abc7dadbe4eba4d364
8 changes: 8 additions & 0 deletions gofakes3.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

@@ -42,6 +43,7 @@ type GoFakeS3 struct {

// simple v4 signature
v4AuthPair map[string]string
mu sync.RWMutex
}

// New creates a new GoFakeS3 using the supplied Backend. Backends are pluggable.
@@ -99,13 +101,17 @@ func (g *GoFakeS3) Server() http.Handler {
}

func (g *GoFakeS3) AddAuthKeys(p map[string]string) {
g.mu.Lock()
defer g.mu.Unlock()
for k, v := range p {
g.v4AuthPair[k] = v
}
signature.StoreKeys(g.v4AuthPair)
}

func (g *GoFakeS3) DelAuthKeys(p []string) {
g.mu.Lock()
defer g.mu.Unlock()
for _, v := range p {
delete(g.v4AuthPair, v)
}
@@ -114,6 +120,8 @@ func (g *GoFakeS3) DelAuthKeys(p []string) {

func (g *GoFakeS3) authMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, rq *http.Request) {
g.mu.RLock()
defer g.mu.RUnlock()
if len(g.v4AuthPair) > 0 {
if result := signature.V4SignVerify(rq); result != signature.ErrNone {
g.log.Print(LogWarn, "Access Denied:", rq.RemoteAddr, "=>", rq.URL)