oso-oso 0.23.0 → 0.26.0

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.
@@ -94,8 +94,7 @@ module Oso
94
94
  else
95
95
  instance.__send__(attribute, *args, **kwargs)
96
96
  end
97
- result = JSON.dump(host.to_polar(result))
98
- call_result(result, call_id: call_id)
97
+ call_result(host.to_polar(result), call_id: call_id)
99
98
  rescue ArgumentError, NoMethodError => e
100
99
  application_error(e.message)
101
100
  call_result(nil, call_id: call_id)
@@ -143,7 +142,7 @@ module Oso
143
142
  calls[call_id] = value.lazy
144
143
  end
145
144
 
146
- result = JSON.dump(next_call_result(call_id))
145
+ result = next_call_result(call_id)
147
146
  call_result(result, call_id: call_id)
148
147
  rescue StopIteration
149
148
  call_result(nil, call_id: call_id)
@@ -245,12 +244,23 @@ module Oso
245
244
 
246
245
  def handle_relationship(call_id, instance, rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
247
246
  typ = host.types[rel.other_type]
248
- constraint = ::Oso::Polar::DataFiltering::Filter.new(
249
- kind: 'Eq',
250
- field: rel.other_field,
251
- value: instance.send(rel.my_field)
247
+
248
+ cls = typ.klass.get
249
+
250
+ condition = ::Oso::Polar::Data::Filter::Condition.new(
251
+ ::Oso::Polar::Data::Filter::Projection.new(cls, rel.other_field),
252
+ 'Eq',
253
+ instance.send(rel.my_field)
252
254
  )
253
- res = typ.exec_query[typ.build_query[[constraint]]]
255
+
256
+ filter = ::Oso::Polar::Data::Filter.new(
257
+ model: cls,
258
+ relations: [],
259
+ conditions: [[condition]],
260
+ types: host.types
261
+ )
262
+
263
+ res = host.adapter.execute_query host.adapter.build_query(filter)
254
264
 
255
265
  if rel.kind == 'one'
256
266
  raise "multiple parents: #{res}" unless res.length == 1
@@ -258,8 +268,7 @@ module Oso
258
268
  res = res[0]
259
269
  end
260
270
 
261
- res = JSON.dump host.to_polar res
262
- call_result(res, call_id: call_id)
271
+ call_result(host.to_polar(res), call_id: call_id)
263
272
  end
264
273
  end
265
274
  end
data/lib/oso/polar.rb CHANGED
@@ -11,6 +11,7 @@ require 'oso/polar/query'
11
11
  require 'oso/polar/query_event'
12
12
  require 'oso/polar/variable'
13
13
  require 'oso/polar/data_filtering'
14
+ require 'oso/polar/data'
14
15
 
15
16
  module Oso
16
17
  # Top-level namespace for Polar language library.
data/lib/oso/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oso
4
- VERSION = '0.23.0'
4
+ VERSION = '0.26.0'
5
5
  end
data/lib/oso.rb CHANGED
@@ -8,7 +8,6 @@ require 'oso/version'
8
8
  # Top-level namespace for Oso authorization library.
9
9
  module Oso
10
10
  Relation = ::Oso::Polar::DataFiltering::Relation
11
- Filter = ::Oso::Polar::DataFiltering::Filter
12
11
 
13
12
  def self.new(not_found_error: NotFoundError, forbidden_error: ForbiddenError, read_action: 'read')
14
13
  ::Oso::Oso.new(not_found_error: not_found_error, forbidden_error: forbidden_error, read_action: read_action)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oso-oso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oso Security, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-10 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -162,16 +162,18 @@ files:
162
162
  - lib/oso/errors.rb
163
163
  - lib/oso/oso.rb
164
164
  - lib/oso/polar.rb
165
+ - lib/oso/polar/data.rb
166
+ - lib/oso/polar/data/adapter.rb
167
+ - lib/oso/polar/data/adapter/active_record_adapter.rb
168
+ - lib/oso/polar/data/filter.rb
165
169
  - lib/oso/polar/data_filtering.rb
166
170
  - lib/oso/polar/errors.rb
167
171
  - lib/oso/polar/expression.rb
168
172
  - lib/oso/polar/ffi.rb
169
173
  - lib/oso/polar/ffi/error.rb
170
- - lib/oso/polar/ffi/message.rb
171
174
  - lib/oso/polar/ffi/polar.rb
172
175
  - lib/oso/polar/ffi/query.rb
173
- - lib/oso/polar/ffi/query_event.rb
174
- - lib/oso/polar/ffi/source.rb
176
+ - lib/oso/polar/ffi/rust_string.rb
175
177
  - lib/oso/polar/host.rb
176
178
  - lib/oso/polar/pattern.rb
177
179
  - lib/oso/polar/polar.rb
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- module Oso
6
- module Polar
7
- module FFI
8
- # Wrapper class for Message FFI pointer + operations.
9
- class Message < ::FFI::AutoPointer
10
- # @return [String]
11
- def to_s
12
- @to_s ||= read_string.force_encoding('UTF-8')
13
- end
14
-
15
- Rust = Module.new do
16
- extend ::FFI::Library
17
- ffi_lib FFI::LIB_PATH
18
-
19
- attach_function :free, :string_free, [Message], :int32
20
- end
21
-
22
- def process(enrich_message)
23
- message = JSON.parse(to_s)
24
- kind = message['kind']
25
- msg = message['msg']
26
- msg = enrich_message.call(msg)
27
-
28
- case kind
29
- when 'Print'
30
- puts(msg)
31
- when 'Warning'
32
- warn(format('[warning] %<msg>s', msg: msg))
33
- end
34
- end
35
-
36
- private_constant :Rust
37
- end
38
- end
39
- end
40
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Oso
4
- module Polar
5
- module FFI
6
- # Wrapper class for QueryEvent FFI pointer + operations.
7
- class QueryEvent < ::FFI::AutoPointer
8
- # @return [String]
9
- def to_s
10
- @to_s ||= read_string.force_encoding('UTF-8')
11
- end
12
-
13
- Rust = Module.new do
14
- extend ::FFI::Library
15
- ffi_lib FFI::LIB_PATH
16
-
17
- attach_function :free, :string_free, [FFI::QueryEvent], :int32
18
- end
19
- private_constant :Rust
20
- end
21
- end
22
- end
23
- end