cedar_policy 0.2.0-x86_64-linux → 0.5.2-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +35 -0
- data/README.md +57 -5
- data/lib/cedar_policy/3.0/cedar_policy.so +0 -0
- data/lib/cedar_policy/3.1/cedar_policy.so +0 -0
- data/lib/cedar_policy/3.2/cedar_policy.so +0 -0
- data/lib/cedar_policy/entities.rb +13 -1
- data/lib/cedar_policy/entity.rb +8 -4
- data/lib/cedar_policy/entity_uid.rb +4 -1
- data/lib/cedar_policy/version.rb +1 -1
- data/release-please-config.json +18 -0
- metadata +7 -5
- data/lib/cedar_policy/3.3/cedar_policy.so +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d70d8d232fc3c61e8e7a84883b0e29f0945176cfd21e33bbeb6c2de988f5ec4
|
4
|
+
data.tar.gz: e79e71b96da97d5dbbb0d0e6ef1c0f78b343216bf8920ab348d72ddaf83ac26e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18c7ead5618d2d796ff9f7e3e8a51a71a6ff76ea87b647804b6f75114a11d76c98ef5c8c356916bea7339b4210f5e4a72e986dbfd77eda3a69ba589dbb73dd38
|
7
|
+
data.tar.gz: ae146c75001414f15197e623aa8e24c33f676d3d0b6bb876e486e3aab1255ae9358f56937edec1384b8f82c0d14f0c559a91beb7c9c408c2a8250263fb973672
|
@@ -0,0 +1 @@
|
|
1
|
+
{".":"0.5.2"}
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.5.2](https://github.com/elct9620/cedar-policy-rb/compare/v0.5.1...v0.5.2) (2025-01-22)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* rb-sys version too old cause build failed ([6b58381](https://github.com/elct9620/cedar-policy-rb/commit/6b583811e9d7e8eef3fe1843e7a04f8b9fc6f975))
|
9
|
+
|
10
|
+
## [0.5.1](https://github.com/elct9620/cedar-policy-rb/compare/v0.5.0...v0.5.1) (2025-01-22)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* the Gemfile.lock not updated ([8853e74](https://github.com/elct9620/cedar-policy-rb/commit/8853e747188e83aa4ac1bfa7b4d1c361932cdb76))
|
16
|
+
|
17
|
+
## [0.5.0](https://github.com/elct9620/cedar-policy-rb/compare/v0.4.0...v0.5.0) (2025-01-22)
|
18
|
+
|
19
|
+
|
20
|
+
### Features
|
21
|
+
|
22
|
+
* **deps:** bump rust cedar_policy to v4.3.0 ([9aea4f1](https://github.com/elct9620/cedar-policy-rb/commit/9aea4f130867243b4d61be41a2f8abfd3d021df2))
|
23
|
+
* **deps:** update cedar-policy to 4.2.0 ([a7218d7](https://github.com/elct9620/cedar-policy-rb/commit/a7218d7c3af0384cfcdae735f07b06c624ea8002))
|
24
|
+
|
25
|
+
## [0.4.0](https://github.com/elct9620/cedar-policy-rb/compare/cedar_policy-v0.3.0...cedar_policy/v0.4.0) (2024-10-06)
|
26
|
+
|
27
|
+
|
28
|
+
### Features
|
29
|
+
|
30
|
+
* **deps:** upgrade cedar-policy to v4.1.0 ([61d6fa1](https://github.com/elct9620/cedar-policy-rb/commit/61d6fa1a59ab2edd71972410c1d9d697fde60776))
|
31
|
+
|
32
|
+
|
33
|
+
### Bug Fixes
|
34
|
+
|
35
|
+
* commitizen hook file bundled into gem ([b0c9c77](https://github.com/elct9620/cedar-policy-rb/commit/b0c9c77459ec614bfd4698d804969adb9b4bccc1))
|
data/README.md
CHANGED
@@ -18,6 +18,10 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
18
18
|
> [!WARNING]
|
19
19
|
> This gem is still under development and the API may change in the future.
|
20
20
|
|
21
|
+
### PolicySet
|
22
|
+
|
23
|
+
Define a policy by Cedar Language:
|
24
|
+
|
21
25
|
```ruby
|
22
26
|
policy = <<~POLICY
|
23
27
|
permit(
|
@@ -27,32 +31,80 @@ policy = <<~POLICY
|
|
27
31
|
);
|
28
32
|
POLICY
|
29
33
|
policy_set = CedarPolicy::PolicySet.new(policy)
|
34
|
+
```
|
35
|
+
|
36
|
+
> Currently, the single policy is not supported.
|
30
37
|
|
31
|
-
|
38
|
+
### Request
|
39
|
+
|
40
|
+
Prepare the Entity's ID via `EntityUid` or an object with `#to_hash` method which returns a hash with `:type` and `:id` keys.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
principal = CedarPolicy::EntityUid.new("User", "1") # or { type: "User", id: "1" }
|
32
44
|
action = CedarPolicy::EntityUid.new("Action", "view")
|
33
45
|
resource = CedarPolicy::EntityUid.new("Image", "1")
|
34
|
-
|
46
|
+
```
|
35
47
|
|
48
|
+
The `Context` object is used to store the request context. Use `Context` or an object with `#to_hash` method which returns a hash.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
ctx = CedarPolicy::Context.new({ ip: "127.0.0.1" }) # or { ip: "127.0.0.1" }
|
52
|
+
```
|
53
|
+
> The `Context` object can initialize without any arguments as an empty context.
|
54
|
+
|
55
|
+
Create a `Request` object with the principal, action, resource, and context.
|
56
|
+
|
57
|
+
```ruby
|
36
58
|
request = CedarPolicy::Request.new(principal, action, resource, ctx)
|
59
|
+
```
|
37
60
|
|
61
|
+
### Entities
|
62
|
+
|
63
|
+
Define the entities with related this request. It should be an array of `Entity` objects which have `#to_hash` method returns a hash with `:uid`,`:attrs`, and `:parents` keys.
|
64
|
+
|
65
|
+
```ruby
|
38
66
|
entities = CedarPolicy::Entities.new([
|
39
67
|
CedarPolicy::Entity.new(
|
40
68
|
CedarPolicy::EntityUid.new("User", "1"),
|
41
|
-
{ role: "admin" }
|
42
|
-
|
69
|
+
{ role: "admin" },
|
70
|
+
[] # Parents' EntityUid
|
71
|
+
),
|
72
|
+
{
|
73
|
+
uid: { type: "Image", id: "1" },
|
74
|
+
attrs: {},
|
75
|
+
parents: []
|
76
|
+
}
|
43
77
|
])
|
78
|
+
```
|
44
79
|
|
80
|
+
### Authorizer
|
81
|
+
|
82
|
+
Create an `Authorizer` object and authorize the request with the policy set and entities.
|
83
|
+
|
84
|
+
```ruby
|
45
85
|
authorizer = CedarPolicy::Authorizer.new
|
86
|
+
```
|
87
|
+
|
88
|
+
If boolean result is enough, use `#authorize?` method.
|
89
|
+
|
90
|
+
```ruby
|
46
91
|
authorizer.authorize?(request, policy_set, entities) # => true
|
92
|
+
```
|
47
93
|
|
94
|
+
If you want to get the decision object, use `#authorize` method.
|
95
|
+
|
96
|
+
```ruby
|
48
97
|
response = authorizer.authorize(request, policy_set, entities)
|
49
98
|
response.decision # => CedarPolicy::Decision::ALLOW
|
50
99
|
```
|
51
100
|
|
101
|
+
> The diagnostics is not supported yet in the response.
|
102
|
+
|
52
103
|
## Roadmap
|
53
104
|
|
54
105
|
* [ ] Add DSL to improve developer experience
|
55
|
-
* [ ]
|
106
|
+
* [ ] Add batch authorization support
|
107
|
+
* [x] Diagnostics return with response
|
56
108
|
* [ ] Validator support
|
57
109
|
* [ ] Schema support
|
58
110
|
|
Binary file
|
Binary file
|
Binary file
|
@@ -3,8 +3,20 @@
|
|
3
3
|
module CedarPolicy
|
4
4
|
# :nodoc:
|
5
5
|
class Entities
|
6
|
+
include Enumerable
|
7
|
+
|
6
8
|
def initialize(entities = [])
|
7
|
-
@entities = Set.new(entities
|
9
|
+
@entities = Set.new(entities.map do |entity|
|
10
|
+
next entity if entity.is_a?(Entity)
|
11
|
+
|
12
|
+
Entity.new(*entity.values_at(:uid, :attrs, :parents))
|
13
|
+
end)
|
14
|
+
end
|
15
|
+
|
16
|
+
def each(&block)
|
17
|
+
return enum_for(:each) unless block_given?
|
18
|
+
|
19
|
+
@entities.each(&block)
|
8
20
|
end
|
9
21
|
|
10
22
|
def to_ary
|
data/lib/cedar_policy/entity.rb
CHANGED
@@ -6,15 +6,19 @@ module CedarPolicy
|
|
6
6
|
attr_reader :uid, :attrs, :parents
|
7
7
|
|
8
8
|
def initialize(uid, attrs = {}, parents = [])
|
9
|
-
raise ArgumentError unless uid.is_a?(EntityUid)
|
9
|
+
raise ArgumentError unless uid.is_a?(EntityUid) || uid.is_a?(Hash)
|
10
10
|
|
11
|
-
@uid = uid
|
11
|
+
@uid = if uid.is_a?(EntityUid)
|
12
|
+
uid
|
13
|
+
else
|
14
|
+
EntityUid.new(*uid.values_at(:type, :id))
|
15
|
+
end
|
12
16
|
@attrs = attrs
|
13
17
|
@parents = Set.new(parents)
|
14
18
|
end
|
15
19
|
|
16
|
-
def
|
17
|
-
|
20
|
+
def eql?(other)
|
21
|
+
hash == other.hash
|
18
22
|
end
|
19
23
|
|
20
24
|
def hash
|
@@ -8,11 +8,14 @@ module CedarPolicy
|
|
8
8
|
def initialize(type_name, id)
|
9
9
|
@type_name = type_name.to_s
|
10
10
|
@id = id.to_s
|
11
|
+
|
12
|
+
freeze
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def eql?(other)
|
14
16
|
hash == other.hash
|
15
17
|
end
|
18
|
+
alias == eql?
|
16
19
|
|
17
20
|
def hash
|
18
21
|
[self.class, @type_name, @id].hash
|
data/lib/cedar_policy/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"release-type": "ruby",
|
3
|
+
"last-release-sha": "7d06a6458e9805cc6ec05f456c650708cc9d9e9f",
|
4
|
+
"packages": {
|
5
|
+
".":{
|
6
|
+
"component": "cedar_policy",
|
7
|
+
"include-component-in-tag": false,
|
8
|
+
"release-type": "ruby"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
"extra-files": [
|
12
|
+
{
|
13
|
+
"type": "toml",
|
14
|
+
"path": "ext/cedar_policy/Cargo.toml",
|
15
|
+
"jsonpath": "$.package.version"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cedar_policy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.5.2
|
5
5
|
platform: x86_64-linux
|
6
6
|
authors:
|
7
7
|
- Aotokitsuruya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby bindings for Cedar policy evaluation engine.
|
14
14
|
email:
|
@@ -18,8 +18,10 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- ".cross_rubies"
|
21
|
+
- ".release-please-manifest.json"
|
21
22
|
- ".rspec"
|
22
23
|
- ".rubocop.yml"
|
24
|
+
- CHANGELOG.md
|
23
25
|
- LICENSE.txt
|
24
26
|
- README.md
|
25
27
|
- Rakefile
|
@@ -27,12 +29,12 @@ files:
|
|
27
29
|
- lib/cedar_policy/3.0/cedar_policy.so
|
28
30
|
- lib/cedar_policy/3.1/cedar_policy.so
|
29
31
|
- lib/cedar_policy/3.2/cedar_policy.so
|
30
|
-
- lib/cedar_policy/3.3/cedar_policy.so
|
31
32
|
- lib/cedar_policy/context.rb
|
32
33
|
- lib/cedar_policy/entities.rb
|
33
34
|
- lib/cedar_policy/entity.rb
|
34
35
|
- lib/cedar_policy/entity_uid.rb
|
35
36
|
- lib/cedar_policy/version.rb
|
37
|
+
- release-please-config.json
|
36
38
|
- sig/cedar_policy.rbs
|
37
39
|
homepage: https://github.com/elct9620/cedar-policy-rb
|
38
40
|
licenses:
|
@@ -53,14 +55,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
55
|
version: '3.0'
|
54
56
|
- - "<"
|
55
57
|
- !ruby/object:Gem::Version
|
56
|
-
version: 3.
|
58
|
+
version: 3.3.dev
|
57
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
60
|
requirements:
|
59
61
|
- - ">="
|
60
62
|
- !ruby/object:Gem::Version
|
61
63
|
version: 3.3.11
|
62
64
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
65
|
+
rubygems_version: 3.5.23
|
64
66
|
signing_key:
|
65
67
|
specification_version: 4
|
66
68
|
summary: Ruby bindings for Cedar policy evaluation engine.
|
Binary file
|