Closed brturner-rivian closed 1 month ago
btw - the go-gitlab package is amazingly helpful
Can you share an example (code) of how you're making this call as well as what the cURL command look like?
The generic curl would be curl --request GET --header "PRIVATE-TOKEN: [redacted]" "https://gitlab.com/api/v4/groups/{group id}/billable_members/{user ID}/memberships"
in my case curl --request GET --header "PRIVATE-TOKEN: [redacted]" "https://gitlab.com/api/v4/groups/1891092/billable_members/10024951/memberships"
the payload returned (sanitized) looks like
[{"id":43867499,"source_id":1891092,"source_full_name":"rootgroup","source_members_url":"https://gitlab.com/groups/rootgroup/-/group_members","created_at":"2021-10-20T20:23:07.538Z","expires_at":null,"access_level":{"string_value":"Minimal Access","integer_value":5,"custom_role":null}},{"id":43868462,"source_id":8320573,"source_full_name":"rootgroup / group subgroup","source_members_url":"https://gitlab.com/groups/rootgroup/dc/-/group_members","created_at":"2021-10-20T21:13:35.699Z","expires_at":null,"access_level":{"string_value":"Developer","integer_value":30,"custom_role":null}},{"id":43868701,"source_id":8362854,"source_full_name":"rootgroup / Project Templates","source_members_url":"https://gitlab.com/groups/rootgroup/project-templates/-/group_members","created_at":"2021-10-20T21:24:09.416Z","expires_at":null,"access_level":{"string_value":"Developer","integer_value":30,"custom_role":null}},{"id":43868861,"source_id":19534091,"source_full_name":"rootgroup / File Templates","source_members_url":"https://gitlab.com/rootgroup/file-templates/-/project_members","created_at":"2021-10-20T21:34:31.194Z","expires_at":null,"access_level":{"string_value":"Developer","integer_value":30,"custom_role":null}},{"id":81092669,"source_id":67944258,"source_full_name":"rootgroup / group subgroup / team subgroup / Diagnostics / Fleet Management / YMS","source_members_url":"https://gitlab.com/groups/rootgroup/dc/team-subgroup/diagnostics/team-applications/yms/-/group_members","created_at":"2023-06-30T16:10:17.565Z","expires_at":null,"access_level":{"string_value":"Maintainer","integer_value":40,"custom_role":null}},{"id":83345375,"source_id":43600229,"source_full_name":"rootgroup / group subgroup2 / platform team / Data atlas dbt","source_members_url":"https://gitlab.com/rootgroup/vt/platform-team/data-atlas-dbt/-/project_members","created_at":"2023-08-09T19:11:12.101Z","expires_at":null,"access_level":{"string_value":"Developer","integer_value":30,"custom_role":null}},{"id":88817886,"source_id":45282881,"source_full_name":"rootgroup / group subgroup / team subgroup / Diagnostics / ABC Cloud / cloud-abc-app","source_members_url":"https://gitlab.com/rootgroup/dc/team-subgroup/diagnostics/abc-cloud/cloud-abc-app/-/project_members","created_at":"2023-10-06T17:22:29.508Z","expires_at":null,"access_level":{"string_value":"Maintainer","integer_value":40,"custom_role":null}},{"id":97276664,"source_id":24876491,"source_full_name":"rootgroup / group subgroup2 / platform team / data-ai-hub","source_members_url":"https://gitlab.com/rootgroup/vt/platform-team/data-atlas-terraform/-/project_members","created_at":"2024-03-19T17:01:18.267Z","expires_at":null,"access_level":{"string_value":"Maintainer","integer_value":40,"custom_role":null}}]
platform team
aannddd.... in putting together the go script for this issue I discovered my mistake (passing an invalid group ID). I thought the call required the git client address.
Corrected script: package main
import ( "fmt" "github.com/xanzy/go-gitlab" "log" "time" )
func changeUserPermissions(git *gitlab.Client, userID int, reportOnly bool) { // get all memberships for this user
listMemberOptions := &gitlab.ListMembershipsForBillableGroupMemberOptions{
PerPage: 100,
Page: 1,
}
// Mistake: Group ID, NOT git client address memberships, _, err := git.Groups.ListMembershipsForBillableGroupMember(1891092, userID, listMemberOptions) if err != nil { log.Fatalf("\n \n ", err) } else { fmt.Printf("\n \n Success! : %v", memberships) }
}
func main() { fmt.Printf("\n Running - Change Inactive Users to Minimal Access \n") fmt.Printf("\n Look Back Date : %v \n", time.Now().AddDate(0, 0, -60)) // Create Client baseURL := "https://gitlab.com/" glToken := "[redacted]" reportOnly := true git, err := gitlab.NewClient(glToken, gitlab.WithBaseURL(baseURL)) if err != nil { fmt.Printf("\n fatal ") fmt.Println(git) log.Fatalf("\n Failed to create client: %v", err) } changeUserPermissions(git, 10024951, reportOnly) }
Apologies, please close the issue and thanks for your time
All good, glad it works as expected.
I'm using most recent 'verified' at e4b083f042189e61b547bf3d967027bd6e31bd8e which includes recent changes to ListMembershipsForBillableGroupMemberOptions.
Calls to ListMembershipsForBillableGroupMember fail with message : invalid ID (int or string). (A curl request with identical user ID works).
The error is consistent regardless of wether user ID is valid or not.
Error message produced is