Compare commits

..

No commits in common. "db41f565ca768d059ba05a943e94b9c41e6a701c" and "ed4a10c9666cbb0f1b5e48cfb2675da339d44505" have entirely different histories.

6 changed files with 1 additions and 84 deletions

View File

@ -235,19 +235,3 @@ func (s *HTTPServer) HandlerAPIUserCreate(w http.ResponseWriter, r *http.Request
w.WriteHeader(http.StatusAccepted)
s.Logger.Infow("Created user.", "req_id", reqID, "remote_addr", r.RemoteAddr, "username", req.Username)
}
func (s *HTTPServer) HandlerAPIUserList(w http.ResponseWriter, r *http.Request) {
reqID := middleware.GetReqID(r.Context())
l, err := s.Users.List()
if err != nil {
s.Logger.Warnw("Error listing users.", "req_id", reqID, "error", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
encoder := json.NewEncoder(w)
if err := encoder.Encode(l); err != nil {
s.Logger.Warnw("Error encoding response.", "req_id", "error", err)
}
}

View File

@ -18,7 +18,3 @@ type ResponseAPIFilePost struct {
ID string `json:"id"`
URL string `json:"url"`
}
type ResponseAPIUserList struct {
Usernames []string `json:"usernames"`
}

View File

@ -1,10 +1,6 @@
package users
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
import "golang.org/x/crypto/bcrypt"
type Role string
@ -20,13 +16,10 @@ type User struct {
Role Role `json:"role"`
}
var ErrNoSuchUser = fmt.Errorf("no such user")
type UserStore interface {
Get(username string) (*User, error)
Store(user *User) error
Delete(username string) error
List() ([]string, error)
}
func (u *User) ValidatePassword(password string) error {

View File

@ -6,8 +6,6 @@ import (
"go.etcd.io/bbolt"
)
var _ UserStore = &BoltUserStore{}
var keyUsers = []byte("users")
type BoltUserStore struct {
@ -69,22 +67,3 @@ func (s *BoltUserStore) Delete(username string) error {
return bkt.Delete([]byte(username))
})
}
func (s *BoltUserStore) List() ([]string, error) {
var ids []string
err := s.db.View(func(tx *bbolt.Tx) error {
bkt := tx.Bucket(keyUsers)
c := bkt.Cursor()
for k, _ := c.First(); k != nil; k, _ = c.Next() {
ids = append(ids, string(k))
}
return nil
})
if err != nil {
return nil, err
}
return ids, nil
}

View File

@ -5,8 +5,6 @@ import (
"sync"
)
var _ UserStore = &MemoryUserStore{}
type MemoryUserStore struct {
users map[string]*User
lock sync.Mutex
@ -39,14 +37,3 @@ func (s *MemoryUserStore) Delete(username string) error {
delete(s.users, username)
return nil
}
func (s *MemoryUserStore) List() ([]string, error) {
s.lock.Lock()
defer s.lock.Unlock()
var ids []string
for k := range s.users {
ids = append(ids, k)
}
return ids, nil
}

View File

@ -47,27 +47,5 @@ func RunUserStoreTest(newFunc func() (func(), users.UserStore), t *testing.T) {
t.Errorf("User mismatch: %s", cmp.Diff(user, userMap[k]))
}
}
l, err := s.List()
if err != nil {
t.Fatalf("Error listing users: %s", err)
}
if len(l) != len(userMap) {
t.Errorf("List wrong amount of users.")
}
for _, username := range l {
if err := s.Delete(username); err != nil {
t.Fatalf("Error deleting user: %s", err)
}
}
l, err = s.List()
if err != nil {
t.Fatalf("Error listing after delete: %s", err)
}
if len(l) != 0 {
t.Fatalf("List is not empty after deleting all")
}
})
}