script_core 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: c19d1c83197db63d2ddbf7f70ed6f02fd5398d6f1247d84b0f21b7152bc69d5d
4
- data.tar.gz: ce5ef153d196492d536a18bd04a39b0e7137fa2411e0c9dc55ad0a38a7a87e1f
3
+ metadata.gz: 5625cda9a35dc19c13582dc07e8bb2bec7845bc1c37c41df871ca51eafacbc95
4
+ data.tar.gz: c147044d8b43a6ca3c89d5a930cd8f7ee3855d914821d3ec9e6bd96bf39ecadf
5
5
  SHA512:
6
- metadata.gz: 68cb35a85e86480436c3c8a2dfa8ae8ded6f8f31c93e4429d37dd63dea54503b1d902383743327a2d967f4735ad39613cbf3eb319d72c25ce7e2dd93649b819a
7
- data.tar.gz: 804c806c5328bb8785e1011f28bf4655bd607c083646f11d8e78a66caad3abd45d92af74beb2ca752a3019f3e949e1412e6325bf023a7f9d5f67f340aa33e315
6
+ metadata.gz: fc78b84f71299af081e7fdc70090cb818ed54aa93053505b85605958affe6d76a43d613727c65ec9b8d1ca5832cb4f1afe2101677d920e048e4ca2e385a08676
7
+ data.tar.gz: 41f9a441d31541d8c25d42773ecc77b310a4ec7025dc8cf9690b1aad7b60e633d21edef707f43ce647e1948e317603e13766ea58be0a4fa6398abec6268dfb66
@@ -4,6 +4,7 @@ require:
4
4
 
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.5
7
+ DisabledByDefault: true
7
8
  Exclude:
8
9
  - bin/**/*
9
10
  - tests/**/*
@@ -15,35 +16,8 @@ AllCops:
15
16
  - spec/dummy/db/schema.rb
16
17
  - spec/dummy/bin/**/*
17
18
 
18
- Rails:
19
- Enabled: true
20
-
21
- Layout/LineLength:
22
- Max: 150
23
-
24
- Metrics/MethodLength:
25
- Max: 100
26
-
27
- Metrics/BlockLength:
28
- Max: 50
29
-
30
- Metrics/ClassLength:
31
- Enabled: false
32
-
33
- Style/GuardClause:
34
- Enabled: false
35
-
36
- Style/Documentation:
37
- Enabled: false
38
-
39
- Style/ClassAndModuleChildren:
40
- Enabled: false
41
-
42
- Naming/AccessorMethodName:
43
- Enabled: false
44
-
45
- Naming/MemoizedInstanceVariableName:
46
- Enabled: false
19
+ #Metrics/AbcSize:
20
+ # Max: 30
47
21
 
48
22
  # Prefer assert_not over assert !
49
23
  Rails/AssertNot:
@@ -55,25 +29,23 @@ Rails/RefuteMethods:
55
29
  Include:
56
30
  - 'test/**/*'
57
31
 
58
- # Prefer &&/|| over and/or.
59
- Style/AndOr:
32
+ Rails/IndexBy:
60
33
  Enabled: true
61
34
 
62
- # Do not use braces for hash literals when they are the last argument of a
63
- # method call.
64
- Style/HashEachMethods:
35
+ Rails/IndexWith:
65
36
  Enabled: true
66
37
 
67
- Style/HashTransformKeys:
68
- Enabled: true
69
-
70
- Style/HashTransformValues:
38
+ # Prefer &&/|| over and/or.
39
+ Style/AndOr:
71
40
  Enabled: true
72
41
 
73
42
  # Align `when` with `case`.
74
43
  Layout/CaseIndentation:
75
44
  Enabled: true
76
45
 
46
+ Layout/ClosingHeredocIndentation:
47
+ Enabled: true
48
+
77
49
  # Align comments with method definitions.
78
50
  Layout/CommentIndentation:
79
51
  Enabled: true
@@ -91,6 +63,9 @@ Layout/EndAlignment:
91
63
  Layout/EmptyLineAfterMagicComment:
