github.com/aiven/aiven-go-client@v1.36.0/account_team_projects.go (about) 1 package aiven 2 3 import "errors" 4 5 type ( 6 // AccountTeamProjectsHandler Aiven go-client handler for Account Team Projects 7 AccountTeamProjectsHandler struct { 8 client *Client 9 } 10 11 // AccountTeamProject represents account team associated project 12 AccountTeamProject struct { 13 ProjectName string `json:"project_name,omitempty"` 14 // team type could be one of the following values: admin, developer, operator amd read_only 15 TeamType string `json:"team_type,omitempty"` 16 } 17 18 // AccountTeamProjectsResponse represents account team list of associated projects API response 19 AccountTeamProjectsResponse struct { 20 APIResponse 21 Projects []AccountTeamProject `json:"projects"` 22 } 23 ) 24 25 // List returns a list of all existing account team projects 26 func (h AccountTeamProjectsHandler) List(accountId, teamId string) (*AccountTeamProjectsResponse, error) { 27 if accountId == "" || teamId == "" { 28 return nil, errors.New("cannot get a list of team projects when account id or team id is empty") 29 } 30 31 path := buildPath("account", accountId, "team", teamId, "projects") 32 bts, err := h.client.doGetRequest(path, nil) 33 if err != nil { 34 return nil, err 35 } 36 37 var rsp AccountTeamProjectsResponse 38 if errR := checkAPIResponse(bts, &rsp); errR != nil { 39 return nil, errR 40 } 41 return &rsp, nil 42 } 43 44 // Create creates account team project association 45 func (h AccountTeamProjectsHandler) Create(accountId, teamId string, p AccountTeamProject) error { 46 if accountId == "" || teamId == "" { 47 return errors.New("cannot create team projects association when account id or team id is empty") 48 } 49 50 if p.ProjectName == "" { 51 return errors.New("cannot create team projects association when project name is empty") 52 } 53 54 path := buildPath("account", accountId, "team", teamId, "project", p.ProjectName) 55 bts, err := h.client.doPostRequest(path, AccountTeamProject{TeamType: p.TeamType}) 56 if err != nil { 57 return err 58 } 59 60 return checkAPIResponse(bts, nil) 61 } 62 63 // Update updates account team project association 64 func (h AccountTeamProjectsHandler) Update(accountId, teamId string, p AccountTeamProject) error { 65 if accountId == "" || teamId == "" { 66 return errors.New("cannot update team projects association when account id or team id is empty") 67 } 68 69 if p.ProjectName == "" { 70 return errors.New("cannot update team projects association when project name is empty") 71 } 72 73 path := buildPath("account", accountId, "team", teamId, "project", p.ProjectName) 74 bts, err := h.client.doPutRequest(path, AccountTeamProject{TeamType: p.TeamType}) 75 if err != nil { 76 return err 77 } 78 79 return checkAPIResponse(bts, nil) 80 } 81 82 // Delete deletes account team project association 83 func (h AccountTeamProjectsHandler) Delete(accountId, teamId, projectName string) error { 84 if accountId == "" || teamId == "" { 85 return errors.New("cannot update team projects association when account id or team id is empty") 86 } 87 88 if projectName == "" { 89 return errors.New("cannot update team projects association when project name is empty") 90 } 91 92 path := buildPath("account", accountId, "team", teamId, "project", projectName) 93 bts, err := h.client.doDeleteRequest(path, nil) 94 if err != nil { 95 return err 96 } 97 98 return checkAPIResponse(bts, nil) 99 }