From 7bf37469bb24ee1909bccc3674ea0b9e8c106656 Mon Sep 17 00:00:00 2001 From: mwester117 <42421851+mwester117@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:33:07 +0100 Subject: [PATCH 1/4] Fixed inheritance bug in sentinelone_policies Module. See Changelog for more Details --- CHANGELOG.rst | 13 ++++++++++ changelogs/changelog.yaml | 11 +++++++++ galaxy.yml | 2 +- plugins/modules/sentinelone_policies.py | 32 +++++++++++-------------- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d531355..1824bbf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,19 @@ Sva.Sentinelone Release Notes .. contents:: Topics +v1.0.1 +====== + +Release Summary +--------------- + +This is a bugfix release + +Bugfixes +-------- + +- sentinelone_policies module: When a group policy inherited from the site area was updated with a custom setting, all other settings were reset to the default values. Now the inherited settings are updated by the settings passed to the module and the other inherited settings are retained. + v1.0.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 53b7178..8fdb475 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -28,3 +28,14 @@ releases: name: sentinelone_upgrade_policies namespace: '' release_date: '2022-08-16' + 1.0.1: + changes: + bugfixes: + - 'sentinelone_policies module: When a group policy inherited from the site + area was updated with a custom setting, all other settings were reset to the + default values. Now the inherited settings are updated by the settings passed + to the module and the other inherited settings are retained.' + release_summary: 'This is a bugfix release' + fragments: + - v1.0.1.yaml + release_date: '2023-01-30' diff --git a/galaxy.yml b/galaxy.yml index dc0c337..852f23a 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: "sva" name: "sentinelone" # The version of the collection. Must be compatible with semantic versioning -version: "1.0.0" +version: "1.0.1" # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: "README.md" diff --git a/plugins/modules/sentinelone_policies.py b/plugins/modules/sentinelone_policies.py index 230c790..96ec279 100644 --- a/plugins/modules/sentinelone_policies.py +++ b/plugins/modules/sentinelone_policies.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from __future__ import (absolute_import, division, print_function) + __metaclass__ = type DOCUMENTATION = r''' @@ -248,28 +249,23 @@ def revert_policy(self, site_group_id: str, module: AnsibleModule): return response @staticmethod - def get_update_body(current_settings: dict, desired_state_settings: dict): + def get_update_body(policy_settings: dict): """ - Create post object. Wrapping settings in data dictionary and check for autoMitigationAction + Prepare the merged object for post request - :param current_settings: current policy settings - :type current_settings: dict - :param desired_state_settings: settings which should be ensured - :type desired_state_settings: dict + :param policy_settings: desired state policy settings + :type policy_settings: dict :return: update body for API :rtype: dict """ - desired_state_policy_body = { - "data": desired_state_settings - } + # Remove deprecated policy settings. The module would not work correctly in some circumstances + del policy_settings['agentNotification'] + del policy_settings['agentUiOn'] - # API call will fail if autoMitigationAction is not set in update body. So we make shure it is set. And use the - # current setting if neccessary - if desired_state_policy_body['data'].get('autoMitigationAction', None) is None: - desired_state_policy_body['data']['autoMitigationAction'] = current_settings['data']['autoMitigationAction'] + policy_object = {'data': policy_settings} - return desired_state_policy_body + return policy_object def run_module(): @@ -311,13 +307,13 @@ def run_module(): # check if every group has the desired settings already current_policy = policy_obj.get_current_policy(current_group_id, module) desired_state_policy = policy_obj.desired_state_policy - diff = policy_obj.merge_compare(current_policy['data'], desired_state_policy)[0] + diff, merged_policy = policy_obj.merge_compare(current_policy['data'], desired_state_policy) if diff: # if group policy is different from desired state, update it current_group_name = current_group_id_name[1] diffs.append({'changes': dict(diff), 'groupId': current_group_id}) basic_message.append(f"Updating policy for group {current_group_name}") - update_body = policy_obj.get_update_body(current_policy, desired_state_policy) + update_body = policy_obj.get_update_body(merged_policy) policy_obj.update_policy(current_group_id, update_body, module) else: # if scope is site level @@ -326,12 +322,12 @@ def run_module(): site_id = policy_obj.site_id current_policy = policy_obj.get_current_policy(site_id, module) desired_state_policy = policy_obj.desired_state_policy - diff = policy_obj.merge_compare(current_policy['data'], desired_state_policy)[0] + diff, merged_policy = policy_obj.merge_compare(current_policy['data'], desired_state_policy) if diff: # if site policy is different from desired state, update it diffs.append({'changes': dict(diff), 'SiteId': site_id}) basic_message.append(f"Updating policy for site {site_name}") - update_body = policy_obj.get_update_body(current_policy, desired_state_policy) + update_body = policy_obj.get_update_body(merged_policy) policy_obj.update_policy(site_id, update_body, module) else: # if we want to enable inheritance From f36b6176e9b3fce8ba1878172d7e5dc89b6769f8 Mon Sep 17 00:00:00 2001 From: mwester117 <42421851+mwester117@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:38:31 +0100 Subject: [PATCH 2/4] Removed obsolete newline --- plugins/modules/sentinelone_policies.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/sentinelone_policies.py b/plugins/modules/sentinelone_policies.py index 96ec279..f8c8304 100644 --- a/plugins/modules/sentinelone_policies.py +++ b/plugins/modules/sentinelone_policies.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. from __future__ import (absolute_import, division, print_function) - __metaclass__ = type DOCUMENTATION = r''' From 7d214434f466057443d892a2067efbb949b69fa7 Mon Sep 17 00:00:00 2001 From: mwester117 <42421851+mwester117@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:48:13 +0100 Subject: [PATCH 3/4] Corrected wording in Changelog --- CHANGELOG.rst | 2 +- changelogs/changelog.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1824bbf..6ba03bd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,7 +16,7 @@ This is a bugfix release Bugfixes -------- -- sentinelone_policies module: When a group policy inherited from the site area was updated with a custom setting, all other settings were reset to the default values. Now the inherited settings are updated by the settings passed to the module and the other inherited settings are retained. +- sentinelone_policies module: When a group policy inherited from the site scope was updated with a custom setting, all other settings were reset to the default values. Now the inherited settings are updated by the settings passed to the module and the other inherited settings are retained. v1.0.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 8fdb475..4ba964b 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -32,7 +32,7 @@ releases: changes: bugfixes: - 'sentinelone_policies module: When a group policy inherited from the site - area was updated with a custom setting, all other settings were reset to the + scope was updated with a custom setting, all other settings were reset to the default values. Now the inherited settings are updated by the settings passed to the module and the other inherited settings are retained.' release_summary: 'This is a bugfix release' From c5e90c9eb2ba66144d4704c9839f6a3578c6b73c Mon Sep 17 00:00:00 2001 From: mwester117 <42421851+mwester117@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:53:37 +0100 Subject: [PATCH 4/4] Changed github ansible-test action to use checkout v3 because node.js 12 is deprecated --- .github/workflows/ansible-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index 346b75f..2a5c1dd 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Perform sanity testing with ansible-test uses: ansible-community/ansible-test-gh-action@release/v1