public function ApigeeEdgeManagementCliService::doesRoleExist in Apigee Edge 8
Check to see if role exists.
Parameters
string $org: The Edge org to create the permissions in.
string $email: The email of an Edge user with org admin role to make Edge API calls.
string $password: The password of an Edge user with org admin role to make Edge API calls.
string $base_url: The base url of the Edge API.
string $role_name: The role name to add the permissions to.
Return value
bool Returns true if the role exists, or false if it doesn't.
Throws
\GuzzleHttp\Exception\TransferException
1 call to ApigeeEdgeManagementCliService::doesRoleExist()
- ApigeeEdgeManagementCliService::createEdgeRoleForDrupal in src/
Command/ Util/ ApigeeEdgeManagementCliService.php - Create role in Apigee Edge for Drupal to use for Edge connection.
File
- src/
Command/ Util/ ApigeeEdgeManagementCliService.php, line 207
Class
- ApigeeEdgeManagementCliService
- Defines an interface for Edge connection classes.
Namespace
Drupal\apigee_edge\Command\UtilCode
public function doesRoleExist(string $org, string $email, string $password, string $base_url, string $role_name) {
$url = $base_url . '/o/' . $org . '/userroles/' . $role_name;
try {
$response = $this->httpClient
->get($url, [
'auth' => [
$email,
$password,
],
'headers' => [
'Accept' => 'application/json',
],
]);
} catch (ClientException $exception) {
if ($exception
->getCode() == 404) {
// Role does not exist.
return FALSE;
}
// Any other response was an exception.
throw $exception;
}
// Make sure role exists.
$body = json_decode((string) $response
->getBody());
if (isset($body->name) && $body->name == $role_name) {
return TRUE;
}
else {
return FALSE;
}
}