Add log for limited users

This commit is contained in:
Taras Kushnir
2025-11-18 19:18:48 +02:00
parent 18445c5dde
commit f8c1bbbaae
2 changed files with 50 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
package main
import (
"flag"
"fmt"
"os"
"strconv"
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/common"
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/config"
)
var (
flagMode = flag.String("mode", "", "encrypt | decrypt")
envFileFlag = flag.String("env", "", "Path to .env file, 'stdin' or empty")
idFlag = flag.String("id", "", "Actual ID")
)
func main() {
flag.Parse()
env, err := common.NewEnvMap(*envFileFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
cfg := config.NewEnvConfig(env.Get)
hasher := common.NewIDHasher(cfg.Get(common.IDHasherSaltKey))
switch *flagMode {
case "encrypt":
id, err := strconv.Atoi(*idFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "Error deserializing ID: %v\n", err)
os.Exit(1)
}
value := hasher.Encrypt(id)
fmt.Print(value)
case "decrypt":
id, err := hasher.Decrypt(*idFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "Error decrypting ID: %v\n", err)
os.Exit(1)
}
fmt.Print(id)
}
}
+1
View File
@@ -369,6 +369,7 @@ func (am *AuthMiddleware) APIKey(keyFunc func(r *http.Request) string) func(http
// if user is not an active subscriber, their properties and orgs might still exist but should not allow API
if softRestriction, err := am.Limiter.Evaluate(ctx, apiKey.UserID.Int32); (err == nil) && !softRestriction {
slog.WarnContext(ctx, "User is limited", "userID", apiKey.UserID.Int32)
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}