feat(step3): тенанты read-through Redis (индекс accessKey→tenant, fallback в auth, бэкфилл на старте)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"shared-sqs/app/persistence"
|
||||
"shared-sqs/app/tenant"
|
||||
)
|
||||
|
||||
@@ -59,6 +61,17 @@ func AuthMiddleware(store *tenant.TenantStore) func(http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
t, ok := store.GetByAccessKey(accessKeyID)
|
||||
if !ok {
|
||||
// Read-through из Redis: тенант мог быть создан control-plane / другим
|
||||
// инстансом и ещё не попасть в локальную память.
|
||||
if raw, found := persistence.LoadTenantByAccessKey(accessKeyID); found {
|
||||
var loaded tenant.Tenant
|
||||
if err := json.Unmarshal(raw, &loaded); err == nil {
|
||||
store.LoadTenant(&loaded)
|
||||
t, ok = store.GetByAccessKey(accessKeyID)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !ok || !t.Active {
|
||||
writeSQSAuthError(w, "InvalidClientTokenId", "The security token included in the request is invalid")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user