Codevault initial commit

This commit is contained in:
2026-08-16 16:23:14 +03:00
commit 6ee80f1c8f
47 changed files with 3177 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package runcmd
import (
"context"
"fmt"
"github.com/kanootoko/codevault/internal/auth"
"github.com/kanootoko/codevault/internal/db"
)
// AddUser opens (creating if necessary) the database at dbPath and upserts a
// user with the given login/password. It intentionally does not depend on the
// application config.
func AddUser(dbPath, login, password string) error {
database, err := db.Open(dbPath)
if err != nil {
return fmt.Errorf("error on opening database: %w", err)
}
defer func() { _ = database.Close() }()
hash, err := auth.Hash(login, password)
if err != nil {
return fmt.Errorf("error on hashing password: %w", err)
}
users := db.NewUsersRepository(database)
if err := users.Upsert(context.Background(), login, hash); err != nil {
return fmt.Errorf("error on upserting user: %w", err)
}
return nil
}