oso-oso 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2dbfedef3bc14832b47137d1c17b247af0cf8bf3
4
- data.tar.gz: 3bad36d04f6744069299b72855be913bc4bd9562
3
+ metadata.gz: c85bc41901e0ed5de32a11d192da0c26b79ac44c
4
+ data.tar.gz: 97f8718e22c0cee489fe7ed0db324d29fa1fb0a4
5
5
  SHA512:
6
- metadata.gz: 13d18f6a934a266e82ec7e981187f7f8523c998b55158044bc09271c255fa56e40159246a55096447296971d88e9c5c68355684d37db99cea59b911810949cd9
7
- data.tar.gz: 5cdae20c3b4c08752db940bcce466d65a787e9728ec935b837eb20eb98fffda4e88f812f63c1d75822f2bd25e6e741c1ae6df8620f2b587ca4b5db0f4901029b
6
+ metadata.gz: ac34d5b51b0f981965098265b2279b9b1f1b73488267e39fffe5eff3e74f484f8f46a9b03e86a6f6fd2326e23af7d93e5d139f57f807fa9e2560dd80392f6b04
7
+ data.tar.gz: d89cf2110f9e7e9e6a6a8070565a59bae49770545fe918fd3ebd7f3b408743446af77a152b4fa4e524aacd999f57d6b0403986adafc04bac6c06228e27d94d39
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-oso (0.7.1)
4
+ oso-oso (0.8.0)
5
5
  ffi (~> 1.0)
6
6
 
7
7
  GEM
Binary file
Binary file
@@ -38,6 +38,7 @@ module Oso
38
38
  # TODO: I think this should probably have some arguments to say what the call is
39
39
  class InvalidCallError < PolarRuntimeError; end
40
40
  class InvalidConstructorError < PolarRuntimeError; end
41
+ class InvalidIteratorError < PolarRuntimeError; end
41
42
  class InvalidQueryTypeError < PolarRuntimeError; end
42
43
  class NullByteInPolarFileError < PolarRuntimeError; end
43
44
  class UnexpectedPolarTypeError < PolarRuntimeError; end
@@ -38,6 +38,9 @@ module Oso
38
38
  @ffi_polar = FFI::Polar.create
39
39
  @host = Host.new(ffi_polar)
40
40
 
41
+ # Register global constants.
42
+ register_constant nil, name: 'nil'
43
+
41
44
  # Register built-in classes.
42
45
  register_class PolarBoolean, name: 'Boolean'
43
46
  register_class Integer
@@ -36,33 +36,6 @@ module Oso
36
36
  ffi_query.question_result(result, call_id: call_id)
37
37
  end
38
38
 
39
- # Register a Ruby method call, wrapping the call result in a generator if
40
- # it isn't already one.
41
- #
42
- # @param method [#to_sym]
43
- # @param call_id [Integer]
44
- # @param instance [Hash<String, Object>]
45
- # @param args [Array<Hash>]
46
- # @raise [InvalidCallError] if the method doesn't exist on the instance or
47
- # the args passed to the method are invalid.
48
- def register_call(attribute, call_id:, instance:, args:, kwargs:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
49
- return if calls.key?(call_id)
50
-
51
- instance = host.to_ruby(instance)
52
- args = args.map { |a| host.to_ruby(a) }
53
- kwargs = Hash[kwargs.map { |k, v| [k.to_sym, host.to_ruby(v)] }]
54
- # The kwargs.empty? check is for Ruby < 2.7.
55
- result = if kwargs.empty?
56
- instance.__send__(attribute, *args)
57
- else
58
- instance.__send__(attribute, *args, **kwargs)
59
- end
60
- result = [result].to_enum unless result.is_a? Enumerator # Call must be a generator.
61
- calls[call_id] = result.lazy
62
- rescue ArgumentError, NoMethodError
63
- raise InvalidCallError
64
- end
65
-
66
39
  # Send next result of Ruby method call across FFI boundary.
67
40
  #
68
41
  # @param result [String]
@@ -97,13 +70,33 @@ module Oso
97
70
  # @param call_id [Integer]
98
71
  # @param instance [Hash<String, Object>]
99
72
  # @raise [Error] if the FFI call raises one.
100
- def handle_call(attribute, call_id:, instance:, args:, kwargs:)
101
- register_call(attribute, call_id: call_id, instance: instance, args: args, kwargs: kwargs)
102
- result = JSON.dump(next_call_result(call_id))
73
+ def handle_call(attribute, call_id:, instance:, args:, kwargs:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
74
+ instance = host.to_ruby(instance)
75
+ args = args.map { |a| host.to_ruby(a) }
76
+ kwargs = Hash[kwargs.map { |k, v| [k.to_sym, host.to_ruby(v)] }]
77
+ # The kwargs.empty? check is for Ruby < 2.7.
78
+ result = if kwargs.empty?
79
+ instance.__send__(attribute, *args)
80
+ else
81
+ instance.__send__(attribute, *args, **kwargs)
82
+ end
83
+ result = JSON.dump(host.to_polar(result))
103
84
  call_result(result, call_id: call_id)
104
- rescue InvalidCallError => e
85
+ rescue ArgumentError, NoMethodError => e
105
86
  application_error(e.message)
106
87
  call_result(nil, call_id: call_id)
88
+ end
89
+
90
+ def handle_next_external(call_id, iterable)
91
+ unless calls.key? call_id
92
+ value = host.to_ruby iterable
93
+ raise InvalidIteratorError unless value.is_a? Enumerable
94
+
95
+ calls[call_id] = value.lazy
96
+ end
97
+
98
+ result = JSON.dump(next_call_result(call_id))
99
+ call_result(result, call_id: call_id)
107
100
  rescue StopIteration
108
101
  call_result(nil, call_id: call_id)
109
102
  end
@@ -173,6 +166,10 @@ module Oso
173
166
  ffi_query.debug_command(command)
174
167
  when 'ExternalOp'
175
168
  raise UnimplementedOperationError, 'comparison operators'
169
+ when 'NextExternal'
170
+ call_id = event.data['call_id']
171
+ iterable = event.data['iterable']
172
+ handle_next_external(call_id, iterable)
176
173
  else
177
174
  raise "Unhandled event: #{JSON.dump(event.inspect)}"
178
175
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oso
4
- VERSION = '0.7.1'
4
+ VERSION = '0.8.0'
5
5
  end
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.7.1
4
+ version: 0.8.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: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi