-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add group role mapping #306
Open
DavidFair
wants to merge
9
commits into
main
Choose a base branch
from
Add_group_role_mapping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f445c1
Rename role add user project to distinguish it
DavidFair bbbc85a
Adds action to map a group to a project
DavidFair 8d04717
Add action to add user to an existing group
DavidFair 756149a
Add .venv to gitignore
DavidFair 861b768
Fix patch not requiring extra path failing test
DavidFair 6f71772
Fix name from project -> group
DavidFair be3c049
Unify domain for group and user
DavidFair 491528a
Fix another copy-paste error in action
DavidFair 200b4f9
Remove unused import from combining domains
DavidFair 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 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 |
---|---|---|
|
@@ -10,3 +10,4 @@ coverage.coverage | |
.vscode/settings.json | ||
|
||
venv/ | ||
.venv/ |
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
# This is slightly a misnomer, as it is actually adding a user to a group, | ||
# but it follows the same pattern as the other role actions | ||
description: Adds a user directly to an existing group | ||
enabled: true | ||
entry_point: src/openstack_actions.py | ||
name: role.add.user.group | ||
parameters: | ||
lib_entry_point: | ||
default: workflows.role_actions.add_user_to_group | ||
immutable: true | ||
type: string | ||
requires_openstack: | ||
default: true | ||
immutable: true | ||
type: boolean | ||
cloud_account: | ||
description: The clouds.yaml account to use whilst performing this action | ||
required: true | ||
type: string | ||
default: "dev" | ||
enum: | ||
- "dev" | ||
- "prod" | ||
user_identifier: | ||
description: User to add to (Name or ID) | ||
type: string | ||
required: true | ||
domain: | ||
description: Authentication domain to search, this much match between group and user | ||
type: string | ||
required: true | ||
default: default | ||
enum: | ||
- default | ||
- stfc | ||
- jasmin | ||
group_name: | ||
description: Group to add the user to | ||
type: string | ||
required: true | ||
runner_type: python-script |
This file contains 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
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. Do the project, role, group parameters take names and IDs or only one type? |
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
description: Add a pre-created group to a given project | ||
enabled: true | ||
entry_point: src/openstack_actions.py | ||
name: role.assign.group.to.project | ||
parameters: | ||
lib_entry_point: | ||
default: workflows.role_actions.assign_group_to_project | ||
immutable: true | ||
type: string | ||
requires_openstack: | ||
default: true | ||
immutable: true | ||
type: boolean | ||
cloud_account: | ||
description: The clouds.yaml account to use whilst performing this action | ||
required: true | ||
type: string | ||
default: "dev" | ||
enum: | ||
- "dev" | ||
- "prod" | ||
project_identifier: | ||
description: Project to add the group to | ||
required: true | ||
type: string | ||
role_identifier: | ||
description: Role to add use with group members | ||
required: true | ||
type: string | ||
default: "user" | ||
group_name: | ||
description: Group to add to a project | ||
type: string | ||
required: true | ||
runner_type: python-script |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -2,7 +2,12 @@ | |
import pytest | ||
|
||
from enums.user_domains import UserDomains | ||
from openstack_api.openstack_roles import assign_role_to_user, remove_role_from_user | ||
from openstack_api.openstack_roles import ( | ||
assign_role_to_user, | ||
remove_role_from_user, | ||
assign_group_role_to_project, | ||
add_user_to_group, | ||
) | ||
from exceptions.missing_mandatory_param_error import MissingMandatoryParamError | ||
from structs.role_details import RoleDetails | ||
|
||
|
@@ -72,7 +77,7 @@ def test_assign_roles_throws_missing_role(missing_param_test): | |
mock_conn.identity.assign_project_role_to_user.assert_not_called() | ||
|
||
|
||
def test_assign_roles_successful(): | ||
def test_assign_roles_successful_single_user(): | ||
""" | ||
Tests that assignment is successful | ||
""" | ||
|
@@ -101,6 +106,53 @@ def test_assign_roles_successful(): | |
) | ||
|
||
|
||
def test_assign_group_role_to_project_successful(): | ||
""" | ||
Tests that a group can be assigned to a project successfully | ||
""" | ||
mock_conn = MagicMock() | ||
assign_group_role_to_project(mock_conn, "project", "role", "group") | ||
|
||
mock_conn.identity.find_project.assert_called_once_with( | ||
"project", ignore_missing=False | ||
) | ||
mock_conn.identity.find_role.assert_called_once_with("role", ignore_missing=False) | ||
mock_conn.identity.find_group.assert_called_once_with("group", ignore_missing=False) | ||
|
||
mock_conn.identity.assign_project_role_to_group( | ||
project=mock_conn.identity.find_project.return_value, | ||
group=mock_conn.identity.find_group.return_value, | ||
role=mock_conn.identity.find_role.return_value, | ||
) | ||
Comment on lines
+122
to
+126
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. Should this be asserting called_with? |
||
|
||
|
||
def test_add_user_to_group(): | ||
""" | ||
Tests that a user can be added to an existing group | ||
""" | ||
mock_conn = MagicMock() | ||
add_user_to_group(mock_conn, "user", "domain", "group") | ||
|
||
mock_conn.identity.find_domain.assert_called_once_with( | ||
"domain", ignore_missing=False | ||
) | ||
mock_conn.identity.find_user.assert_called_once_with( | ||
"user", | ||
domain_id=mock_conn.identity.find_domain.return_value.id, | ||
ignore_missing=False, | ||
) | ||
mock_conn.identity.find_group.assert_called_once_with( | ||
"group", | ||
domain_id=mock_conn.identity.find_domain.return_value.id, | ||
ignore_missing=False, | ||
) | ||
|
||
mock_conn.identity.add_user_to_group.assert_called_once_with( | ||
user=mock_conn.identity.find_user.return_value, | ||
group=mock_conn.identity.find_group.return_value, | ||
) | ||
|
||
|
||
def test_remove_roles_throws_missing_project(missing_param_test): | ||
""" | ||
Tests that an exception is thrown if the specified project is missing | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this group name only or can also be ID?