From b185785910ee94b1e6afb66e02856b96037146d2 Mon Sep 17 00:00:00 2001 From: JB Volta Date: Thu, 30 Nov 2023 10:21:45 -0500 Subject: [PATCH] RM AuditTrail --- lib/AuditTrail.php | 204 ----------------------- lib/Resource/Event.php | 62 ------- lib/Resource/EventAction.php | 21 --- lib/Version.php | 2 +- tests/WorkOS/AuditTrailTest.php | 277 -------------------------------- 5 files changed, 1 insertion(+), 565 deletions(-) delete mode 100644 lib/AuditTrail.php delete mode 100644 lib/Resource/Event.php delete mode 100644 lib/Resource/EventAction.php delete mode 100644 tests/WorkOS/AuditTrailTest.php diff --git a/lib/AuditTrail.php b/lib/AuditTrail.php deleted file mode 100644 index 2e160ca7..00000000 --- a/lib/AuditTrail.php +++ /dev/null @@ -1,204 +0,0 @@ - self::METADATA_SIZE_LIMIT - ) { - $msg = "Number of metadata keys exceed limit: " . self::METADATA_SIZE_LIMIT; - throw new Exception\UnexpectedValueException($msg); - } - - $headers = null; - if ($idempotencyKey) { - $headers = ["idempotency-key: {$idempotencyKey}"]; - } - - Client::request(Client::METHOD_POST, $eventsPath, $headers, $event, true); - - return true; - } - - /** - * Filter for Audit Trail Events. - * - * @param null|string|array $group Group or array of groups to filter for - * @param null|string|array $action Action of array of actions to filter for - * @param null|string|array $actionType Action type of array of action types to filter for - * @param null|string|array $actorName Actor name or array of actor names to filter for - * @param null|string|array $actorId Actor ID or array of action IDs to filter for - * @param null|string|array $targetName Target name or array of target names to filter for - * @param null|string|array $targetID Target ID or array of target IDs to filter for - * @param string $occurredAt ISO-8601 datetime of when an event occurred - * @param string $occurredAtGt ISO-8601 datetime of when an event occurred after - * @param string $occurredAtGte ISO-8601 datetime of when an event occurred at or after - * @param string $occurredAtLt ISO-8601 datetime of when an event occurred before - * @param string $occurredAtLte ISO-8601 datetime of when an event occured at or before - * @param string $search Keyword search - * @param int $limit Number of Events to return - * @param string $before Event ID to look before - * @param string $after Event ID to look after - * @param \WorkOS\Resource\Order $order The Order in which to paginate records - * - * @throws Exception\WorkOSException - * - * @return array An array containing the following: - * null|string Event ID to use as before cursor - * null|string Event ID to use as after cursor - * array \WorkOS\Resource\Event instances - */ - public function getEvents( - $group = null, - $action = null, - $actionType = null, - $actorName = null, - $actorId = null, - $targetName = null, - $targetId = null, - $occurredAt = null, - $occurredAtGt = null, - $occurredAtGte = null, - $occurredAtLt = null, - $occurredAtLte = null, - $search = null, - $limit = self::DEFAULT_EVENT_LIMIT, - $before = null, - $after = null, - $order = null - ) { - $eventsPath = "events"; - - $params = [ - "limit" => $limit, - "before" => $before, - "after" => $after, - "order" => $order - ]; - - if ($group) { - if (is_string($group)) { - $group = array($group); - } - $params["group"] = $group; - } - - if ($action) { - if (is_string($action)) { - $action = array($action); - } - $params["action"] = $action; - } - - if ($actionType) { - if (is_string($actionType)) { - $actionType = array($actionType); - } - $params["action_type"] = $actionType; - } - - if ($actorName) { - if (is_string($actorName)) { - $actorName = array($actorName); - } - $params["actor_name"] = $actorName; - } - - if ($actorId) { - if (is_string($actorId)) { - $actorId = array($actorId); - } - $params["actor_id"] = $actorId; - } - - if ($targetName) { - if (is_string($targetName)) { - $targetName = array($targetName); - } - $params["target_name"] = $targetName; - } - - if ($targetId) { - if (is_string($targetId)) { - $targetId = array($targetId); - } - $params["target_id"] = $targetId; - } - - if ($occurredAt) { - $params["occurred_at"] = $occurredAt; - } else { - if ($occurredAtGte) { - $params["occurred_at_gte"] = $occurredAtGte; - } elseif ($occurredAtGt) { - $params["occurred_at_gt"] = $occurredAtGt; - } - - if ($occurredAtLte) { - $params["occurred_at_lte"] = $occurredAtLte; - } elseif ($occurredAtLt) { - $params["occurred_at_lt"] = $occurredAtLt; - } - } - - if ($search) { - $params["search"] = $search; - } - - $response = Client::request( - Client::METHOD_GET, - $eventsPath, - null, - $params, - true - ); - - $events = []; - list($before, $after) = Util\Request::parsePaginationArgs($response); - foreach ($response["data"] as $responseData) { - \array_push($events, Resource\Event::constructFromResponse($responseData)); - } - - return [$before, $after, $events]; - } -} diff --git a/lib/Resource/Event.php b/lib/Resource/Event.php deleted file mode 100644 index 1c9266dd..00000000 --- a/lib/Resource/Event.php +++ /dev/null @@ -1,62 +0,0 @@ - "id", - "group" => "group", - "location" => "location", - "latitude" => "latitude", - "longitude" => "longitude", - "type" => "type", - "actor_name" => "actorName", - "actor_id" => "actorId", - "target_name" => "targetName", - "target_id" => "targetId", - "metadata" => "metadata", - "occurred_at" => "occurredAt" - ]; - - public static function constructFromResponse($response) - { - $instance = parent::constructFromResponse($response); - - $rawEventAction = $response["action"]; - $instance->values["action"] = EventAction::constructFromResponse($rawEventAction); - - return $instance; - } - - public function toArray() - { - $eventArray = parent::toArray(); - - $eventAction = $eventArray["action"]; - $eventArray["action"] = $eventAction->toArray(); - - return $eventArray; - } -} diff --git a/lib/Resource/EventAction.php b/lib/Resource/EventAction.php deleted file mode 100644 index 49ea14de..00000000 --- a/lib/Resource/EventAction.php +++ /dev/null @@ -1,21 +0,0 @@ - "id", - "name" => "name" - ]; -} diff --git a/lib/Version.php b/lib/Version.php index e204c9f8..c6692140 100644 --- a/lib/Version.php +++ b/lib/Version.php @@ -5,5 +5,5 @@ final class Version { public const SDK_IDENTIFIER = "WorkOS PHP"; - public const SDK_VERSION = '3.4.0'; + public const SDK_VERSION = '4.0.0'; } diff --git a/tests/WorkOS/AuditTrailTest.php b/tests/WorkOS/AuditTrailTest.php deleted file mode 100644 index 613c7fda..00000000 --- a/tests/WorkOS/AuditTrailTest.php +++ /dev/null @@ -1,277 +0,0 @@ -traitSetUp(); - - $this->at = new AuditTrail(); - } - - public function testCreateAuditTrailEvent() - { - $this->withApiKeyAndClientId(); - - $path = "events"; - - $eventFixture = $this->eventFixture(); - - $this->mockRequest( - Client::METHOD_POST, - $path, - null, - $eventFixture, - true - ); - - $this->assertTrue((new AuditTrail())->createEvent($eventFixture)); - } - - public function testCreateAuditTrailEventFailsWithTooMuchMetadata() - { - $this->withApiKeyAndClientId(); - - $eventFixture = $this->eventFixture(); - $eventFixture["metadata"] = \array_pad( - ["things" => "stuff"], - AuditTrail::METADATA_SIZE_LIMIT + 1, - "even_more_stuff" - ); - - $this->expectException(Exception\UnexpectedValueException::class); - (new AuditTrail())->createEvent($eventFixture); - } - - public function testGetEvents() - { - $this->withApiKeyAndClientId(); - - $eventsPath = "events"; - - $result = $this->getEventsResponseFixture(); - $params = [ - "limit" => AuditTrail::DEFAULT_EVENT_LIMIT, - "before" => null, - "after" => null, - "order" => null - ]; - - $this->mockRequest( - Client::METHOD_GET, - $eventsPath, - null, - $params, - true, - $result - ); - - $getEventsEventFixture = $this->getEventsEventFixture(); - - list($before, $after, $events) = $this->at->getEvents(); - $this->assertSame($getEventsEventFixture, $events[0]->toArray()); - } - - public function testGetEventsCorrectlyIncludesOccurredAtFilter() - { - $this->withApiKeyAndClientId(); - - $eventsPath = "events"; - - $result = $this->getEventsResponseFixture(); - $params = [ - "limit" => AuditTrail::DEFAULT_EVENT_LIMIT, - "before" => null, - "after" => null, - "order" => null, - "occurred_at" => "2020-02-21T00:32:14.443Z" - ]; - - $this->mockRequest( - Client::METHOD_GET, - $eventsPath, - null, - $params, - true, - $result - ); - - $getEventsEventFixture = $this->getEventsEventFixture(); - - $this->at->getEvents( - null, - null, - null, - null, - null, - null, - null, - "2020-02-21T00:32:14.443Z", - "2020-02-21T00:32:14.443Z", - "2020-02-21T00:32:14.443Z", - "2020-02-21T00:32:14.443Z", - "2020-02-21T00:32:14.443Z" - ); - } - - public function testGetEventsCorrectlyIncludesOccurredAtGte() - { - $this->withApiKeyAndClientId(); - - $eventsPath = "events"; - - $result = $this->getEventsResponseFixture(); - $params = [ - "limit" => AuditTrail::DEFAULT_EVENT_LIMIT, - "before" => null, - "after" => null, - "order" => null, - "occurred_at_gte" => "2020-02-21T00:32:14.443Z" - ]; - - $this->mockRequest( - Client::METHOD_GET, - $eventsPath, - null, - $params, - true, - $result - ); - - $getEventsEventFixture = $this->getEventsEventFixture(); - - $this->at->getEvents( - null, - null, - null, - null, - null, - null, - null, - null, - "2020-02-21T00:32:14.443Z", - "2020-02-21T00:32:14.443Z" - ); - } - - public function testGetEventsCorrectlyIncludesOccurredAtLte() - { - $this->withApiKeyAndClientId(); - - $eventsPath = "events"; - - $result = $this->getEventsResponseFixture(); - $params = [ - "limit" => AuditTrail::DEFAULT_EVENT_LIMIT, - "before" => null, - "after" => null, - "order" => null, - "occurred_at_lte" => "2020-02-21T00:32:14.443Z" - ]; - - $this->mockRequest( - Client::METHOD_GET, - $eventsPath, - null, - $params, - true, - $result - ); - - $getEventsEventFixture = $this->getEventsEventFixture(); - - $this->at->getEvents( - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - "2020-02-21T00:32:14.443Z", - "2020-02-21T00:32:14.443Z" - ); - } - - // Fixtures - - private function eventFixture() - { - return [ - "group" => "organization_1", - "action" => "user.login", - "action_type" => "C", - "actor_name" => "user@email.com", - "actor_id" => "user_1", - "target_name" => "user@email.com", - "target_id" => "user_1", - "location" => "1.1.1.1", - "occurred_at" => (new \DateTime())->format(\DateTime::ISO8601) - ]; - } - - private function getEventsEventFixture() - { - return [ - "id" => "evt_123", - "action" => [ - "id" => "evt_action_123", - "name" => "user.login", - ], - "group" => "organization_1", - "location" => "1.1.1.1", - "latitude" => null, - "longitude" => null, - "type" => "C", - "actorName" => "user@email.com", - "actorId" => "user_1", - "targetName" => "user@email.com", - "targetId" => "user_1", - "metadata" => [ - "a" => "b" - ], - "occurredAt" => "2020-02-21T00:32:14.443Z" - ]; - } - - private function getEventsResponseFixture() - { - return json_encode([ - "data" => [ - [ - "id" => "evt_123", - "group" => "organization_1", - "location" => "1.1.1.1", - "latitude" => null, - "longitude" => null, - "action" => [ - "id" => "evt_action_123", - "name" => "user.login", - ], - "type" => "C", - "actor_name" => "user@email.com", - "actor_id" => "user_1", - "target_name" => "user@email.com", - "target_id" => "user_1", - "occurred_at" => "2020-02-21T00:32:14.443Z", - "metadata" => [ - "a" => "b" - ] - ] - ], - "list_metadata" => [ - "before" => null, - "after" => null - ], - ]); - } -}