Scalr\Service\Azure::getContributorRoleAssignmentInfo PHP Method

getContributorRoleAssignmentInfo() public method

Get Role Assignment list in specified subscription.
public getContributorRoleAssignmentInfo ( string $subscriptionId, string $appObjectId, string $contributorRoleId ) : Scalr\Service\Azure\DataType\RoleAssignmentData
$subscriptionId string subscription::subscriptionId value of one of user's subscriptions
$appObjectId string Application Object Id
$contributorRoleId string Contributor Role Id
return Scalr\Service\Azure\DataType\RoleAssignmentData Server response body (JSON)
    public function getContributorRoleAssignmentInfo($subscriptionId, $appObjectId, $contributorRoleId)
    {
        $result = null;
        $path = '/subscriptions/' . $subscriptionId . '/providers/Microsoft.Authorization/roleAssignments';
        $headers = ['Authorization' => 'Bearer ' . $this->getAccessToken()->token];
        $request = $this->getClient()->prepareRequest($path, 'GET', self::RESOURCE_API_VERSION, Azure::URL_MANAGEMENT_WINDOWS, [], [], $headers);
        $response = $this->getClient()->call($request);
        $contributorRoleDefinitionId = "/subscriptions/" . $subscriptionId . "/providers/Microsoft.Authorization/roleDefinitions/" . $contributorRoleId;
        if (!$response->hasError()) {
            $responseObject = $response->getResult();
            foreach ($responseObject as $roleAssignment) {
                $roleAssignment = RoleAssignmentData::initArray($roleAssignment);
                /* @var $roleAssignment RoleAssignmentData */
                if (!empty($roleAssignment->properties->roleDefinitionId) && !empty($roleAssignment->properties->principalId) && $roleAssignment->properties->roleDefinitionId == $contributorRoleDefinitionId && $roleAssignment->properties->principalId == $appObjectId) {
                    $result = $roleAssignment;
                    break;
                }
            }
        }
        return $result;
    }