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 +4 -4
- data/.rubocop.yml +35 -57
- data/lib/script_core/engine.rb +24 -5
- data/lib/script_core/executable.rb +4 -3
- data/lib/script_core/version.rb +1 -1
- data/lib/tasks/script_core.rake +3 -1
- data/script_core.gemspec +1 -2
- data/spec/dummy/app/lib/script_engine.rb +64 -5
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5625cda9a35dc19c13582dc07e8bb2bec7845bc1c37c41df871ca51eafacbc95
|
4
|
+
data.tar.gz: c147044d8b43a6ca3c89d5a930cd8f7ee3855d914821d3ec9e6bd96bf39ecadf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc78b84f71299af081e7fdc70090cb818ed54aa93053505b85605958affe6d76a43d613727c65ec9b8d1ca5832cb4f1afe2101677d920e048e4ca2e385a08676
|
7
|
+
data.tar.gz: 41f9a441d31541d8c25d42773ecc77b310a4ec7025dc8cf9690b1aad7b60e633d21edef707f43ce647e1948e317603e13766ea58be0a4fa6398abec6268dfb66
|
data/.rubocop.yml
CHANGED
@@ -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
|
-
|
19
|
-
|
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
|
-
|
59
|
-
Style/AndOr:
|
32
|
+
Rails/IndexBy:
|
60
33
|
Enabled: true
|
61
34
|
|
62
|
-
|
63
|
-
# method call.
|
64
|
-
Style/HashEachMethods:
|
35
|
+
Rails/IndexWith:
|
65
36
|
Enabled: true
|
66
37
|
|
67
|
-
|
68
|
-
|
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/
|
119
|
+
Layout/SpaceBeforeComma:
|
145
120
|
Enabled: true
|
146
121
|
|
147
|
-
Layout/
|
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
|
-
#
|
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/
|
239
|
-
Enabled: false
|
240
|
-
|
241
|
-
Lint/RaiseException:
|
207
|
+
Lint/DeprecatedOpenSSLConstant:
|
242
208
|
Enabled: true
|
243
209
|
|
244
|
-
|
210
|
+
Style/ParenthesesAroundCondition:
|
245
211
|
Enabled: true
|
246
212
|
|
247
|
-
Style/
|
213
|
+
Style/HashTransformKeys:
|
248
214
|
Enabled: true
|
249
215
|
|
250
|
-
Style/
|
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
|
data/lib/script_core/engine.rb
CHANGED
@@ -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(
|
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(
|
16
|
-
|
17
|
-
|
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 }
|
data/lib/script_core/version.rb
CHANGED
data/lib/tasks/script_core.rake
CHANGED
@@ -63,7 +63,9 @@
|
|
63
63
|
end
|
64
64
|
|
65
65
|
Dir.chdir(SCRIPT_CORE_ROOT.join("ext/enterprise_script_service")) do
|
66
|
-
|
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
|
|
data/script_core.gemspec
CHANGED
@@ -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("
|
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
|
8
|
+
@engine ||= ScriptCore::Engine.new ENGINE_PATH.join("bin")
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
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
|
-
|
58
|
+
memory_quota: memory_quota,
|
59
|
+
timeout: timeout
|
25
60
|
end
|
26
61
|
|
27
|
-
def run_inline(
|
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
|
-
|
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.
|
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-
|
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
|
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
|
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.
|
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.
|