1package backend
 2
 3import (
 4	"golang.org/x/crypto/ssh"
 5)
 6
 7// User is an interface representing a user.
 8type User interface {
 9	// Username returns the user's username.
10	Username() string
11	// IsAdmin returns whether the user is an admin.
12	IsAdmin() bool
13	// PublicKeys returns the user's public keys.
14	PublicKeys() []ssh.PublicKey
15}
16
17// UserAccess is an interface that handles user access to repositories.
18type UserAccess interface {
19	// AccessLevel returns the access level of the username to the repository.
20	AccessLevel(repo string, username string) AccessLevel
21	// AccessLevelByPublicKey returns the access level of the public key to the repository.
22	AccessLevelByPublicKey(repo string, pk ssh.PublicKey) AccessLevel
23}
24
25// UserStore is an interface for managing users.
26type UserStore interface {
27	// User finds the given user.
28	User(username string) (User, error)
29	// UserByPublicKey finds the user with the given public key.
30	UserByPublicKey(pk ssh.PublicKey) (User, error)
31	// Users returns a list of all users.
32	Users() ([]string, error)
33	// CreateUser creates a new user.
34	CreateUser(username string, opts UserOptions) (User, error)
35	// DeleteUser deletes a user.
36	DeleteUser(username string) error
37	// SetUsername sets the username of the user.
38	SetUsername(oldUsername string, newUsername string) error
39	// SetAdmin sets whether the user is an admin.
40	SetAdmin(username string, admin bool) error
41	// AddPublicKey adds a public key to the user.
42	AddPublicKey(username string, pk ssh.PublicKey) error
43	// RemovePublicKey removes a public key from the user.
44	RemovePublicKey(username string, pk ssh.PublicKey) error
45	// ListPublicKeys lists the public keys of the user.
46	ListPublicKeys(username string) ([]ssh.PublicKey, error)
47}
48
49// UserOptions are options for creating a user.
50type UserOptions struct {
51	// Admin is whether the user is an admin.
52	Admin bool
53	// PublicKeys are the user's public keys.
54	PublicKeys []ssh.PublicKey
55}