92
64
  Enabled: true
93
65
 
66
+ Layout/EmptyLinesAroundAccessModifier:
67
+ Enabled: true
68
+
94
69
  Layout/EmptyLinesAroundBlockBody:
95
70
  Enabled: true
96
71
 
@@ -106,13 +81,13 @@ Layout/EmptyLinesAroundMethodBody:
106
81
  Layout/EmptyLinesAroundModuleBody:
107
82
  Enabled: true
108
83
 
109
- Layout/FirstArgumentIndentation:
110
- Enabled: true
111
-
112
84
  # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
113
85
  Style/HashSyntax:
114
86
  Enabled: true
115
87
 
88
+ Layout/FirstArgumentIndentation:
89
+ Enabled: true
90
+
116
91
  # Method definitions after `private` or `protected` isolated calls need one
117
92
  # extra level of indentation.
118
93
  Layout/IndentationConsistency:
@@ -141,10 +116,10 @@ Layout/SpaceAroundEqualsInParameterDefault:
141
116
  Layout/SpaceAroundKeyword:
142
117
  Enabled: true
143
118
 
144
- Layout/SpaceAroundOperators:
119
+ Layout/SpaceBeforeComma:
145
120
  Enabled: true
146
121
 
147
- Layout/SpaceBeforeComma:
122
+ Layout/SpaceBeforeComment:
148
123
  Enabled: true
149
124
 
150
125
  Layout/SpaceBeforeFirstArg:
@@ -164,9 +139,6 @@ Style/FrozenStringLiteralComment:
164
139
  Style/RedundantFreeze:
165
140
  Enabled: true
166
141
 
167
- Style/AccessModifierDeclarations:
168
- Enabled: false
169
-
170
142
  # Use `foo {}` not `foo{}`.
171
143
  Layout/SpaceBeforeBlockBraces:
172
144
  Enabled: true
@@ -192,7 +164,7 @@ Style/StringLiterals:
192
164
  Layout/IndentationStyle:
193
165
  Enabled: true
194
166
 
195
- # Blank lines should not have any spaces.
167
+ # Empty lines should not have any spaces.
196
168
  Layout/TrailingEmptyLines:
197
169
  Enabled: true
198
170
 
@@ -200,9 +172,6 @@ Layout/TrailingEmptyLines:
200
172
  Layout/TrailingWhitespace:
201
173
  Enabled: true
202
174
 
203
- Layout/SpaceAroundMethodCallOperator:
204
- Enabled: true
205
-
206
175
  # Use quotes for string literals when they are enough.
207
176
  Style/RedundantPercentQ:
208
177
  Enabled: true
@@ -235,19 +204,16 @@ Lint/UselessAssignment:
235
204
  Lint/DeprecatedClassMethods:
236
205
  Enabled: true
237
206
 
238
- Lint/AssignmentInCondition:
239
- Enabled: false
240
-
241
- Lint/RaiseException:
207
+ Lint/DeprecatedOpenSSLConstant:
242
208
  Enabled: true
243
209
 
244
- Lint/StructNewOverride:
210
+ Style/ParenthesesAroundCondition:
245
211
  Enabled: true
246
212
 
247
- Style/ExponentialNotation:
213
+ Style/HashTransformKeys:
248
214
  Enabled: true
249
215
 
250
- Style/ParenthesesAroundCondition:
216
+ Style/HashTransformValues:
251
217
  Enabled: true
252
218
 
253
219
  Style/RedundantBegin:
@@ -268,6 +234,12 @@ Style/ColonMethodCall:
268
234
  Style/TrivialAccessors:
269
235
  Enabled: true
270
236
 
237
+ Style/SlicingWithRange:
238
+ Enabled: true
239
+
240
+ Style/RedundantRegexpEscape:
241
+ Enabled: true
242
+
271
243
  Performance/FlatMap:
272
244
  Enabled: true
273
245
 
@@ -288,3 +260,9 @@ Performance/ReverseEach:
288
260
 
289
261
  Performance/UnfreezeString:
290
262
  Enabled: true
