-
Notifications
You must be signed in to change notification settings - Fork 123
/
example.php
48 lines (42 loc) · 1.76 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require __DIR__ . '/vendor/autoload.php';
use Cerbos\Effect\V1\Effect;
use Cerbos\Sdk\Builder\AttributeValue;
use Cerbos\Sdk\Builder\CerbosClientBuilder;
use Cerbos\Sdk\Builder\CheckResourcesRequest;
use Cerbos\Sdk\Builder\Principal;
use Cerbos\Sdk\Builder\ResourceEntry;
use Cerbos\Sdk\Utility\RequestId;
$client = CerbosClientBuilder::newInstance("localhost:3593")
->withPlaintext(true)
->build();
$request = CheckResourcesRequest::newInstance()
->withRequestId(RequestId::generate())
->withPrincipal(
Principal::newInstance("bugs_bunny")
->withRole("user")
->withAttribute("beta_tester", AttributeValue::boolValue(true))
)
->withResourceEntries(
[
ResourceEntry::newInstance("album:object", "BUGS001")
->withAttribute("owner", AttributeValue::stringValue("bugs_bunny"))
->withAttribute("public", AttributeValue::boolValue(false))
->withAttribute("flagged", AttributeValue::boolValue(false))
->withActions(["comment", "view:public"]),
ResourceEntry::newInstance("album:object", "DAFFY002")
->withAttribute("owner", AttributeValue::stringValue("daffy_duck"))
->withAttribute("public", AttributeValue::boolValue(true))
->withAttribute("flagged", AttributeValue::boolValue(false))
->withActions(["comment", "view:public"])
]
);
$checkResourcesResponse = $client->checkResources($request);
foreach (["BUGS001", "DAFFY002"] as $resourceId) {
$resultEntry = $checkResourcesResponse->find($resourceId);
$actions = $resultEntry->getActions();
foreach ($actions as $k => $v) {
printf("%s -> %s", $k, Effect::name($v));
}
}
?>