Skip to content

Commit

Permalink
Move debug message in HttpWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 20, 2024
1 parent 9d82e9d commit 6233090
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
68 changes: 30 additions & 38 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function addGrouperGroupMember(array $queryData)
$this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']);

try {
$results = $this->http->sendRequest('PUT', $connectionUrl, json_encode($usersToAdd, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('PUT',
$connectionUrl,
json_encode($usersToAdd, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -157,9 +157,9 @@ public function createGroupWithTemplate(array $queryData)
$status = true;
$message = '';
try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($groupToSave));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('POST',
$connectionUrl,
json_encode($groupToSave));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -235,9 +235,9 @@ public function createUpdateGroup(array $queryData)
$connectionUrl = "{$this->config['fullUrl']}/groups";

try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($groupToSave, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('POST',
$connectionUrl,
json_encode($groupToSave, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -286,9 +286,9 @@ public function deleteGroupWithTemplate(array $queryData)
$connectionUrl = "{$this->config['fullUrl']}/gshTemplateExec";

try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($groupToDelete, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('POST',
$connectionUrl,
json_encode($groupToDelete, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -336,10 +336,9 @@ public function getGrouperGroupInfo(array $queryData)
$connectionUrl = "{$this->config['fullUrl']}/attributeAssignments";

try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($stemToFind, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));

$results = $this->http->sendRequest('POST',
$connectionUrl,
json_encode($stemToFind, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -379,8 +378,6 @@ public function getGrouperMemberOfGroups(string $userId)
. "&actAsSubjectId={$userId}";
try {
$results = $this->http->sendRequest('GET', $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -415,9 +412,9 @@ public function getMembersInGroup(array $queryData) {
$this->http->setHeader(['Content-Type' => 'application/json', 'Accept' => 'application/json']);

try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($usersToShow, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('POST',
$connectionUrl,
json_encode($usersToShow, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -453,7 +450,6 @@ public function getOptionalGroups(array $queryData)

try {
$results = $this->useMembershipUrl($queryData);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -543,16 +539,16 @@ public function joinGrouperGroup(string $userId, string $groupName)
$connectionUrl = "{$this->config['fullUrl']}/groups/{$groupName}/members";

try {
$results = $this->http->sendRequest('PUT', $connectionUrl, json_encode($groupCommand, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('PUT',
$connectionUrl,
json_encode($groupCommand, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

return isset($results['WsAddMemberResults']['wsGroupAssigned'])
&& $results['WsAddMemberResults']['wsGroupAssigned']['name'] == urldecode($groupName);
&& $results['WsAddMemberResults']['wsGroupAssigned']['name'] == urldecode($groupName);
}

/**
Expand Down Expand Up @@ -586,9 +582,9 @@ public function leaveGrouperGroup(string $userId, string $groupName)
$connectionUrl = "{$this->config['fullUrl']}/groups/{$groupName}/members";

try {
$results = $this->http->sendRequest('PUT', $connectionUrl, json_encode($groupCommand, JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('PUT',
$connectionUrl,
json_encode($groupCommand, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -620,8 +616,6 @@ public function isMemberOf(string $groupName, string $userId): bool
. "/{$groupNameEncoded}/members/{$userId}";
try {
$results = $this->http->sendRequest('GET', $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -693,10 +687,8 @@ public function removeGrouperGroupMember(array $queryData)

try {
$results = $this->http->sendRequest('POST',
$connectionUrl, json_encode($userToDelete,
JSON_THROW_ON_ERROR));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$connectionUrl,
json_encode($userToDelete, JSON_THROW_ON_ERROR));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down Expand Up @@ -759,9 +751,9 @@ private function useMembershipUrl(array $queryData)
$connectionUrl = "{$this->config['fullUrl']}/memberships";

try {
$results = $this->http->sendRequest('POST', $connectionUrl, json_encode($groupsToShow));
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $connectionUrl);
CakeLog::write('debug', __METHOD__ . '::response: ' . var_export($results, true));
$results = $this->http->sendRequest('POST',
$connectionUrl,
json_encode($groupsToShow));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand Down
12 changes: 11 additions & 1 deletion Lib/GrouperHTTPWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function setHeader(array $headerSetting): void
* @throws GrouperLiteWidgetException If issue with Grouper WS connection
*/
public function sendRequest(string $method, string $uri, string $body = ''): array {
CakeLog::write('debug', __METHOD__ . '::connection url: ' . $uri);

$this->_request['method'] = $method;
$this->_request['uri'] = $this->_parseUri($uri);
Expand All @@ -156,6 +157,15 @@ public function sendRequest(string $method, string $uri, string $body = ''): arr
CakeLog::write('error', __METHOD__ . ': Grouper WS returned non-200 of ' . var_export($apiResults->body(), true));
}

return json_decode($apiResults->body(), true);
$payload = json_decode($apiResults->body(), true);

CakeLog::write('debug', __METHOD__ . '::payload: ' . var_export($payload, true));

$successHeader = $apiResults->getHeader('X-Grouper-success');
if (empty($successHeader)) {
throw new RuntimeException('Web service did not even respond!');
}

return $payload;
}
}

0 comments on commit 6233090

Please sign in to comment.