263
+
264
+ Performance/DeletePrefix:
265
+ Enabled: true
266
+
267
+ Performance/DeleteSuffix:
268
+ Enabled: true
@@ -21,15 +21,34 @@ def initialize(bin_path = ScriptCore::DEFAULT_BIN_PATH,
21
21
  @instructions = File.exist?(preload_instructions_path) ? File.binread(preload_instructions_path) : nil
22
22
  end
23
23
 
24
- def eval(sources, input: nil, instruction_quota_start: nil, environment_variables: {})
24
+ def eval(
25
+ sources, input: {}, environment_variables: {},
26
+ instruction_quota: nil, instruction_quota_start: nil, memory_quota: nil, timeout: nil
27
+ )
25
28
  @executable.run(
26
- input: input || {},
29
+ input: input,
27
30
  sources: sources,
28
31
  instructions: @instructions,
29
- timeout: @timeout,
30
- instruction_quota: @instruction_quota,
32
+ timeout: timeout || @timeout,
33
+ instruction_quota: instruction_quota || @instruction_quota,
31
34
  instruction_quota_start: instruction_quota_start || @instruction_quota_start,
32
- memory_quota: @memory_quota,
35
+ memory_quota: memory_quota || @memory_quota,
36
+ environment_variables: environment_variables
37
+ )
38
+ end
39
+
40
+ def eval_mrb(
41
+ binary_mrb, input: {}, environment_variables: {},
42
+ instruction_quota: nil, instruction_quota_start: nil, memory_quota: nil, timeout: nil
43
+ )
44
+ @executable.run(
45
+ input: input,
46
+ sources: [],
47
+ instructions: binary_mrb,
48
+ timeout: timeout || @timeout,
49
+ instruction_quota: instruction_quota || @instruction_quota,
50
+ instruction_quota_start: instruction_quota_start || @instruction_quota_start,
51
+ memory_quota: memory_quota || @memory_quota,
33
52
  environment_variables: environment_variables
34
53
  )
35
54
  end
@@ -12,9 +12,10 @@ def initialize(executable_path)
12
12
  @executable_path = executable_path.to_s
13
13
  end
14
14
 
15
- def run(input: {}, sources:, instructions: nil,
16
- timeout: 1, instruction_quota: 100_000, instruction_quota_start: 0, memory_quota: 8 << 20,
17
- environment_variables: {})
15
+ def run(
16
+ input: {}, environment_variables: {}, sources:, instructions: nil,
17
+ timeout: 1, instruction_quota: 100_000, instruction_quota_start: 0, memory_quota: 8 << 20
18
+ )
18
19
  packer = ScriptCore::Protocol.packer_factory.packer
19
20
 
20
21
  payload = { input: input, sources: sources }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScriptCore
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
@@ -63,7 +63,9 @@
63
63
  end
64
64
 
65
65
  Dir.chdir(SCRIPT_CORE_ROOT.join("ext/enterprise_script_service")) do
66
- sh("#{env_vars} #{Rails.root.join('bin', 'bundle')} exec rake")
66
+ bundle_stub_path = Rails.root.join("bin", "bundle")
67
+ bundle_cmd = File.exists?(bundle_stub_path) ? bundle_stub_path : "bundle"
68
+ sh("#{env_vars} #{bundle_cmd} exec rake")
67
69
  end
68
70
  end
69
71
 
@@ -40,7 +40,6 @@
40
40
  spec.add_dependency("msgpack", "~> 1.0")
41
41
  spec.add_dependency("rake-compiler", "~> 1.0")
42
42
 
43
- spec.add_development_dependency("bundler", "~> 1")
44
- spec.add_development_dependency("rake", "~> 12.0")
43
+ spec.add_development_dependency("rake", "~> 12")
45
44
  spec.add_development_dependency("rspec", "~> 3.5")
46
45
  end
@@ -2,11 +2,43 @@
2
2
 
3
3
  module ScriptEngine
4
4
  class << self
5
+ ENGINE_PATH = Rails.root.join("mruby")
6
+
5
7
  def engine
6
- @engine ||= ScriptCore::Engine.new Rails.root.join("mruby/bin")
8
+ @engine ||= ScriptCore::Engine.new ENGINE_PATH.join("bin")
7
9
  end
8
10
 
9
- def run(string, payload: nil, instruction_quota_start: nil)
11
+ def precompile(code, with_lib: true)
12
+ wrapped_code =
13
+ if with_lib
14
+ "prepare; Output.value = class Object\n#{code}\nend; pack_output"
15
+ else
16
+ code
17
+ end
18
+
19
+ mrbc_executable = ENGINE_PATH.join("bin/mrbc").realpath
20
+ tmp_dir = Rails.root.join("tmp")
21
+ lib_files = with_lib ? Dir[ENGINE_PATH.join("lib/**/*.rb").to_s] : []
22
+
23
+ code_sha = Digest::SHA2.hexdigest(wrapped_code)
24
+ tmp_rb = tmp_dir.join("#{code_sha}.rb")
25
+ tmp_output = tmp_dir.join("#{code_sha}.mrb")
26
+ cmd = "#{mrbc_executable} --remove-lv -o #{tmp_output} #{lib_files.join(' ')} #{tmp_rb}"
27
+
28
+ File.write tmp_rb, wrapped_code
29
+ system(cmd, exception: true)
30
+
31
+ compiled = File.binread tmp_output
32
+
33
+ FileUtils.rm([tmp_rb, tmp_output])
34
+
35
+ compiled
36
+ end
37
+
38
+ def run(
39
+ string, payload: nil,
40
+ instruction_quota: nil, instruction_quota_start: nil, memory_quota: nil, timeout: nil
41
+ )
10
42
  sources = [
11
43
  %w[preparing prepare],
12
44
  ["user", string],
@@ -20,14 +52,41 @@ def run(string, payload: nil, instruction_quota_start: nil)
20
52
  },
21
53
  payload: payload
22
54
  },
