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

Connect: Fetch correct role set when listing db users #13790

Merged
merged 10 commits into from
Jun 27, 2022

Conversation

ravicious
Copy link
Member

@ravicious ravicious commented Jun 23, 2022

Fixes gravitational/webapps.e#290.

#12281 fixed fetching db users for remote clusters for tsh db ls. #13617 applied the same fix to tsh db ls --all and extracted the fetchRoleSet function.

This PR extracts that function to lib/client so that we can reuse it lib/teleterm. Other than accepting log as an argument, nothing was changed about that function.

In Connect we basically needed to apply the same fix that was applied in #12281 to tool/tsh/db.go. As mentioned above, that whole section of code was extracted into fetchRoleSet in #13617.

#12281 fixed fetching db users for remote clusters
for `tsh db ls`. #13617 applied the same fix to
`tsh db ls --all` and extracted the `fetchRoleSet` function.

This commit extracts it to `lib/client` so that we can reuse it in
`lib/teleterm`. Other than accepting `log` as an argument, nothing was
changed about that function.
@github-actions github-actions bot added the tsh tsh - Teleport's command line tool for logging into nodes running Teleport. label Jun 23, 2022
@github-actions github-actions bot requested review from codingllama and lxea June 23, 2022 11:46
lib/client/api.go Outdated Show resolved Hide resolved
lib/teleterm/clusters/cluster_databases.go Outdated Show resolved Hide resolved
lib/client/api.go Outdated Show resolved Hide resolved
tool/tsh/db.go Show resolved Hide resolved
@ravicious
Copy link
Member Author

@codingllama I moved the function to lib/services and added some tests, let me know what you think.

@ravicious ravicious requested a review from codingllama June 24, 2022 13:59
lib/services/role.go Outdated Show resolved Hide resolved
Copy link
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the new tests, @ravicious. It looks good.

lib/services/role.go Outdated Show resolved Hide resolved
lib/services/role.go Outdated Show resolved Hide resolved
lib/services/role.go Outdated Show resolved Hide resolved
lib/services/role_test.go Outdated Show resolved Hide resolved
lib/services/role_test.go Outdated Show resolved Hide resolved
Comment on lines +5016 to +5018
}

func TestFetchAllClusterRoles_UsesDefaultRolesAndTraitsIfCurrentUserIsUnavailable(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's combine those 2 test cases in a single table-driven test, so we take advantage of their common setup.

https://github.com/golang/go/wiki/TableDrivenTests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fine if I leave them as separate tests for now? IMHO updating something that was repeated just once doesn't require that much work vs untangling the code in case we need to add a third case that's just slightly different than the other two.

lib/services/role_test.go Show resolved Hide resolved
@ravicious ravicious requested a review from atburke June 24, 2022 16:07
@ravicious ravicious enabled auto-merge (squash) June 27, 2022 08:24
@ravicious ravicious merged commit 8a27614 into master Jun 27, 2022
@github-actions
Copy link

@ravicious See the table below for backport results.

Branch Result
branch/v10 Failed

ravicious added a commit that referenced this pull request Jun 27, 2022
* Move fetchRoleSet from tsh/db to lib/services as FetchAllClusterRoles.

* Connect: Fetch correct role set when listing db users

* Add tests for FetchAllClusterRoles
@ravicious ravicious deleted the ravicious/db-users-role-set branch June 27, 2022 09:26
@ravicious
Copy link
Member Author

I did a quick manual test to confirm that the changes implemented in #12281 and #13617 still work as expected.

ravicious added a commit that referenced this pull request Jun 27, 2022
…13877)

Connect: Fetch correct role set when listing db users (#13790)

* Move fetchRoleSet from tsh/db to lib/services as FetchAllClusterRoles.

* Connect: Fetch correct role set when listing db users

* Add tests for FetchAllClusterRoles
greedy52 added a commit that referenced this pull request Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tsh tsh - Teleport's command line tool for logging into nodes running Teleport.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants