oso-oso 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '09ee09c3366406a34633c870ddfe4ff271971529'
4
- data.tar.gz: 764b0f3b440d567e19e45b71eff823b9000f35ef
3
+ metadata.gz: cf2c949f57a56b4849f24ed9593c78da58baa5a0
4
+ data.tar.gz: 31ac99dcfa3bba1bbbee68474a3fe3702fb7484d
5
5
  SHA512:
6
- metadata.gz: fdae19c2528c46a85004241f0a8e59639123e416724239670cb9ff2ffc1172a87bb116b481d575e466c74f634213abdced263211f991721f1ff990e1e085d884
7
- data.tar.gz: 309a196e2a0a3725e3bc1f45be8382ed85026dc7fc271662efaef8e207b0df2891f26da48ece702f1d9ce3e3731ea52c0a6cea30bf50af6acde54f08b44d79ec
6
+ metadata.gz: f1708d82f2531d50456ddcadb967bd024414700808e81b440836eb344f542cfda46af651382a6445a098dce9cf1e1c63c6802df73e3f97713a819d0b07ef5aae
7
+ data.tar.gz: d96b91d530555ed98d040c2d3c8e8e0adbdffa352cef6bd49c22e6f225c16bfa9f4c488d37468201e16e0950791581621737b94f1b9d5ffc8b8c4dffeaa4e656
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-oso (0.5.0)
4
+ oso-oso (0.5.1)
5
5
  ffi (~> 1.0)
6
6
 
7
7
  GEM
data/Makefile CHANGED
@@ -3,17 +3,17 @@
3
3
  rust:
4
4
  $(MAKE) -C ../.. rust-build
5
5
 
6
- install: rust
6
+ install:
7
7
  bundle install
8
8
 
9
- test: install
9
+ test: install rust
10
10
  bundle exec rake spec
11
11
 
12
- lint:
12
+ lint: install
13
13
  bundle exec rubocop
14
14
 
15
- typecheck:
15
+ typecheck: install
16
16
  bundle exec solargraph typecheck
17
17
 
18
- repl: install
18
+ repl: install rust
19
19
  bundle exec oso
Binary file
Binary file
@@ -27,6 +27,7 @@ module Oso
27
27
  class UnsupportedError < PolarRuntimeError; end
28
28
  class PolarTypeError < PolarRuntimeError; end
29
29
  class StackOverflowError < PolarRuntimeError; end
30
+ class FileLoadingError < PolarRuntimeError; end
30
31
 
31
32
  # Errors originating from this side of the FFI boundary.
32
33
 
@@ -37,26 +38,12 @@ module Oso
37
38
  class InvalidCallError < PolarRuntimeError; end
38
39
  class InvalidConstructorError < PolarRuntimeError; end
39
40
  class InvalidQueryTypeError < PolarRuntimeError; end
40
- class InlineQueryFailedError < PolarRuntimeError; end
41
41
  class NullByteInPolarFileError < PolarRuntimeError; end
42
42
  class UnexpectedPolarTypeError < PolarRuntimeError; end
43
- class PolarFileAlreadyLoadedError < PolarRuntimeError # rubocop:disable Style/Documentation
44
- # @param file [String]
45
- def initialize(file)
46
- super("File #{file} has already been loaded.")
47
- end
48
- end
49
- class PolarFileContentsChangedError < PolarRuntimeError # rubocop:disable Style/Documentation
50
- # @param file [String]
51
- def initialize(file)
52
- super("A file with the name #{file}, but different contents, has already been loaded.")
53
- end
54
- end
55
- class PolarFileNameChangedError < PolarRuntimeError # rubocop:disable Style/Documentation
56
- # @param file [String]
57
- # @param existing [String]
58
- def initialize(file, existing)
59
- super("A file with the same contents as #{file} named #{existing} has already been loaded.")
43
+ class InlineQueryFailedError < PolarRuntimeError; # rubocop:disable Style/Documentation
44
+ # @param source [String]
45
+ def initialize(source)
46
+ super("Inline query failed: #{source}")
60
47
  end
61
48
  end
62
49
  class PolarFileExtensionError < PolarRuntimeError # rubocop:disable Style/Documentation
@@ -46,6 +46,13 @@ module Oso
46
46
  Rust.free(ptr) unless ptr.null?
47
47
  end
48
48
  end
49
+
50
+ # Wrapper class for Source FFI pointer.
51
+ class Source < ::FFI::AutoPointer
52
+ def self.release(ptr)
53
+ Rust.free(ptr) unless ptr.null?
54
+ end
55
+ end
49
56
  end
50
57
  private_constant :FFI
51
58
  end
@@ -56,3 +63,4 @@ require 'oso/polar/ffi/query'
56
63
  require 'oso/polar/ffi/query_event'
57
64
  require 'oso/polar/ffi/error'
58
65
  require 'oso/polar/ffi/message'
66
+ require 'oso/polar/ffi/source'
@@ -83,6 +83,8 @@ module Oso
83
83
  ::Oso::Polar::PolarTypeError.new(msg, details: details)
84
84
  when 'StackOverflow'
85
85
  ::Oso::Polar::StackOverflowError.new(msg, details: details)
86
+ when 'FileLoading'
87
+ ::Oso::Polar::FileLoadingError.new(msg, details: details)
86
88
  else
87
89
  ::Oso::Polar::PolarRuntimeError.new(msg, details: details)
88
90
  end
@@ -26,7 +26,7 @@ module Oso
26
26
  when 'Print'
27
27
  puts(msg)
28
28
  when 'Warning'
29
- warn('[warning] %<msg>s')
29
+ warn(format('[warning] %<msg>s', msg: msg))
30
30
  end
