oso-oso 0.7.1 → 0.10.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/ext/oso-oso/lib/libpolar.dylib +0 -0
- data/ext/oso-oso/lib/libpolar.so +0 -0
- data/ext/oso-oso/lib/polar.dll +0 -0
- data/lib/oso.rb +0 -2
- data/lib/oso/oso.rb +0 -2
- data/lib/oso/polar/errors.rb +1 -0
- data/lib/oso/polar/host.rb +1 -1
- data/lib/oso/polar/polar.rb +3 -0
- data/lib/oso/polar/query.rb +28 -31
- data/lib/oso/version.rb +1 -1
- metadata +2 -4
- data/lib/oso/http.rb +0 -16
- data/lib/oso/path_mapper.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae952cafcf3913929a677cf97af57146e43cf818
|
4
|
+
data.tar.gz: 1a2d03946f1c4150c15fe190ce7a9cdf7f1cf4f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21238d2bc1cebc1706a2f09b51106faaed0a91cd3ba1e79a36d1d51c6819c7a489d0fdda8aed200f343c3a3a143f1fdf6d567b3efd4e3c1e64465098d204e53
|
7
|
+
data.tar.gz: 9f479f720fc1ee1b8cd09f69a7518c1e9cc6c9b0fae1f4070e657d931df804765003888a0d3026513c5024412a150798c52b6717b0e34ed6ba6bff148d996a28
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
oso-oso (0.
|
4
|
+
oso-oso (0.10.0)
|
5
5
|
ffi (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
coderay (1.1.3)
|
15
15
|
diff-lcs (1.4.4)
|
16
16
|
e2mmap (0.1.0)
|
17
|
-
ffi (1.
|
17
|
+
ffi (1.14.2)
|
18
18
|
jaro_winkler (1.5.4)
|
19
19
|
maruku (0.7.3)
|
20
20
|
method_source (1.0.0)
|
Binary file
|
data/ext/oso-oso/lib/libpolar.so
CHANGED
Binary file
|
data/ext/oso-oso/lib/polar.dll
CHANGED
Binary file
|
data/lib/oso.rb
CHANGED
data/lib/oso/oso.rb
CHANGED
data/lib/oso/polar/errors.rb
CHANGED
@@ -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
|
data/lib/oso/polar/host.rb
CHANGED
@@ -46,7 +46,7 @@ module Oso
|
|
46
46
|
# @raise [DuplicateClassAliasError] if attempting to register a class
|
47
47
|
# under a previously-registered name.
|
48
48
|
def cache_class(cls, name:)
|
49
|
-
raise DuplicateClassAliasError
|
49
|
+
raise DuplicateClassAliasError.new name: name, old: get_class(name), new: cls if classes.key? name
|
50
50
|
|
51
51
|
classes[name] = cls
|
52
52
|
name
|
data/lib/oso/polar/polar.rb
CHANGED
data/lib/oso/polar/query.rb
CHANGED
@@ -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
|
-
|
102
|
-
|
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
|
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
|
data/lib/oso/version.rb
CHANGED
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.
|
4
|
+
version: 0.10.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:
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -130,9 +130,7 @@ files:
|
|
130
130
|
- ext/oso-oso/lib/libpolar.so
|
131
131
|
- ext/oso-oso/lib/polar.dll
|
132
132
|
- lib/oso.rb
|
133
|
-
- lib/oso/http.rb
|
134
133
|
- lib/oso/oso.rb
|
135
|
-
- lib/oso/path_mapper.rb
|
136
134
|
- lib/oso/polar.rb
|
137
135
|
- lib/oso/polar/errors.rb
|
138
136
|
- lib/oso/polar/ffi.rb
|
data/lib/oso/http.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Oso
|
4
|
-
# An HTTP resource.
|
5
|
-
class Http
|
6
|
-
def initialize(hostname, path, query)
|
7
|
-
@hostname = hostname
|
8
|
-
@path = path
|
9
|
-
@query = query
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
attr_reader :hostname, :path, :query
|
15
|
-
end
|
16
|
-
end
|
data/lib/oso/path_mapper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Oso
|
4
|
-
# Map from a template string with capture groups of the form
|
5
|
-
# `{name}` to a dictionary of the form `{name: captured_value}`
|
6
|
-
class PathMapper
|
7
|
-
def initialize(template)
|
8
|
-
capture_group = /({([^}]+)})/
|
9
|
-
|
10
|
-
template = template.dup
|
11
|
-
template.scan(capture_group).each do |outer, inner|
|
12
|
-
template = if inner == '*'
|
13
|
-
template.gsub! outer, '.*'
|
14
|
-
else
|
15
|
-
template.gsub! outer, "(?<#{inner}>[^/]+)"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
@pattern = /\A#{template}\Z/
|
19
|
-
end
|
20
|
-
|
21
|
-
def map(string)
|
22
|
-
string.match(pattern)&.named_captures || {}
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :pattern
|
28
|
-
end
|
29
|
-
end
|