feat(lab6): add observability and SLO burn-rate alerts

This commit is contained in:
2026-11-15 06:54:54 +03:00
parent 470d9d6f1e
commit 63c1f06b84
204 changed files with 25348 additions and 37 deletions
+32
View File
@@ -0,0 +1,32 @@
package security
import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"fmt"
)
const sessionTokenBytes = 32
func GenerateSessionToken() (string, []byte, error) {
randomBytes := make([]byte, sessionTokenBytes)
if _, err := rand.Read(randomBytes); err != nil {
return "", nil, fmt.Errorf("generate session token: %w", err)
}
token := base64.RawURLEncoding.EncodeToString(randomBytes)
tokenHash := HashSessionToken(token)
return token, tokenHash, nil
}
func HashSessionToken(token string) []byte {
digest := sha256.Sum256([]byte(token))
hash := make([]byte, len(digest))
copy(hash, digest[:])
return hash
}