Skip to content

Commit 34f2e4f

Browse files
authored
feat: add docs: add minimal DocC catalog (#32)
1 parent 03b836a commit 34f2e4f

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Adapters
2+
3+
Adapters load and save policy.
4+
5+
- FileAdapter(filePath: "examples/basic_policy.csv")
6+
- MemoryAdapter()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Caching
2+
3+
SwiftCasbin includes an optional in-memory cache for enforce results.
4+
5+
- Enable: `e.enableMemoryCache(capacity: 200)`
6+
- Clear: `e.getCache()?.clear()`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Policy Management
2+
3+
Add or remove policy at runtime.
4+
5+
```swift
6+
_ = try e.addPolicy(params: ["alice", "data1", "read"]).get()
7+
let removed = try e.removeFilteredPolicy(fieldIndex: 1, fieldValues: ["domain1","data1"]).get()
8+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Quick Start
2+
3+
Minimal example to authorize a request with SwiftCasbin.
4+
5+
```swift
6+
import Casbin
7+
8+
let model = try DefaultModel.from(text: ""
9+
+ "[request_definition]\n"
10+
+ "r = sub, obj, act\n"
11+
+ "[policy_definition]\n"
12+
+ "p = sub, obj, act\n"
13+
+ "[policy_effect]\n"
14+
+ "e = some(where (p.eft == allow))\n"
15+
+ "[matchers]\n"
16+
+ "m = r.sub == p.sub && r.obj == p.obj && r.act == p.act\n"
17+
)
18+
let adapter = MemoryAdapter()
19+
let e = try Enforcer(m: model, adapter: adapter)
20+
_ = try e.addPolicy(params: ["alice", "data1", "read"]).get()
21+
let ok = try e.enforce("alice", "data1", "read").get()
22+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ``Casbin``
2+
3+
SwiftCasbin is a Swift authorization library that evaluates access decisions from a model (CONF) and policy rules (CSV) with RBAC, ABAC, and RESTful matchers.
4+
5+
## Overview
6+
7+
Load a model and policy via an Adapter, then call Enforcer.enforce to authorize a request.
8+
9+
### Quick Start
10+
11+
```swift
12+
import Casbin
13+
14+
let model = try DefaultModel.from(text: ""
15+
+ "[request_definition]\n"
16+
+ "r = sub, obj, act\n"
17+
+ "[policy_definition]\n"
18+
+ "p = sub, obj, act\n"
19+
+ "[policy_effect]\n"
20+
+ "e = some(where (p.eft == allow))\n"
21+
+ "[matchers]\n"
22+
+ "m = r.sub == p.sub && r.obj == p.obj && r.act == p.act\n"
23+
)
24+
let adapter = MemoryAdapter()
25+
let e = try Enforcer(m: model, adapter: adapter)
26+
_ = try e.addPolicy(params: ["alice", "data1", "read"]).get()
27+
let ok = try e.enforce("alice", "data1", "read").get()
28+
```
29+
30+
## Topics
31+
32+
### Guides
33+
- <doc:QuickStart>
34+
- <doc:Caching>
35+
- <doc:Adapters>
36+
- <doc:PolicyManagement>

0 commit comments

Comments
 (0)