31
31
  end
32
32
 
@@ -10,7 +10,7 @@ module Oso
10
10
  ffi_lib FFI::LIB_PATH
11
11
 
12
12
  attach_function :new, :polar_new, [], FFI::Polar
13
- attach_function :load_str, :polar_load, [FFI::Polar, :string, :string], :int32
13
+ attach_function :load, :polar_load, [FFI::Polar, :string, :string], :int32
14
14
  attach_function :next_inline_query, :polar_next_inline_query, [FFI::Polar, :uint32], FFI::Query
15
15
  attach_function :new_id, :polar_get_external_id, [FFI::Polar], :uint64
16
16
  attach_function :new_query_from_str, :polar_new_query, [FFI::Polar, :string, :uint32], FFI::Query
@@ -33,8 +33,8 @@ module Oso
33
33
  # @param src [String]
34
34
  # @param filename [String]
35
35
  # @raise [FFI::Error] if the FFI call returns an error.
36
- def load_str(src, filename: nil)
37
- loaded = Rust.load_str(self, src, filename)
36
+ def load(src, filename: nil)
37
+ loaded = Rust.load(self, src, filename)
38
38
  process_messages
39
39
  raise FFI::Error.get if loaded.zero?
40
40
  end
@@ -15,6 +15,7 @@ module Oso
15
15
  attach_function :application_error, :polar_application_error, [FFI::Query, :string], :int32
16
16
  attach_function :next_event, :polar_next_query_event, [FFI::Query], FFI::QueryEvent
17
17
  attach_function :next_message, :polar_next_query_message, [FFI::Query], FFI::Message
18
+ attach_function :source, :polar_query_source_info, [FFI::Query], FFI::Source
18
19
  attach_function :free, :query_free, [FFI::Query], :int32
19
20
  end
20
21
  private_constant :Rust
@@ -74,6 +75,15 @@ module Oso
74
75
  message.process
75
76
  end
76
77
  end
78
+
79
+ # @return [String]
80
+ # @raise [FFI::Error] if the FFI call returns an error.
81
+ def source
82
+ res = Rust.source(self)
83
+ raise FFI::Error.get if res.null?
84
+
85
+ res.to_s
86
+ end
77
87
  end
78
88
  end
79
89
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oso
4
+ module Polar
5
+ module FFI
6
+ # Wrapper class for Source FFI pointer.
7
+ class Source < ::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, [Message], :int32
18
+ end
19
+
20
+ private_constant :Rust
21
+ end
22
+ end
23
+ end
24
+ end
@@ -42,8 +42,6 @@ module Oso
42
42
  def initialize
43
43
  @ffi_polar = FFI::Polar.create
44
44
  @host = Host.new(ffi_polar)
45
- @loaded_names = {}
46
- @loaded_contents = {}
47
45
 
48
46
  # Register built-in classes.
49
47
  register_class PolarBoolean, name: 'Boolean'
@@ -56,8 +54,6 @@ module Oso
56
54
 
57
55
  # Replace the current Polar instance but retain all registered classes and constructors.
58
56
  def clear
59
- loaded_names.clear
60
- loaded_contents.clear
61
57
  @ffi_polar = FFI::Polar.create
62
58
  end
63
59
 
@@ -66,23 +62,11 @@ module Oso
66
62
  # @param name [String]
67
63
  # @raise [PolarFileExtensionError] if provided filename has invalid extension.
68
64
  # @raise [PolarFileNotFoundError] if provided filename does not exist.
69
- def load_file(name) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
65
+ def load_file(name)
70
66
  raise PolarFileExtensionError, name unless File.extname(name) == '.polar'
71
67
 
72
68
  file_data = File.open(name, &:read)
73
- hash = Digest::MD5.hexdigest(file_data)
74
-
75
- if loaded_names.key?(name)
76
- raise PolarFileAlreadyLoadedError, name if loaded_names[name] == hash
77
-
78
- raise PolarFileContentsChangedError, name
79
- elsif loaded_contents.key?(hash)
80
- raise PolarFileNameChangedError, name, loaded_contents[hash]
81
- else
82
- load_str(file_data, filename: name)
83
- loaded_names[name] = hash
84
- loaded_contents[hash] = name
85
- end
69
+ load_str(file_data, filename: name)
86
70
  rescue Errno::ENOENT
87
71
  raise PolarFileNotFoundError, name
88
72
  end
@@ -97,7 +81,7 @@ module Oso
97
81
  def load_str(str, filename: nil) # rubocop:disable Metrics/MethodLength
98
82
  raise NullByteInPolarFileError if str.chomp("\0").include?("\0")
99
83
 
100
- ffi_polar.load_str(str, filename: filename)
84
+ ffi_polar.load(str, filename: filename)
101
85
  loop do
102
86
  next_query = ffi_polar.next_inline_query
103
87
  break if next_query.nil?
@@ -105,7 +89,7 @@ module Oso
105
89
  begin
106
90
  Query.new(next_query, host: host).results.next
107
91
  rescue StopIteration
108
- raise InlineQueryFailedError
92
+ raise InlineQueryFailedError, next_query.source
109
93
  end
110
94
  end
111
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oso
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
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.5.0
4
+ version: 0.5.1
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-08-25 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -141,6 +141,7 @@ files:
141
141
  - lib/oso/polar/ffi/polar.rb
142
142
  - lib/oso/polar/ffi/query.rb
143
143
  - lib/oso/polar/ffi/query_event.rb
144
+ - lib/oso/polar/ffi/source.rb
144
145
  - lib/oso/polar/host.rb
145
146
  - lib/oso/polar/polar.rb
146
147
  - lib/oso/polar/predicate.rb