-
Notifications
You must be signed in to change notification settings - Fork 123
/
example.cs
50 lines (47 loc) · 2.07 KB
/
example.cs
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
49
50
using Cerbos.Api.V1.Effect;
using Cerbos.Sdk.Response;
using Cerbos.Sdk.Builder;
using Cerbos.Sdk.Utility;
internal class Program
{
private static void Main(string[] args)
{
var client = CerbosClientBuilder.ForTarget("http://localhost:3593").WithPlaintext().Build();
var request = CheckResourcesRequest
.NewInstance()
.WithRequestId(RequestId.Generate())
.WithIncludeMeta(true)
.WithPrincipal(
Principal
.NewInstance("bugs_bunny", "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")
.WithPolicyVersion("20210210")
.WithAttribute("owner", AttributeValue.StringValue("daffy_duck"))
.WithAttribute("public", AttributeValue.BoolValue(true))
.WithAttribute("flagged", AttributeValue.BoolValue(false))
.WithActions("comment", "view:public")
);
CheckResourcesResponse result = client.CheckResources(request);
foreach (var resourceId in new[] { "BUGS001", "DAFFY002" })
{
var resultEntry = result.Find(resourceId);
Console.Write($"\nResource ID: {resourceId}\n");
foreach (var actionEffect in resultEntry.Actions)
{
string action = actionEffect.Key;
Effect effect = actionEffect.Value;
Console.Write($"\t{action} -> {(effect == Effect.Allow ? "EFFECT_ALLOW" : "EFFECT_DENY")}\n");
}
}
}
}