|
1 | 1 | import HTTP, JSON, JuliaHub |
2 | | -function _get_user_groups_rest(auth::JuliaHub.Authentication) |
3 | | - r = HTTP.get( |
4 | | - JuliaHub._url(auth, "user", "groups"), |
5 | | - JuliaHub._authheaders(auth), |
6 | | - ) |
7 | | - r.status == 200 && return String.(JSON.parse(String(r.body))) |
8 | | - JuliaHub._throw_invalidresponse(r) |
9 | | -end |
10 | | -function _get_user_groups_gql(auth::JuliaHub.Authentication) |
| 2 | +function _get_user_groups(auth::JuliaHub.Authentication)::Vector{String} |
11 | 3 | # Note: this query is newer than the one we use in src/userinfo.jl, and works |
12 | 4 | # with newer JuliaHub versions, whereas the other one specifically works with |
13 | | - # older versions. |
| 5 | + # older versions. This specific query has been tested with JuliaHub 6.8+ |
14 | 6 | userinfo_gql = read(joinpath(@__DIR__, "userInfo.gql"), String) |
15 | | - r = JuliaHub._gql_request(auth, userinfo_gql) |
16 | | - r.status == 200 || error("Invalid response from GQL ($(r.status))\n$(r.body)") |
17 | | - user = only(r.json["data"]["users"]) |
18 | | - String[g["group"]["name"] for g in user["groups"]] |
19 | | -end |
20 | | -function _get_user_groups(auth::JuliaHub.Authentication)::Vector{String} |
21 | | - rest_exception = try |
22 | | - return _get_user_groups_rest(auth) |
23 | | - catch e |
24 | | - @debug "Failed to fetch user groups via REST API" exception = (e, catch_backtrace()) |
25 | | - e, catch_backtrace() |
26 | | - end |
27 | 7 | try |
28 | | - return _get_user_groups_gql(auth) |
| 8 | + r = JuliaHub._gql_request(auth, userinfo_gql) |
| 9 | + r.status == 200 || error("Invalid response from GQL ($(r.status))\n$(r.body)") |
| 10 | + user = only(r.json["data"]["users"]) |
| 11 | + return String[g["group"]["name"] for g in user["groups"]] |
29 | 12 | catch e |
30 | 13 | @error "Unable to determine valid user groups" |
31 | 14 | @error "> REST API failure" exception = rest_exception |
|
0 commit comments