diff --git a/sdcclient/secure/_policy_events_v1.py b/sdcclient/secure/_policy_events_v1.py index 79e38c6f..8d68b5a6 100644 --- a/sdcclient/secure/_policy_events_v1.py +++ b/sdcclient/secure/_policy_events_v1.py @@ -115,3 +115,21 @@ def get_more_policy_events(self, ctx): `examples/get_secure_policy_events.py `_ ''' return self._get_policy_events_int(ctx) + + def get_policy_event(self, event_id): + """ + + Args: + event_id: The ID of the Runtime Policy event to retrieve more info from. + + Returns: + A tuple where the first parameter indicates if the request was successful, and the second parameter + holds the info from the policy event or the error. + """ + policy_events_url = f'{self.url}/api/v1/secureEvents/{event_id}' + + res = self.http.get(policy_events_url, headers=self.hdrs, verify=self.ssl_verify) + if not self._checkResponse(res): + return False, self.lasterr + + return True, res.json() diff --git a/specs/secure/policy_events_v1_spec.py b/specs/secure/policy_events_v1_spec.py index 1e9cd666..ad7337aa 100644 --- a/specs/secure/policy_events_v1_spec.py +++ b/specs/secure/policy_events_v1_spec.py @@ -13,9 +13,9 @@ token=os.getenv("SDC_SECURE_TOKEN")) with context("when we try to retrieve policy events from the last 7 days"): with it("returns the list of all events happened"): - day_in_seconds = 7 * 24 * 60 * 60 + week_in_seconds = 7 * 24 * 60 * 60 - ok, res = self.client.get_policy_events_duration(day_in_seconds) + ok, res = self.client.get_policy_events_duration(week_in_seconds) expect((ok, res)).to(be_successful_api_call) expect(res).to(have_keys("ctx", "data")) @@ -34,18 +34,18 @@ contain(have_keys("id", "timestamp", "customerId", "source", "name", "description", "cursor"))) with it("returns the list of all events from the last 7 days that match a filter"): - day_in_seconds = 7 * 24 * 60 * 60 + week_in_seconds = 7 * 24 * 60 * 60 - ok, res = self.client.get_policy_events_duration(day_in_seconds, filter='severity in ("4","5")') + ok, res = self.client.get_policy_events_duration(week_in_seconds, filter='severity in ("4","5")') expect((ok, res)).to(be_successful_api_call) expect(res).to(have_keys("ctx", "data")) expect(res["data"]).to(contain(have_key("severity", be_within(3, 6)))) with it("returns an empty list if the filter does not match"): - day_in_seconds = 7 * 24 * 60 * 60 + week_in_seconds = 7 * 24 * 60 * 60 - ok, res = self.client.get_policy_events_duration(day_in_seconds, filter='severity in ("-1")') + ok, res = self.client.get_policy_events_duration(week_in_seconds, filter='severity in ("-1")') expect((ok, res)).to(be_successful_api_call) expect(res).to(have_keys("ctx", "data")) @@ -54,8 +54,8 @@ with _context("and from the first event we retrieve the rest of events"): # Deactivated tests. There seems to be a bug in the API -- need confirmation with it("returns the list of all events except the first"): - day_in_seconds = 7 * 24 * 60 * 60 - _, res = self.client.get_policy_events_duration(day_in_seconds) + week_in_seconds = 7 * 24 * 60 * 60 + _, res = self.client.get_policy_events_duration(week_in_seconds) ctx = {"cursor": res["data"][0]["cursor"]} qty_before = len(res["data"]) @@ -76,3 +76,16 @@ } call = self.client.get_more_policy_events(wrong_context) expect(call).to_not(be_successful_api_call) + + with context("while retrieving a single event"): + with it("retrieves the event correctly"): + week_in_seconds = 7 * 24 * 60 * 60 + ok, res = self.client.get_policy_events_duration(week_in_seconds) + + expect((ok, res)).to(be_successful_api_call) + + event_id = res["data"][0]["id"] + ok, res = self.client.get_policy_event(event_id) + + expect((ok, res)).to(be_successful_api_call) + expect(res).to(have_keys("name", "timestamp", "customerId", "originator", "machineId", id=event_id))