Skip to content

Commit

Permalink
New modules (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
herve4m authored Oct 27, 2024
1 parent 933d207 commit 967d03e
Show file tree
Hide file tree
Showing 18 changed files with 3,058 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Red Hat Advanced Cluster Security for Kubernetes Collection Release Notes

.. contents:: Topics

v1.1.0
======

New Modules
-----------

- herve4m.rhacs_configuration.rhacs_compliance_schedule - Manage compliance schedule configurations.
- herve4m.rhacs_configuration.rhacs_report_schedule - Manage vulnerability reporting schedules.

v1.0.0
======

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Name | Description
`rhacs_auth_provider` | Manage authentication providers
`rhacs_cloud_management_platform` | Manage RHACS integration with cloud platforms
`rhacs_collection` | Manage deployment collections
`rhacs_compliance_schedule` | Manage compliance schedule configurations
`rhacs_config` | Manage RHACS configuration
`rhacs_delegated_image_scan` | Manage delegated image scanning configuration
`rhacs_exception` | Configure vulnerability exception expiration periods
Expand All @@ -41,6 +42,7 @@ Name | Description
`rhacs_policy_import` | Import security policies
`rhacs_policy_notifier` | Associate notifiers to policies
`rhacs_policy_status` | Enable or disable policies
`rhacs_report_schedule` | Manage vulnerability reporting schedules
`rhacs_role` | Manage roles
`rhacs_signature` | Manage RHACS integrations with Cosign signatures

Expand Down
9 changes: 9 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ releases:
name: rhacs_signature
namespace: ''
release_date: '2024-10-17'
1.1.0:
modules:
- description: Manage compliance schedule configurations.
name: rhacs_compliance_schedule
namespace: ''
- description: Manage vulnerability reporting schedules.
name: rhacs_report_schedule
namespace: ''
release_date: '2024-10-27'
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: herve4m
name: rhacs_configuration
version: 1.0.0
version: 1.1.0
readme: README.md
authors:
- Hervé Quatremain <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ action_groups:
- rhacs_policy_clone
- rhacs_policy_export
- rhacs_policy_import
- rhacs_compliance_schedule
121 changes: 119 additions & 2 deletions plugins/module_utils/api_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,22 +714,25 @@ def unconditional_update(

return response.get("json", {})

def get_item_from_resource_list(self, name_or_id, resource_list):
def get_item_from_resource_list(self, name_or_id, resource_list, name_attribute="name"):
"""Retrieve an RHACS object from a list or objects.
:param name_or_id: Name or ID of the object to retrieve.
:type name_or_id: str
:param resource_list: List of objects. Each object is a dictionary and
must have the ``name`` and ``id`` keys.
:type resource_list: list
:param name_attribute: The attribute in the list that contains the
object name.
:type name_attribute: str
:return: The object or None if the object is not found.
:rtype: dict
"""
if not name_or_id or not resource_list:
return None
for res in resource_list:
if name_or_id == res.get("name") or name_or_id == res.get("id"):
if name_or_id == res.get(name_attribute) or name_or_id == res.get("id"):
return res
return None

Expand Down Expand Up @@ -995,3 +998,117 @@ def get_notifier_id(self, name_or_id):
self.get_notifiers(),
error_msg="the notifier method (in `notifiers') does not exist",
)

def get_collections(self):
"""Retrieve the list of the deployment collections.
:return: The list of deployment collection objects
:rtype: list
"""
try:
return self.collections
except AttributeError:
# Retrieve the existing deployment collections
#
# GET /v1/collections
# {
# "collections": [
# {
# "id": "7e4a265e-2d5a-4ff4-81a8-e426b102dbae",
# "name": "My collection",
# "description": "My description",
# "createdAt": "2024-10-03T14:07:18.562326152Z",
# "lastUpdated": "2024-10-03T14:07:18.562326152Z",
# "createdBy": {
# "id": "sso:4df1...b62d:admin",
# "name": "admin"
# },
# "updatedBy": {
# "id": "sso:4df1...b62d:admin",
# "name": "admin"
# },
# "resourceSelectors": [
# {
# "rules": [
# {
# "fieldName": "Namespace Label",
# "operator": "OR",
# "values": [
# {
# "value": "team=payment",
# "matchType": "EXACT"
# },
# {
# "value": "foo=bar",
# "matchType": "EXACT"
# }
# ]
# },
# {
# "fieldName": "Namespace Label",
# "operator": "OR",
# "values": [
# {
# "value": "toto=titi",
# "matchType": "EXACT"
# }
# ]
# },
# {
# "fieldName": "Deployment",
# "operator": "OR",
# "values": [
# {
# "value": "nginx-deployment",
# "matchType": "EXACT"
# },
# {
# "value": "^nginx-deployment$",
# "matchType": "REGEX"
# }
# ]
# }
# ]
# }
# ],
# "embeddedCollections": [
# {
# "id": "a7e188bb-f4f5-4023-a91f-4d4585809d17"
# }
# ]
# },
# ...
# ]
# }
c = self.get_object_path(
"/v1/collections", query_params={"query.pagination.limit": 10000}
)
self.collections = c.get("collections", [])
return self.collections

def get_collection(self, name_or_id):
"""Retrieve a deployment collection object.
:param name_or_id: Name or ID of the collection to retrieve.
:type name_or_id: str
:return: The collection object or None if the collection is not found.
:rtype: dict
"""
return self.get_item_from_resource_list(name_or_id, self.get_collections())

def get_collection_id(self, name_or_id):
"""Return the ID of a deployment collection.
:param name_or_id: Name or ID of the collection to retrieve.
:type name_or_id: str
:return: The deployment collection ID. If the collection is not found,
then the module exists in error.
:rtype: str
"""
return self.get_id_from_resource_list(
name_or_id,
self.get_collections(),
error_msg="the deployment collection (in `collection') does not exist",
)
Loading

0 comments on commit 967d03e

Please sign in to comment.