feat(admin): add quota group membership endpoints
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
dabfa7ee9d
commit
7a591810ad
2 changed files with 88 additions and 0 deletions
24
admin.go
24
admin.go
|
|
@ -155,6 +155,30 @@ func (s *AdminService) DeleteQuotaGroup(ctx context.Context, quotagroup string)
|
|||
return s.client.Delete(ctx, path)
|
||||
}
|
||||
|
||||
// ListQuotaGroupUsers returns all users in a quota group.
|
||||
func (s *AdminService) ListQuotaGroupUsers(ctx context.Context, quotagroup string) ([]types.User, error) {
|
||||
path := ResolvePath("/api/v1/admin/quota/groups/{quotagroup}/users", Params{"quotagroup": quotagroup})
|
||||
return ListAll[types.User](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// IterQuotaGroupUsers returns an iterator over all users in a quota group.
|
||||
func (s *AdminService) IterQuotaGroupUsers(ctx context.Context, quotagroup string) iter.Seq2[types.User, error] {
|
||||
path := ResolvePath("/api/v1/admin/quota/groups/{quotagroup}/users", Params{"quotagroup": quotagroup})
|
||||
return ListIter[types.User](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// AddQuotaGroupUser adds a user to a quota group.
|
||||
func (s *AdminService) AddQuotaGroupUser(ctx context.Context, quotagroup, username string) error {
|
||||
path := ResolvePath("/api/v1/admin/quota/groups/{quotagroup}/users/{username}", Params{"quotagroup": quotagroup, "username": username})
|
||||
return s.client.Put(ctx, path, nil, nil)
|
||||
}
|
||||
|
||||
// RemoveQuotaGroupUser removes a user from a quota group.
|
||||
func (s *AdminService) RemoveQuotaGroupUser(ctx context.Context, quotagroup, username string) error {
|
||||
path := ResolvePath("/api/v1/admin/quota/groups/{quotagroup}/users/{username}", Params{"quotagroup": quotagroup, "username": username})
|
||||
return s.client.Delete(ctx, path)
|
||||
}
|
||||
|
||||
// ListQuotaRules returns all available quota rules.
|
||||
func (s *AdminService) ListQuotaRules(ctx context.Context) ([]types.QuotaRuleInfo, error) {
|
||||
return ListAll[types.QuotaRuleInfo](ctx, s.client, "/api/v1/admin/quota/rules", nil)
|
||||
|
|
|
|||
|
|
@ -513,6 +513,70 @@ func TestAdminService_DeleteQuotaGroup_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAdminService_ListQuotaGroupUsers_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
t.Errorf("expected GET, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/admin/quota/groups/default/users" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
}
|
||||
json.NewEncoder(w).Encode([]types.User{
|
||||
{ID: 1, UserName: "alice"},
|
||||
{ID: 2, UserName: "bob"},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
users, err := f.Admin.ListQuotaGroupUsers(context.Background(), "default")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(users) != 2 {
|
||||
t.Fatalf("got %d users, want 2", len(users))
|
||||
}
|
||||
if users[0].UserName != "alice" {
|
||||
t.Errorf("got username=%q, want %q", users[0].UserName, "alice")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminService_AddQuotaGroupUser_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPut {
|
||||
t.Errorf("expected PUT, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/admin/quota/groups/default/users/alice" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
if err := f.Admin.AddQuotaGroupUser(context.Background(), "default", "alice"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminService_RemoveQuotaGroupUser_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodDelete {
|
||||
t.Errorf("expected DELETE, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/admin/quota/groups/default/users/alice" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
if err := f.Admin.RemoveQuotaGroupUser(context.Background(), "default", "alice"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminService_ListQuotaRules_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue