1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
package gitlab
import (
"fmt"
"net/http"
)
// MemberRolesService handles communication with the member roles related
// methods of the GitLab API.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/member_roles.html
type MemberRolesService struct {
client *Client
}
// MemberRole represents a GitLab member role.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/member_roles.html
type MemberRole struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
GroupID int `json:"group_id"`
BaseAccessLevel AccessLevelValue `json:"base_access_level"`
AdminCICDVariables bool `json:"admin_cicd_variables,omitempty"`
AdminComplianceFramework bool `json:"admin_compliance_framework,omitempty"`
AdminGroupMembers bool `json:"admin_group_member,omitempty"`
AdminMergeRequests bool `json:"admin_merge_request,omitempty"`
AdminPushRules bool `json:"admin_push_rules,omitempty"`
AdminTerraformState bool `json:"admin_terraform_state,omitempty"`
AdminVulnerability bool `json:"admin_vulnerability,omitempty"`
AdminWebHook bool `json:"admin_web_hook,omitempty"`
ArchiveProject bool `json:"archive_project,omitempty"`
ManageDeployTokens bool `json:"manage_deploy_tokens,omitempty"`
ManageGroupAccesToken bool `json:"manage_group_access_tokens,omitempty"`
ManageMergeRequestSettings bool `json:"manage_merge_request_settings,omitempty"`
ManageProjectAccessToken bool `json:"manage_project_access_tokens,omitempty"`
ManageSecurityPolicyLink bool `json:"manage_security_policy_link,omitempty"`
ReadCode bool `json:"read_code,omitempty"`
ReadRunners bool `json:"read_runners,omitempty"`
ReadDependency bool `json:"read_dependency,omitempty"`
ReadVulnerability bool `json:"read_vulnerability,omitempty"`
RemoveGroup bool `json:"remove_group,omitempty"`
RemoveProject bool `json:"remove_project,omitempty"`
}
// ListMemberRoles gets a list of member roles for a specified group.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/member_roles.html#list-all-member-roles-of-a-group
func (s *MemberRolesService) ListMemberRoles(gid interface{}, options ...RequestOptionFunc) ([]*MemberRole, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/member_roles", PathEscape(group))
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}
var mrs []*MemberRole
resp, err := s.client.Do(req, &mrs)
if err != nil {
return nil, resp, err
}
return mrs, resp, nil
}
// CreateMemberRoleOptions represents the available CreateMemberRole() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/member_roles.html#add-a-member-role-to-a-group
type CreateMemberRoleOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
BaseAccessLevel *AccessLevelValue `url:"base_access_level,omitempty" json:"base_access_level,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
AdminCICDVariables *bool `url:"admin_cicd_variables" json:"admin_cicd_variables,omitempty"`
AdminComplianceFramework *bool `url:"admin_compliance_framework" json:"admin_compliance_framework,omitempty"`
AdminGroupMembers *bool `url:"admin_group_member" json:"admin_group_member,omitempty"`
AdminMergeRequest *bool `url:"admin_merge_request,omitempty" json:"admin_merge_request,omitempty"`
AdminPushRules *bool `url:"admin_push_rules" json:"admin_push_rules,omitempty"`
AdminTerraformState *bool `url:"admin_terraform_state" json:"admin_terraform_state,omitempty"`
AdminVulnerability *bool `url:"admin_vulnerability,omitempty" json:"admin_vulnerability,omitempty"`
AdminWebHook *bool `url:"admin_web_hook" json:"admin_web_hook,omitempty"`
ArchiveProject *bool `url:"archive_project" json:"archive_project,omitempty"`
ManageDeployTokens *bool `url:"manage_deploy_tokens" json:"manage_deploy_tokens,omitempty"`
ManageGroupAccesToken *bool `url:"manage_group_access_tokens" json:"manage_group_access_tokens,omitempty"`
ManageMergeRequestSettings *bool `url:"manage_merge_request_settings" json:"manage_merge_request_settings,omitempty"`
ManageProjectAccessToken *bool `url:"manage_project_access_tokens" json:"manage_project_access_tokens,omitempty"`
ManageSecurityPolicyLink *bool `url:"manage_security_policy_link" json:"manage_security_policy_link,omitempty"`
ReadCode *bool `url:"read_code,omitempty" json:"read_code,omitempty"`
ReadRunners *bool `url:"read_runners" json:"read_runners,omitempty"`
ReadDependency *bool `url:"read_dependency,omitempty" json:"read_dependency,omitempty"`
ReadVulnerability *bool `url:"read_vulnerability,omitempty" json:"read_vulnerability,omitempty"`
RemoveGroup *bool `url:"remove_group" json:"remove_group,omitempty"`
RemoveProject *bool `url:"remove_project" json:"remove_project,omitempty"`
}
// CreateMemberRole creates a new member role for a specified group.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/member_roles.html#add-a-member-role-to-a-group
func (s *MemberRolesService) CreateMemberRole(gid interface{}, opt *CreateMemberRoleOptions, options ...RequestOptionFunc) (*MemberRole, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/member_roles", PathEscape(group))
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
mr := new(MemberRole)
resp, err := s.client.Do(req, mr)
if err != nil {
return nil, resp, err
}
return mr, resp, nil
}
// DeleteMemberRole deletes a member role from a specified group.
//
// Gitlab API docs:
// https://docs.gitlab.com/ee/api/member_roles.html#remove-member-role-of-a-group
func (s *MemberRolesService) DeleteMemberRole(gid interface{}, memberRole int, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/member_roles/%d", PathEscape(group), memberRole)
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
|