user.go

 1package store
 2
 3import (
 4	"context"
 5
 6	"github.com/charmbracelet/soft-serve/pkg/db"
 7	"github.com/charmbracelet/soft-serve/pkg/db/models"
 8	"golang.org/x/crypto/ssh"
 9)
10
11// UserStore is an interface for managing users.
12type UserStore interface {
13	GetUserByID(ctx context.Context, h db.Handler, id int64) (models.User, error)
14	FindUserByUsername(ctx context.Context, h db.Handler, username string) (models.User, error)
15	FindUserByPublicKey(ctx context.Context, h db.Handler, pk ssh.PublicKey) (models.User, error)
16	FindUserByAccessToken(ctx context.Context, h db.Handler, token string) (models.User, error)
17	GetAllUsers(ctx context.Context, h db.Handler) ([]models.User, error)
18	CreateUser(ctx context.Context, h db.Handler, username string, isAdmin bool, pks []ssh.PublicKey, emails []string) error
19	DeleteUserByUsername(ctx context.Context, h db.Handler, username string) error
20	SetUsernameByUsername(ctx context.Context, h db.Handler, username string, newUsername string) error
21	SetAdminByUsername(ctx context.Context, h db.Handler, username string, isAdmin bool) error
22	AddPublicKeyByUsername(ctx context.Context, h db.Handler, username string, pk ssh.PublicKey) error
23	RemovePublicKeyByUsername(ctx context.Context, h db.Handler, username string, pk ssh.PublicKey) error
24	ListPublicKeysByUserID(ctx context.Context, h db.Handler, id int64) ([]ssh.PublicKey, error)
25	ListPublicKeysByUsername(ctx context.Context, h db.Handler, username string) ([]ssh.PublicKey, error)
26	SetUserPassword(ctx context.Context, h db.Handler, userID int64, password string) error
27	SetUserPasswordByUsername(ctx context.Context, h db.Handler, username string, password string) error
28
29	AddUserEmail(ctx context.Context, h db.Handler, userID int64, email string, isPrimary bool) error
30	ListUserEmails(ctx context.Context, h db.Handler, userID int64) ([]models.UserEmail, error)
31	RemoveUserEmail(ctx context.Context, h db.Handler, userID int64, email string) error
32	SetUserPrimaryEmail(ctx context.Context, h db.Handler, userID int64, email string) error
33}