summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2025-10-12 19:13:48 +0900
committerhaturatu <taro@eyes4you.org>2025-10-12 19:13:55 +0900
commit98189b5926ea48dae90ee9e01bfcb6d2c69c32a6 (patch)
tree93a071493d245ac716cb0add3915e6347156c6b4
parent0cf0d195218fc289f2a04db5535d8fbbd96c988c (diff)
chore(git): gitignore
-rw-r--r--.gitignore4
-rw-r--r--cmd/admin-cli/main.go62
2 files changed, 64 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 9f3fa75..1b4b73a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
# Binaries
-auth-proxy-server
-admin-cli
+/auth-proxy-server
+/admin-cli
# DB file
auth.db
diff --git a/cmd/admin-cli/main.go b/cmd/admin-cli/main.go
new file mode 100644
index 0000000..fdcfe2e
--- /dev/null
+++ b/cmd/admin-cli/main.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "auth-proxy/database"
+ "auth-proxy/logging"
+ "auth-proxy/models"
+ "auth-proxy/utils"
+ "flag"
+ "fmt"
+ "os"
+
+ "github.com/joho/godotenv"
+)
+
+func main() {
+ // Initialize logging
+ logging.InitLoggers()
+
+ // Load .env file
+ if err := godotenv.Load(); err != nil {
+ logging.AppLog.Info("No .env file found, using environment variables")
+ }
+
+ username := flag.String("username", "", "Username for the new admin user")
+ password := flag.String("password", "", "Password for the new admin user")
+ flag.Parse()
+
+ if *username == "" || *password == "" {
+ logging.AppLog.Error("Both --username and --password flags are required")
+ os.Exit(1)
+ }
+
+ // Validate password policy
+ if ok, message := utils.ValidatePassword(*password); !ok {
+ logging.AppLog.Error("Password does not meet the policy", "reason", message)
+ os.Exit(1)
+ }
+
+ // Initialize DB connection
+ database.InitDB()
+ defer database.CloseDB()
+
+ // Check if user already exists
+ existingUser, err := models.GetUserByUsername(*username)
+ if err != nil {
+ logging.AppLog.Error("Error checking for existing user", "error", err)
+ os.Exit(1)
+ }
+ if existingUser != nil {
+ logging.AppLog.Error(fmt.Sprintf("User '%s' already exists.", *username))
+ os.Exit(1)
+ }
+
+ // Create admin user
+ _, err = models.CreateUser(*username, *password, "admin")
+ if err != nil {
+ logging.AppLog.Error("Failed to create admin user", "error", err)
+ os.Exit(1)
+ }
+
+ fmt.Printf("Admin user '%s' created successfully.\n", *username)
+}