feat(slurmdb): add AccountsService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
136
internal/slurm/slurmdb_accounts.go
Normal file
136
internal/slurm/slurmdb_accounts.go
Normal file
@@ -0,0 +1,136 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// GetAccountsOptions specifies optional parameters for GetAccounts and GetAccount.
|
||||
type GetAccountsOptions struct {
|
||||
Description *string `url:"description,omitempty"`
|
||||
WithAssocs *string `url:"with_assocs,omitempty"`
|
||||
WithCoords *string `url:"with_coords,omitempty"`
|
||||
WithDeleted *string `url:"with_deleted,omitempty"`
|
||||
}
|
||||
|
||||
// GetAccounts lists all accounts.
|
||||
func (s *SlurmdbAccountsService) GetAccounts(ctx context.Context, opts *GetAccountsOptions) (*OpenapiAccountsResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/accounts"
|
||||
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.Description != nil {
|
||||
q.Set("description", *opts.Description)
|
||||
}
|
||||
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)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiAccountsResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// GetAccount gets a single account by name.
|
||||
func (s *SlurmdbAccountsService) GetAccount(ctx context.Context, accountName string, opts *GetAccountsOptions) (*OpenapiAccountsResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/account/%s", accountName)
|
||||
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.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)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiAccountsResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// PostAccounts updates accounts.
|
||||
func (s *SlurmdbAccountsService) PostAccounts(ctx context.Context, body *OpenapiAccountsResp) (*OpenapiAccountsResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/accounts"
|
||||
req, err := s.client.NewRequest("POST", path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiAccountsResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// PostAccountsAssociation adds accounts with conditional association.
|
||||
func (s *SlurmdbAccountsService) PostAccountsAssociation(ctx context.Context, body *OpenapiAccountsAddCondResp) (*OpenapiAccountsAddCondRespStr, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/accounts_association"
|
||||
req, err := s.client.NewRequest("POST", path, body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiAccountsAddCondRespStr
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// DeleteAccount deletes an account by name.
|
||||
func (s *SlurmdbAccountsService) DeleteAccount(ctx context.Context, accountName string) (*OpenapiAccountsRemovedResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/account/%s", accountName)
|
||||
req, err := s.client.NewRequest("DELETE", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiAccountsRemovedResp
|
||||
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