feat(step3): тенанты read-through Redis (индекс accessKey→tenant, fallback в auth, бэкфилл на старте)

This commit is contained in:
Repinoid
2026-10-10 16:09:52 +03:00
parent 1862f058be
commit 8e22bc4b9b
3 changed files with 50 additions and 0 deletions
+13
View File
@@ -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