55
+ environment_variables: { "TZ" => Time.zone.name },
56
+ instruction_quota: instruction_quota,
23
57
  instruction_quota_start: instruction_quota_start,
24
- environment_variables: { "TZ" => Time.zone.name }
58
+ memory_quota: memory_quota,
59
+ timeout: timeout
25
60
  end
26
61
 
27
- def run_inline(string, payload: nil, instruction_quota_start: nil)
62
+ def run_inline(
63
+ string, payload: nil,
64
+ instruction_quota: nil, instruction_quota_start: nil, memory_quota: nil, timeout: nil
65
+ )
28
66
  run "Output.value = class Object\n#{string}\nend",
29
67
  payload: payload,
30
- instruction_quota_start: instruction_quota_start
68
+ instruction_quota: instruction_quota,
69
+ instruction_quota_start: instruction_quota_start,
70
+ memory_quota: memory_quota,
71
+ timeout: timeout
72
+ end
73
+
74
+ def run_precompiled(
75
+ binary_mrb, payload: nil,
76
+ instruction_quota: nil, instruction_quota_start: nil, memory_quota: nil, timeout: nil
77
+ )
78
+ engine.eval_mrb binary_mrb,
79
+ input: {
80
+ configuration: {
81
+ time_zone_offset: Time.zone.formatted_offset(false)
82
+ },
83
+ payload: payload
84
+ },
85
+ environment_variables: { "TZ" => Time.zone.name },
86
+ instruction_quota: instruction_quota,
87
+ instruction_quota_start: instruction_quota_start,
88
+ memory_quota: memory_quota,
89
+ timeout: timeout
31
90
  end
32
91
  end
33
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -38,34 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '12.0'
47
+ version: '12'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '12.0'
54
+ version: '12'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -2935,7 +2921,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2935
2921
  - !ruby/object:Gem::Version
2936
2922
  version: '0'
2937
2923
  requirements: []
2938
- rubygems_version: 3.1.2
2924
+ rubygems_version: 3.1.4
2939
2925
  signing_key:
2940
2926
  specification_version: 4
2941
2927
  summary: A script engine powered by mruby sandboxie, It's a fork of Shopify's ESS.