cedar_policy 0.1.0-x64-mingw-ucrt → 0.2.0-x64-mingw-ucrt
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/.cross_rubies +0 -4
- data/README.md +46 -10
- 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/3.3/cedar_policy.so +0 -0
- data/lib/cedar_policy/context.rb +14 -0
- data/lib/cedar_policy/entities.rb +14 -0
- data/lib/cedar_policy/entity.rb +32 -0
- data/lib/cedar_policy/entity_uid.rb +31 -0
- data/lib/cedar_policy/version.rb +1 -1
- data/lib/cedar_policy.rb +21 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 352fb8b0bba39354b308498edb3db13be6adaadbbce79d1bb5b609c9bd960a6c
|
4
|
+
data.tar.gz: '0499e1d6fb5fcda311a6ea3f00311c1dc1b6867c2948933cb7e61006dd54f220'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34821ca0271fe61863365a23c7e5b23042e174bf2223b04f06c417fa5e808ebbb9e6a6339f1d904b905addbe10ab94ab103175069b2f0014db27ad24d045e07d
|
7
|
+
data.tar.gz: 3f318558b5fb444d8ecf5bf69ffcf791c81b513b04c41f6fd8ac7493a91820e070fc192b661698a893877eba7d744e7aa63f6e722ae29ce1dd46007dcbef0f66
|
data/.cross_rubies
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
3.0.0:aarch64-linux
|
2
|
-
3.0.0:arm-linux
|
3
2
|
3.0.0:arm64-darwin
|
4
3
|
3.0.0:x64-mingw32
|
5
4
|
3.0.0:x86_64-darwin
|
6
5
|
3.0.0:x86_64-linux
|
7
6
|
3.1.0:aarch64-linux
|
8
|
-
3.1.0:arm-linux
|
9
7
|
3.1.0:arm64-darwin
|
10
8
|
3.1.0:x64-mingw-ucrt
|
11
9
|
3.1.0:x86_64-darwin
|
12
10
|
3.1.0:x86_64-linux
|
13
11
|
3.2.0:aarch64-linux
|
14
|
-
3.2.0:arm-linux
|
15
12
|
3.2.0:arm64-darwin
|
16
13
|
3.2.0:x64-mingw-ucrt
|
17
14
|
3.2.0:x86_64-darwin
|
18
15
|
3.2.0:x86_64-linux
|
19
16
|
3.3.0:aarch64-linux
|
20
|
-
3.3.0:arm-linux
|
21
17
|
3.3.0:arm64-darwin
|
22
18
|
3.3.0:x64-mingw-ucrt
|
23
19
|
3.3.0:x86_64-darwin
|
data/README.md
CHANGED
@@ -1,24 +1,60 @@
|
|
1
|
-
|
1
|
+
Cedar Policy
|
2
|
+
===
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cedar_policy`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
Ruby bindings for Cedar policy evaluation engine.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
8
|
Install the gem and add to the application's Gemfile by executing:
|
12
9
|
|
13
|
-
$ bundle add
|
10
|
+
$ bundle add cedar_policy
|
14
11
|
|
15
12
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
13
|
|
17
|
-
$ gem install
|
14
|
+
$ gem install cedar_policy
|
18
15
|
|
19
16
|
## Usage
|
20
17
|
|
21
|
-
|
18
|
+
> [!WARNING]
|
19
|
+
> This gem is still under development and the API may change in the future.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
policy = <<~POLICY
|
23
|
+
permit(
|
24
|
+
principal == AdminUser::"1",
|
25
|
+
action == Action::"view",
|
26
|
+
resource
|
27
|
+
);
|
28
|
+
POLICY
|
29
|
+
policy_set = CedarPolicy::PolicySet.new(policy)
|
30
|
+
|
31
|
+
principal = CedarPolicy::EntityUid.new("User", "1")
|
32
|
+
action = CedarPolicy::EntityUid.new("Action", "view")
|
33
|
+
resource = CedarPolicy::EntityUid.new("Image", "1")
|
34
|
+
ctx = CedarPolicy::Context.new
|
35
|
+
|
36
|
+
request = CedarPolicy::Request.new(principal, action, resource, ctx)
|
37
|
+
|
38
|
+
entities = CedarPolicy::Entities.new([
|
39
|
+
CedarPolicy::Entity.new(
|
40
|
+
CedarPolicy::EntityUid.new("User", "1"),
|
41
|
+
{ role: "admin" }
|
42
|
+
)
|
43
|
+
])
|
44
|
+
|
45
|
+
authorizer = CedarPolicy::Authorizer.new
|
46
|
+
authorizer.authorize?(request, policy_set, entities) # => true
|
47
|
+
|
48
|
+
response = authorizer.authorize(request, policy_set, entities)
|
49
|
+
response.decision # => CedarPolicy::Decision::ALLOW
|
50
|
+
```
|
51
|
+
|
52
|
+
## Roadmap
|
53
|
+
|
54
|
+
* [ ] Add DSL to improve developer experience
|
55
|
+
* [ ] Diagnostics return with response
|
56
|
+
* [ ] Validator support
|
57
|
+
* [ ] Schema support
|
22
58
|
|
23
59
|
## Development
|
24
60
|
|
@@ -28,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
28
64
|
|
29
65
|
## Contributing
|
30
66
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/cedar-policy-rb.
|
32
68
|
|
33
69
|
## License
|
34
70
|
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CedarPolicy
|
4
|
+
# :nodoc:
|
5
|
+
class Entities
|
6
|
+
def initialize(entities = [])
|
7
|
+
@entities = Set.new(entities)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_ary
|
11
|
+
@entities.map { |entity| CedarPolicy.deep_serialize(entity) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CedarPolicy
|
4
|
+
# :nodoc:
|
5
|
+
class Entity
|
6
|
+
attr_reader :uid, :attrs, :parents
|
7
|
+
|
8
|
+
def initialize(uid, attrs = {}, parents = [])
|
9
|
+
raise ArgumentError unless uid.is_a?(EntityUid)
|
10
|
+
|
11
|
+
@uid = uid
|
12
|
+
@attrs = attrs
|
13
|
+
@parents = Set.new(parents)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
hahs == other.hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash
|
21
|
+
[self.class, @uid].hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_hash
|
25
|
+
{
|
26
|
+
uid: @uid,
|
27
|
+
attrs: @attrs,
|
28
|
+
parents: @parents.to_a
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CedarPolicy
|
4
|
+
# :nodoc:
|
5
|
+
class EntityUid
|
6
|
+
attr_reader :type_name, :id
|
7
|
+
|
8
|
+
def initialize(type_name, id)
|
9
|
+
@type_name = type_name.to_s
|
10
|
+
@id = id.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
hash == other.hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def hash
|
18
|
+
[self.class, @type_name, @id].hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_str
|
22
|
+
"#{@type_name}::#{@id.inspect}"
|
23
|
+
end
|
24
|
+
alias to_s to_str
|
25
|
+
alias inspect to_str
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{ type: @type_name, id: @id }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/cedar_policy/version.rb
CHANGED
data/lib/cedar_policy.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "json"
|
4
|
+
require "set"
|
5
|
+
|
3
6
|
require_relative "cedar_policy/version"
|
4
7
|
require_relative "cedar_policy/cedar_policy"
|
8
|
+
require_relative "cedar_policy/entity_uid"
|
9
|
+
require_relative "cedar_policy/entity"
|
10
|
+
require_relative "cedar_policy/entities"
|
11
|
+
require_relative "cedar_policy/context"
|
5
12
|
|
13
|
+
# :nodoc:
|
6
14
|
module CedarPolicy
|
7
15
|
class Error < StandardError; end
|
8
|
-
|
16
|
+
|
17
|
+
def self.deep_serialize(input)
|
18
|
+
input.to_hash.each_with_object({}) do |(key, value), output|
|
19
|
+
output[key.to_sym] =
|
20
|
+
case value
|
21
|
+
when ->(h) { h.respond_to?(:to_hash) } then deep_serialize(value)
|
22
|
+
when Array
|
23
|
+
value.map { |item| item.respond_to?(:to_hash) ? deep_serialize(item) : item }
|
24
|
+
else
|
25
|
+
value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
9
29
|
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: x64-mingw-ucrt
|
6
6
|
authors:
|
7
7
|
- Aotokitsuruya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby bindings for Cedar policy evaluation engine.
|
14
14
|
email:
|
@@ -27,6 +27,10 @@ files:
|
|
27
27
|
- lib/cedar_policy/3.1/cedar_policy.so
|
28
28
|
- lib/cedar_policy/3.2/cedar_policy.so
|
29
29
|
- lib/cedar_policy/3.3/cedar_policy.so
|
30
|
+
- lib/cedar_policy/context.rb
|
31
|
+
- lib/cedar_policy/entities.rb
|
32
|
+
- lib/cedar_policy/entity.rb
|
33
|
+
- lib/cedar_policy/entity_uid.rb
|
30
34
|
- lib/cedar_policy/version.rb
|
31
35
|
- sig/cedar_policy.rbs
|
32
36
|
homepage: https://github.com/elct9620/cedar-policy-rb
|