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

BUG: allow server query with non-admin credentials #152

Merged

Conversation

anish-mudaraddi
Copy link
Collaborator

@anish-mudaraddi anish-mudaraddi commented Oct 10, 2023

This PR changes the way server-query works
Now, by default - a server query will use the current scoped project - set in clouds.yaml if no meta-params given
To run admin-level queries - i.e. those which require accessing projects other than the preset one in clouds.yaml - an extra meta-param is required as_admin=True

To run a query on all projects - a meta-param is required all_projects=True alongside as_admin=True
To run a query on select projects - a meta-param is required from_projects=[] alongside as_admin=True

If neither of these meta-params is given and as_admin=True is set - the query will run on all projects that the user - scoped in clouds.yaml has access to.

Also changes mapping for server_status to status and not vm_state so now we can use SHUTOFF instead of STOPPED

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (2906a92) 97.28% compared to head (3f11195) 97.32%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #152      +/-   ##
==========================================
+ Coverage   97.28%   97.32%   +0.03%     
==========================================
  Files         149      149              
  Lines        6479     6500      +21     
  Branches      420      420              
==========================================
+ Hits         6303     6326      +23     
+ Misses        143      142       -1     
+ Partials       33       32       -1     
Files Coverage Δ
lib/openstack_query/mappings/server_mapping.py 100.00% <ø> (ø)
lib/openstack_query/runners/runner_wrapper.py 91.39% <100.00%> (-0.10%) ⬇️
lib/openstack_query/runners/server_runner.py 100.00% <100.00%> (+4.76%) ⬆️
...ib/openstack_query/mappings/test_server_mapping.py 100.00% <ø> (ø)
...lib/openstack_query/runners/test_runner_wrapper.py 99.24% <100.00%> (-0.02%) ⬇️
.../lib/openstack_query/runners/test_server_runner.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anish-mudaraddi anish-mudaraddi force-pushed the openstack-query/non-admin-server-query branch from d2f870d to c102710 Compare October 10, 2023 12:43
raise ParseQueryError(
"This query uses a preset that requires searching on project_ids "
"- but you've provided projects to search in using from_projects meta param"
"- please use one or the other, not both"
"- or you are not running as admin"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this applies in this case? Since the exception only applies to the query lib and how the user sets the flag regardless of their cred status

Copy link
Collaborator Author

@anish-mudaraddi anish-mudaraddi Oct 10, 2023

Choose a reason for hiding this comment

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

quirk of how it works basically
if a user tries to run a query where they are trying to filter by project id and they are not admin - run_query() will be run with both a meta-param auto-generated which contains one project (the one that is scoped to the project) and filter kwargs set by the user - then we will hit the error

meoflynn
meoflynn previously approved these changes Oct 11, 2023
now parse-meta-params will default to only searching in currently scoped project-id unless as_admin flag given
@anish-mudaraddi anish-mudaraddi force-pushed the openstack-query/non-admin-server-query branch from 357d8e2 to 3f11195 Compare October 13, 2023 09:05
@DavidFair DavidFair merged commit edb0cb9 into stfc:main Oct 13, 2023
8 checks passed
@anish-mudaraddi anish-mudaraddi deleted the openstack-query/non-admin-server-query branch October 24, 2023 12:58
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.

3 participants