-
Notifications
You must be signed in to change notification settings - Fork 0
fix(auth): align GraphQL queries/mutations with backend schema and add nubi fallbacks #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9ef699a
fix(auth): align GraphQL queries and mutations with backend schema
a0ccaa8
fix(nubi): add tenant-wide fallback and support --account-id in query
bc598fb
refactor(auth): use custom unmarshaler for group roles and trim permi…
2c6da0e
fix(nubi): use isolated response struct for ListAgents and ListTools …
aef3080
fix(auth): add omitempty to Class in customRolePermissionInput and ad…
9f23479
fix(auth,nubi): preserve unmarshal error on group roles and make fall…
50f5c19
fix(auth): validate that permission module is not empty
b022330
fix(nubi,auth): add context to ListAgents and ListTools, and skip emp…
e9e49e9
refactor(nubi,auth): extract listWithAccountFallback helper and retur…
d39d4a6
fix(auth,nubi): handle null/empty unmarshaling, wrap fallback errors,…
75a933e
fix(auth,nubi): avoid redundant unmarshal and guard against empty/nul…
0dc719e
fix(nubi): defensively check that response key exists and has data be…
b510334
fix(auth,nubi): always pass permissions variable and wrap fallback er…
f34fd84
fix(auth,nubi): allowlist query names, pass nil description variable,…
0983f1f
fix(nubi): format fallback error with %v instead of multiple %w
7166f3d
fix(auth): explicitly pass nil description variable in authGroupsCrea…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| package cmd | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||
| "bytes" | ||||||||||||||||||||||||||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| "github.com/nudgebee/nbctl/pkg/client" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -13,6 +15,47 @@ var authGroupsCmd = &cobra.Command{ | |||||||||||||||||||||||||||||||||||||||||||
| Short: "Manage tenant user groups", | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| type groupRoleItem struct { | ||||||||||||||||||||||||||||||||||||||||||||
| Role string `json:"role"` | ||||||||||||||||||||||||||||||||||||||||||||
| EntityType string `json:"entity_type"` | ||||||||||||||||||||||||||||||||||||||||||||
| EntityID string `json:"entity_id"` | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| type groupRolesField []groupRoleItem | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| func (g *groupRolesField) UnmarshalJSON(data []byte) error { | ||||||||||||||||||||||||||||||||||||||||||||
| trimmed := bytes.TrimSpace(data) | ||||||||||||||||||||||||||||||||||||||||||||
| if len(trimmed) == 0 || string(trimmed) == "null" || string(trimmed) == `""` { | ||||||||||||||||||||||||||||||||||||||||||||
| *g = nil | ||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
blue4209211 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var items []groupRoleItem | ||||||||||||||||||||||||||||||||||||||||||||
| err := json.Unmarshal(trimmed, &items) | ||||||||||||||||||||||||||||||||||||||||||||
| if err == nil { | ||||||||||||||||||||||||||||||||||||||||||||
| *g = items | ||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var str string | ||||||||||||||||||||||||||||||||||||||||||||
| if errStr := json.Unmarshal(trimmed, &str); errStr != nil { | ||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||
|
blue4209211 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| str = strings.TrimSpace(str) | ||||||||||||||||||||||||||||||||||||||||||||
| if str == "" || str == "null" { | ||||||||||||||||||||||||||||||||||||||||||||
| *g = nil | ||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if errArr := json.Unmarshal([]byte(str), &items); errArr != nil { | ||||||||||||||||||||||||||||||||||||||||||||
| return errArr | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| *g = items | ||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
blue4209211 marked this conversation as resolved.
blue4209211 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var authGroupsListCmd = &cobra.Command{ | ||||||||||||||||||||||||||||||||||||||||||||
| Use: "list", | ||||||||||||||||||||||||||||||||||||||||||||
| Short: "List user groups with assigned roles and member count", | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -26,8 +69,8 @@ var authGroupsListCmd = &cobra.Command{ | |||||||||||||||||||||||||||||||||||||||||||
| id | ||||||||||||||||||||||||||||||||||||||||||||
| name | ||||||||||||||||||||||||||||||||||||||||||||
| description | ||||||||||||||||||||||||||||||||||||||||||||
| roles | ||||||||||||||||||||||||||||||||||||||||||||
| user_count | ||||||||||||||||||||||||||||||||||||||||||||
| group_roles | ||||||||||||||||||||||||||||||||||||||||||||
| member_count | ||||||||||||||||||||||||||||||||||||||||||||
| created_at | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -37,12 +80,12 @@ var authGroupsListCmd = &cobra.Command{ | |||||||||||||||||||||||||||||||||||||||||||
| var respData struct { | ||||||||||||||||||||||||||||||||||||||||||||
| UsergroupsList struct { | ||||||||||||||||||||||||||||||||||||||||||||
| Rows []struct { | ||||||||||||||||||||||||||||||||||||||||||||
| ID string `json:"id"` | ||||||||||||||||||||||||||||||||||||||||||||
| Name string `json:"name"` | ||||||||||||||||||||||||||||||||||||||||||||
| Description string `json:"description"` | ||||||||||||||||||||||||||||||||||||||||||||
| Roles []string `json:"roles"` | ||||||||||||||||||||||||||||||||||||||||||||
| UserCount int `json:"user_count"` | ||||||||||||||||||||||||||||||||||||||||||||
| CreatedAt string `json:"created_at"` | ||||||||||||||||||||||||||||||||||||||||||||
| ID string `json:"id"` | ||||||||||||||||||||||||||||||||||||||||||||
| Name string `json:"name"` | ||||||||||||||||||||||||||||||||||||||||||||
| Description string `json:"description"` | ||||||||||||||||||||||||||||||||||||||||||||
| GroupRoles groupRolesField `json:"group_roles"` | ||||||||||||||||||||||||||||||||||||||||||||
| MemberCount int `json:"member_count"` | ||||||||||||||||||||||||||||||||||||||||||||
| CreatedAt string `json:"created_at"` | ||||||||||||||||||||||||||||||||||||||||||||
| } `json:"rows"` | ||||||||||||||||||||||||||||||||||||||||||||
| } `json:"usergroups_list"` | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -61,16 +104,23 @@ var authGroupsListCmd = &cobra.Command{ | |||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| var rows []groupRow | ||||||||||||||||||||||||||||||||||||||||||||
| for _, r := range respData.UsergroupsList.Rows { | ||||||||||||||||||||||||||||||||||||||||||||
| var roles []string | ||||||||||||||||||||||||||||||||||||||||||||
| for _, item := range r.GroupRoles { | ||||||||||||||||||||||||||||||||||||||||||||
| if item.Role != "" { | ||||||||||||||||||||||||||||||||||||||||||||
| roles = append(roles, item.Role) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
blue4209211 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| rolesStr := "-" | ||||||||||||||||||||||||||||||||||||||||||||
| if len(r.Roles) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||
| rolesStr = strings.Join(r.Roles, ", ") | ||||||||||||||||||||||||||||||||||||||||||||
| if len(roles) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||
| rolesStr = strings.Join(roles, ", ") | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| rows = append(rows, groupRow{ | ||||||||||||||||||||||||||||||||||||||||||||
| ID: r.ID, | ||||||||||||||||||||||||||||||||||||||||||||
| Name: r.Name, | ||||||||||||||||||||||||||||||||||||||||||||
| Description: r.Description, | ||||||||||||||||||||||||||||||||||||||||||||
| Roles: rolesStr, | ||||||||||||||||||||||||||||||||||||||||||||
| UserCount: r.UserCount, | ||||||||||||||||||||||||||||||||||||||||||||
| UserCount: r.MemberCount, | ||||||||||||||||||||||||||||||||||||||||||||
| CreatedAt: r.CreatedAt, | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -103,32 +153,38 @@ var authGroupsCreateCmd = &cobra.Command{ | |||||||||||||||||||||||||||||||||||||||||||
| graphqlClient := client.NewClient() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| req := client.NewRequest(` | ||||||||||||||||||||||||||||||||||||||||||||
| mutation CreateUserGroup($request: UserGroupCreateInput!) { | ||||||||||||||||||||||||||||||||||||||||||||
| usergroup_create(request: $request) { | ||||||||||||||||||||||||||||||||||||||||||||
| mutation CreateUserGroup($name: String!, $description: String) { | ||||||||||||||||||||||||||||||||||||||||||||
| usergroup_create(name: $name, description: $description) { | ||||||||||||||||||||||||||||||||||||||||||||
| id | ||||||||||||||||||||||||||||||||||||||||||||
| name | ||||||||||||||||||||||||||||||||||||||||||||
| status | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| `) | ||||||||||||||||||||||||||||||||||||||||||||
| req.Var("request", map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||
| "name": groupName, | ||||||||||||||||||||||||||||||||||||||||||||
| "description": desc, | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
| req.Var("name", groupName) | ||||||||||||||||||||||||||||||||||||||||||||
| if desc != "" { | ||||||||||||||||||||||||||||||||||||||||||||
| req.Var("description", desc) | ||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
|
blue4209211 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
| req.Var("description", nil) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
blue4209211 marked this conversation as resolved.
blue4209211 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| var respData struct { | ||||||||||||||||||||||||||||||||||||||||||||
| UsergroupCreate struct { | ||||||||||||||||||||||||||||||||||||||||||||
| ID string `json:"id"` | ||||||||||||||||||||||||||||||||||||||||||||
| Name string `json:"name"` | ||||||||||||||||||||||||||||||||||||||||||||
| Status string `json:"status"` | ||||||||||||||||||||||||||||||||||||||||||||
| ID string `json:"id"` | ||||||||||||||||||||||||||||||||||||||||||||
| } `json:"usergroup_create"` | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if err := graphqlClient.Run(cmd.Context(), req, &respData); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| format.GetFormat().Print(respData.UsergroupCreate) | ||||||||||||||||||||||||||||||||||||||||||||
| format.GetFormat().Print(struct { | ||||||||||||||||||||||||||||||||||||||||||||
| ID string `json:"id"` | ||||||||||||||||||||||||||||||||||||||||||||
| Name string `json:"name"` | ||||||||||||||||||||||||||||||||||||||||||||
| Status string `json:"status"` | ||||||||||||||||||||||||||||||||||||||||||||
| }{ | ||||||||||||||||||||||||||||||||||||||||||||
| ID: respData.UsergroupCreate.ID, | ||||||||||||||||||||||||||||||||||||||||||||
| Name: groupName, | ||||||||||||||||||||||||||||||||||||||||||||
| Status: "created", | ||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.