github.com/aiven/aiven-go-client@v1.36.0/account_teams.go (about)

     1  package aiven
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  )
     7  
     8  type (
     9  	// AccountTeamsHandler Aiven go-client handler for Account Teams
    10  	AccountTeamsHandler struct {
    11  		client *Client
    12  	}
    13  
    14  	// AccountTeam represents account team
    15  	AccountTeam struct {
    16  		AccountId  string     `json:"account_id,omitempty"`
    17  		Id         string     `json:"team_id,omitempty"`
    18  		Name       string     `json:"team_name"`
    19  		CreateTime *time.Time `json:"create_time,omitempty"`
    20  		UpdateTime *time.Time `json:"update_time,omitempty"`
    21  	}
    22  
    23  	// AccountTeamsResponse represents account list of teams API response
    24  	AccountTeamsResponse struct {
    25  		APIResponse
    26  		Teams []AccountTeam `json:"teams"`
    27  	}
    28  
    29  	// AccountTeamResponse represents account team API response
    30  	AccountTeamResponse struct {
    31  		APIResponse
    32  		Team AccountTeam `json:"team"`
    33  	}
    34  )
    35  
    36  // List returns a list of all existing account teams
    37  func (h AccountTeamsHandler) List(accountId string) (*AccountTeamsResponse, error) {
    38  	if accountId == "" {
    39  		return nil, errors.New("cannot get a list of teams for an account when account id is empty")
    40  	}
    41  
    42  	path := buildPath("account", accountId, "teams")
    43  	bts, err := h.client.doGetRequest(path, nil)
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  
    48  	var rsp AccountTeamsResponse
    49  	if errR := checkAPIResponse(bts, &rsp); errR != nil {
    50  		return nil, errR
    51  	}
    52  
    53  	return &rsp, nil
    54  }
    55  
    56  // Get retrieves an existing account team by account and team id`s
    57  func (h AccountTeamsHandler) Get(accountId, teamId string) (*AccountTeamResponse, error) {
    58  	if accountId == "" || teamId == "" {
    59  		return nil, errors.New("cannot get account team where account id or team id is empty")
    60  	}
    61  
    62  	path := buildPath("account", accountId, "team", teamId)
    63  	bts, err := h.client.doGetRequest(path, nil)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  
    68  	var rsp AccountTeamResponse
    69  	if errR := checkAPIResponse(bts, &rsp); errR != nil {
    70  		return nil, errR
    71  	}
    72  
    73  	return &rsp, nil
    74  }
    75  
    76  // Create creates an account team
    77  func (h AccountTeamsHandler) Create(accountId string, team AccountTeam) (*AccountTeamResponse, error) {
    78  	if accountId == "" {
    79  		return nil, errors.New("cannot get create a team where account id is empty")
    80  	}
    81  
    82  	path := buildPath("account", accountId, "teams")
    83  	bts, err := h.client.doPostRequest(path, team)
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  
    88  	var rsp AccountTeamResponse
    89  	if errR := checkAPIResponse(bts, &rsp); errR != nil {
    90  		return nil, errR
    91  	}
    92  
    93  	return &rsp, nil
    94  }
    95  
    96  // Update updates an account team
    97  func (h AccountTeamsHandler) Update(accountId, teamId string, team AccountTeam) (*AccountTeamResponse, error) {
    98  	if accountId == "" {
    99  		return nil, errors.New("cannot get create a team where account id is empty")
   100  	}
   101  
   102  	path := buildPath("account", accountId, "team", teamId)
   103  	bts, err := h.client.doPutRequest(path, team)
   104  	if err != nil {
   105  		return nil, err
   106  	}
   107  
   108  	var rsp AccountTeamResponse
   109  	if errR := checkAPIResponse(bts, &rsp); errR != nil {
   110  		return nil, errR
   111  	}
   112  
   113  	return &rsp, nil
   114  }
   115  
   116  // Delete deletes an account team
   117  func (h AccountTeamsHandler) Delete(accountId, teamId string) error {
   118  	if accountId == "" || teamId == "" {
   119  		return errors.New("cannot get delete an accounts team where account id or team id is empty")
   120  	}
   121  
   122  	path := buildPath("account", accountId, "team", teamId)
   123  	bts, err := h.client.doDeleteRequest(path, nil)
   124  	if err != nil {
   125  		return err
   126  	}
   127  
   128  	return checkAPIResponse(bts, nil)
   129  }