Skip to content
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

[BUGFIX] CLI: Fix get role and rolebinding #1669

Merged
merged 4 commits into from
Dec 20, 2023
Merged

[BUGFIX] CLI: Fix get role and rolebinding #1669

merged 4 commits into from
Dec 20, 2023

Conversation

Nexucis
Copy link
Member

@Nexucis Nexucis commented Dec 20, 2023

When running the command ./bin/percli get role --all or ./bin/percli get rolebinding --all, the command crashes with an error stack like that:

➜  perses git:(nexucis/refresh-token) ✗ ./bin/percli get role --all
panic: interface conversion: api.Entity is *v1.Role, not *v1.GlobalRole

goroutine 1 [running]:
github.com/perses/perses/internal/cli/service.(*role).BuildMatrix(0x100b71908?, {0x14000431100?, 0xc, 0x0?})
	/Users/ahusson/workspace/go/src/perses/perses/internal/cli/service/role.go:52 +0x854
github.com/perses/perses/internal/cli/cmd/get.(*option).Execute(0x1400040b700)
	/Users/ahusson/workspace/go/src/perses/perses/internal/cli/cmd/get/get.go:98 +0xa0
github.com/perses/perses/internal/cli/cmd.Run({0x100b70ac8, 0x1400040b700}, 0x0?, {0x1400041a4e0, 0x1, 0x2})
	/Users/ahusson/workspace/go/src/perses/perses/internal/cli/cmd/cmd.go:40 +0xb0
github.com/perses/perses/internal/cli/cmd/get.NewCMD.func1(0x14000415c00?, {0x1400041a4e0?, 0x4?, 0x1008cc6f4?})
	/Users/ahusson/workspace/go/src/perses/perses/internal/cli/cmd/get/get.go:127 +0x40
github.com/spf13/cobra.(*Command).execute(0x1400042c900, {0x1400041a4c0, 0x2, 0x2})
	/Users/ahusson/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0x82c
github.com/spf13/cobra.(*Command).ExecuteC(0x1400042c000)
	/Users/ahusson/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/ahusson/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
	/Users/ahusson/workspace/go/src/perses/perses/cmd/percli/main.go:91 +0xf8

After fixing this cast error, it appears the display of the role is not right as well. This PR is also fixing that.

Before:

➜  perses git:(main) ✗ ./bin/percli get role --all
   NAME  | PROJECT | AGE  |   ACTION    | SCOPE
---------+---------+------+-------------+--------
  editor | 106751d | *    | Dashboard
         |         |      | Datasource
         |         |      | Folder
         |         |      | Secret
         |         |      | Variable
         |         |      | Project
         |         |      | Role
         |         |      | RoleBinding
  owner  | 106751d | *    | *
  viewer | 106751d | read | *
  editor | 106751d | *    | Dashboard
         |         |      | Datasource
         |         |      | Folder
         |         |      | Secret
         |         |      | Variable
         |         |      | Project
         |         |      | Role
         |         |      | RoleBinding
  owner  | 106751d | *    | *
  viewer | 106751d | read | *
  editor | 106751d | *    | Dashboard
         |         |      | Datasource
         |         |      | Folder
         |         |      | Secret
         |         |      | Variable
         |         |      | Project
         |         |      | Role
         |         |      | RoleBinding

After:

➜  perses git:(nexucis/refresh-token) ✗ ./bin/percli get role --all
   NAME  |  PROJECT  |   AGE   | ACTION |    SCOPE
---------+-----------+---------+--------+--------------
  editor | MyProject | 106751d | *      | Dashboard
         |           |         |        | Datasource
         |           |         |        | Folder
         |           |         |        | Secret
         |           |         |        | Variable
         |           |         |        | Project
         |           |         |        | Role
         |           |         |        | RoleBinding
  owner  | MyProject | 106751d | *      | *
  viewer | MyProject | 106751d | read   | *
  editor | Showcase  | 106751d | *      | Dashboard
         |           |         |        | Datasource
         |           |         |        | Folder
         |           |         |        | Secret
         |           |         |        | Variable
         |           |         |        | Project
         |           |         |        | Role
         |           |         |        | RoleBinding

As a side note:

  • the creating and updating date seems to not be set by the server
  • the editor role shouldn't have the permission to create or modify a role and a role binding

I will fix that in another PR

Note: to be merged after #1668

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
@Nexucis Nexucis added this pull request to the merge queue Dec 20, 2023
Merged via the queue into main with commit 68c9b1b Dec 20, 2023
18 checks passed
@Nexucis Nexucis deleted the nexucis/fix-role branch December 20, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants