feat(slurmdb): add UsersService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
155
internal/slurm/slurmdb_users.go
Normal file
155
internal/slurm/slurmdb_users.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// GetUsersOptions specifies optional parameters for GetUsers and GetUser.
|
||||
type GetUsersOptions struct {
|
||||
AdminLevel *string `url:"admin_level,omitempty"`
|
||||
DefaultAccount *string `url:"default_account,omitempty"`
|
||||
DefaultWckey *string `url:"default_wckey,omitempty"`
|
||||
WithAssocs *string `url:"with_assocs,omitempty"`
|
||||
WithCoords *string `url:"with_coords,omitempty"`
|
||||
WithDeleted *string `url:"with_deleted,omitempty"`
|
||||
WithWckeys *string `url:"with_wckeys,omitempty"`
|
||||
WithoutDefaults *string `url:"without_defaults,omitempty"`
|
||||
}
|
||||
|
||||
// GetUsers lists all users.
|
||||
func (s *SlurmdbUsersService) GetUsers(ctx context.Context, opts *GetUsersOptions) (*OpenapiUsersResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/users"
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if opts != nil {
|
||||
u, parseErr := url.Parse(req.URL.String())
|
||||
if parseErr != nil {
|
||||
return nil, nil, parseErr
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.AdminLevel != nil {
|
||||
q.Set("admin_level", *opts.AdminLevel)
|
||||
}
|
||||
if opts.DefaultAccount != nil {
|
||||
q.Set("default_account", *opts.DefaultAccount)
|
||||
}
|
||||
if opts.DefaultWckey != nil {
|
||||
q.Set("default_wckey", *opts.DefaultWckey)
|
||||
}
|
||||
if opts.WithAssocs != nil {
|
||||
q.Set("with_assocs", *opts.WithAssocs)
|
||||
}
|
||||
if opts.WithCoords != nil {
|
||||
q.Set("with_coords", *opts.WithCoords)
|
||||
}
|
||||
if opts.WithDeleted != nil {
|
||||
q.Set("with_deleted", *opts.WithDeleted)
|
||||
}
|
||||
if opts.WithWckeys != nil {
|
||||
q.Set("with_wckeys", *opts.WithWckeys)
|
||||
}
|
||||
if opts.WithoutDefaults != nil {
|
||||
q.Set("without_defaults", *opts.WithoutDefaults)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiUsersResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// GetUser gets a single user by name.
|
||||
func (s *SlurmdbUsersService) GetUser(ctx context.Context, userName string, opts *GetUsersOptions) (*OpenapiUsersResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/user/%s", userName)
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if opts != nil {
|
||||
u, parseErr := url.Parse(req.URL.String())
|
||||
if parseErr != nil {
|
||||
return nil, nil, parseErr
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.WithDeleted != nil {
|
||||
q.Set("with_deleted", *opts.WithDeleted)
|
||||
}
|
||||
if opts.WithAssocs != nil {
|
||||
q.Set("with_assocs", *opts.WithAssocs)
|
||||
}
|
||||
if opts.WithCoords != nil {
|
||||
q.Set("with_coords", *opts.WithCoords)
|
||||
}
|
||||
if opts.WithWckeys != nil {
|
||||
q.Set("with_wckeys", *opts.WithWckeys)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiUsersResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// PostUsers updates users.
|
||||
func (s *SlurmdbUsersService) PostUsers(ctx context.Context, body *OpenapiUsersResp) (*OpenapiUsersResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/users"
|
||||
req, err := s.client.NewRequest("POST", path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiUsersResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// PostUsersAssociation adds users with conditional association.
|
||||
func (s *SlurmdbUsersService) PostUsersAssociation(ctx context.Context, body *OpenapiUsersAddCondResp) (*OpenapiUsersAddCondRespStr, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/users_association"
|
||||
req, err := s.client.NewRequest("POST", path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiUsersAddCondRespStr
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// DeleteUser deletes a user by name.
|
||||
func (s *SlurmdbUsersService) DeleteUser(ctx context.Context, userName string) (*OpenapiResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/user/%s", userName)
|
||||
req, err := s.client.NewRequest("DELETE", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user