cpee-eval-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df0ac0169869de150fcc4006236aa7827c8815199b5a05b2433b02f31c00aea7
4
+ data.tar.gz: 1fe55c3eef49f0bb3ca16807c58e986cc8b57bc94064af24cbee4029cb488344
5
+ SHA512:
6
+ metadata.gz: 9607dea7a01072d1533d91365ccf3436454aa49f8da0521d3b8906639f83cc11ecc0c442b216ece4a955e6e5c0a96ee0920eb1c74ab95a917152fed16056eb8f
7
+ data.tar.gz: b2d29f6757561af76ef56bc414e6f834c9d7c5a0d2d2c239ddf958508517eb79753994cad8e2396217ac52104a34d13b26f9ca7031a73ed4ee90d948f6a2fdbb
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Juergen 'eTM' Mangler <juergen.mangler@gmail.com>
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # CPEE Eval Ruby
2
+
3
+ CPEE can utilize multiple script languages when it comes to evaluationg
4
+ conditions, excuting prepare/finalize/update/rescue or script tasks.
5
+
6
+ Evaluating the expresions/code is delegated to an external service. This
7
+ projects implements the ruby version of this functionality.
8
+
9
+ The advantage of this approach is, so that you can isolate the evaluation on
10
+ separate servers for security and load-balancing reasons.
11
+
12
+ To install the service go to the commandline
13
+
14
+ ```bash
15
+ gem install cpee-eval-ruby
16
+ cpee-eval-ruby new eval
17
+ cd eval
18
+ ./eval-ruby start
19
+ ```
20
+
21
+ The service is running under port 9302. If this port has to be changed (or the
22
+ host, or local-only access, ...), create a file eval-ruby.conf and add one
23
+ or many of the following yaml keys:
24
+
25
+ ```yaml
26
+ :port: 9302
27
+ :bind: 127.0.0.1
28
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+ require 'rubygems/package_task'
3
+
4
+ spec = eval(File.read('cpee-eval-ruby.gemspec'))
5
+ Gem::PackageTask.new(spec) do |pkg|
6
+ pkg.need_zip = true
7
+ pkg.need_tar = true
8
+ FileUtils.mkdir 'pkg' rescue nil
9
+ FileUtils.rm_rf Dir.glob('pkg/*')
10
+ FileUtils.ln_sf "#{pkg.name}.gem", "pkg/#{spec.name}.gem"
11
+ end
12
+
13
+ task :default => [:gem]
14
+
15
+ task :push => :gem do |r|
16
+ `gem push pkg/cpee-eval-ruby.gem`
17
+ end
18
+
19
+ task :install => :gem do |r|
20
+ `gem install pkg/cpee-eval-ruby.gem`
21
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cpee-eval-ruby"
3
+ s.version = "1.0.0"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.license = "LGPL-3.0-or-later"
6
+ s.summary = "Ruby eval for the cloud process execution engine (cpee.org)"
7
+
8
+ s.description = "see http://cpee.org"
9
+
10
+ s.files = Dir['{server/**/*,tools/**/*,lib/**/*}'] + %w(LICENSE Rakefile cpee-eval-ruby.gemspec README.md AUTHORS)
11
+ s.require_path = 'lib'
12
+ s.extra_rdoc_files = ['README.md']
13
+ s.bindir = 'tools'
14
+ s.executables = ['cpee-eval-ruby']
15
+
16
+ s.required_ruby_version = '>=2.4.0'
17
+
18
+ s.authors = ['Juergen eTM Mangler']
19
+
20
+ s.email = 'juergen.mangler@gmail.com'
21
+ s.homepage = 'http://cpee.org/'
22
+
23
+ s.add_runtime_dependency 'riddl', '~> 1.0'
24
+ end
@@ -0,0 +1,107 @@
1
+ # This file is part of CPEE-EVAL-RUBY.
2
+ #
3
+ # CPEE-EVAL-RUBY is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as published by the
5
+ # Free Software Foundation, either version 3 of the License, or (at your
6
+ # option) any later version.
7
+ #
8
+ # CPEE-EVAL-RUBY is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with CPEE-EVAL-RUBY (file LICENSE in the main directory). If not,
15
+ # see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'rubygems'
18
+ require 'cpee/value_helper'
19
+ require 'xml/smart'
20
+ require 'riddl/server'
21
+ require 'securerandom'
22
+ require 'base64'
23
+ require 'uri'
24
+ require 'redis'
25
+ require 'json'
26
+ require 'weel'
27
+ require_relative 'translation'
28
+
29
+ module CPEE
30
+ module EvalRuby
31
+
32
+ SERVER = File.expand_path(File.join(__dir__,'implementation.xml'))
33
+
34
+ class DoIt < Riddl::Implementation #{{{
35
+ def exec(mr,code,result=nil,headers=nil)
36
+ mr.instance_eval(code)
37
+ end
38
+
39
+ def response
40
+ code = @p.shift.value
41
+ # code = code.read if code.respond_to? :read
42
+ # code = Riddl::Protocols::Utils::unescape(code)
43
+ dataelements = JSON::parse(@p.shift.value.read)
44
+ local = nil
45
+ local = JSON::parse(@p.shift.value.read) if @p[0].name == 'local'
46
+ endpoints = JSON::parse(@p.shift.value.read)
47
+ additional = JSON::parse(@p.shift.value.read)
48
+ status = JSON::parse(@p.shift.value.read) if @p.any? && @p[0].name == 'status'
49
+ status = WEEL::Status.new(status['id'],status['message']) if status
50
+ call_result = JSON::parse(@p.shift.value.read) if @p.any? && @p[0].name == 'call_result'
51
+ call_headers = JSON::parse(@p.shift.value.read) if @p.any? && @p[0].name == 'call_headers'
52
+
53
+ # symbolize keys, because JSON
54
+ dataelements.transform_keys!{|k| k.to_sym}
55
+ local.first.transform_keys!{|k| k.to_sym} if local
56
+ endpoints.transform_keys!{|k| k.to_sym}
57
+ additional.transform_keys!{|k| k.to_sym}
58
+ additional.each_value do |v|
59
+ v.transform_keys!{|k| k.to_sym}
60
+ end
61
+
62
+ if status || call_result || call_headers
63
+ struct = WEEL::ManipulateStructure.new(dataelements,endpoints,status,local,additional)
64
+ exec struct, code, CPEE::EvalRuby::Translation::simplify_structurized_result(call_result), call_headers
65
+ ret = []
66
+ ret.push Riddl::Parameter::Simple.new('result','')
67
+
68
+ res = {}
69
+ struct.changed_data.each do |e|
70
+ res[e] = struct.data[e]
71
+ end
72
+ ret.push Riddl::Parameter::Complex.new('changed_dataelements','application/json',JSON::generate(res)) if res.any?
73
+ res = {}
74
+ struct.changed_endpoints.each do |e|
75
+ res[e] = struct.endpoints[e]
76
+ end
77
+ ret.push Riddl::Parameter::Complex.new('changed_endpoints','application/json',JSON::generate(res)) if res.any?
78
+ ret.push Riddl::Parameter::Complex.new('changed_status','application/json',JSON::generate(status)) if struct.changed_status
79
+ ret
80
+ else
81
+ struct = WEEL::ReadStructure.new(dataelements,endpoints,local,additional)
82
+ res = exec struct, code
83
+ Riddl::Parameter::Simple.new('result',res)
84
+ end
85
+ end
86
+ end #}}}
87
+ class Structurize < Riddl::Implementation #{{{
88
+ def response
89
+ Riddl::Parameter::Complex.new('structurized','application/json',JSON::generate(CPEE::EvalRuby::Translation::structurize_result(@p)))
90
+ end
91
+ end #}}}
92
+
93
+ def self::implementation(opts)
94
+ Proc.new do
95
+ on resource do
96
+ on resource 'exec' do
97
+ run DoIt if put 'exec'
98
+ end
99
+ on resource 'structurize' do
100
+ run Structurize if put
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+ end
@@ -0,0 +1,69 @@
1
+ <!--
2
+ This file is part of CPEE-EVAL-RUBY.
3
+
4
+ CPEE-EVAL-RUBY is free software: you can redistribute it and/or modify it
5
+ under the terms of the GNU Lesser General Public License as published by the
6
+ Free Software Foundation, either version 3 of the License, or (at your
7
+ option) any later version.
8
+
9
+ CPEE-EVAL-RUBY is distributed in the hope that it will be useful, but WITHOUT
10
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
+ details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with CPEE-EVAL-RUBY (file LICENSE in the main directory). If not, see
16
+ <http://www.gnu.org/licenses/>.
17
+ -->
18
+
19
+ <description datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://riddl.org/ns/description/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
20
+ <message name="exec">
21
+ <parameter name="code" type="string"/>
22
+ <parameter name="dataelements" mimetype="application/json"/>
23
+ <optional>
24
+ <parameter name="local" mimetype="application/json"/>
25
+ </optional>
26
+ <parameter name="endpoints" mimetype="application/json"/>
27
+ <parameter name="additional" mimetype="application/json"/>
28
+ <optional>
29
+ <parameter name="status" mimetype="application/json"/>
30
+ </optional>
31
+ <optional>
32
+ <parameter name="call_result" mimetype="application/json"/>
33
+ <parameter name="call_headers" mimetype="application/json"/>
34
+ </optional>
35
+ </message>
36
+
37
+ <message name="res">
38
+ <choice>
39
+ <parameter name="result" type="boolean"/>
40
+ <parameter name="result" type="string"/>
41
+ </choice>
42
+ <optional>
43
+ <parameter name="signal" type="string"/>
44
+ </optional>
45
+ <optional>
46
+ <parameter name="changed_dataelements" mimetype="application/json"/>
47
+ </optional>
48
+ <optional>
49
+ <parameter name="changed_endpoints" mimetype="application/json"/>
50
+ </optional>
51
+ <optional>
52
+ <parameter name="changed_status" mimetype="application/json"/>
53
+ </optional>
54
+ </message>
55
+
56
+ <message name="struc">
57
+ <parameter name="structurized" mimetype="application/json"/>
58
+ </message>
59
+
60
+ <resource>
61
+ <resource relative="exec">
62
+ <put in="exec" out="res"/>
63
+ </resource>
64
+ <resource relative="structurize">
65
+ <put out="struc"/>
66
+ </resource>
67
+ </resource>
68
+
69
+ </description>
@@ -0,0 +1,177 @@
1
+ # This file is part of CPEE-EVAL-RUBY.
2
+ #
3
+ # CPEE-EVAL-RUBY is free software: you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as published by the
5
+ # Free Software Foundation, either version 3 of the License, or (at your
6
+ # option) any later version.
7
+ #
8
+ # CPEE-EVAL-RUBY is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11
+ # for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public License
14
+ # along with CPEE-EVAL-RUBY (file LICENSE in the main directory). If not,
15
+ # see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'json'
18
+ require 'yaml'
19
+ require 'xml/smart'
20
+ require 'riddl/client'
21
+
22
+ module CPEE
23
+ module EvalRuby
24
+ module Translation
25
+
26
+ class ParamArray < ::Array
27
+ def value(index)
28
+ tmp = find_all{|e| e['name'] == index}
29
+ case tmp.length
30
+ when 0; nil
31
+ when 1; tmp[0]['data']
32
+ else tmp
33
+ end if tmp
34
+ end
35
+ end
36
+
37
+ def self::simplify_structurized_result(result)
38
+ if result && result.length == 1
39
+ if result[0].has_key? 'mimetype'
40
+ if result[0]['mimetype'] == 'application/json'
41
+ result = JSON::parse(result[0]['data']) rescue nil
42
+ elsif result[0]['mimetype'] == 'text/csv'
43
+ result = result[0]['data']
44
+ elsif result[0]['mimetype'] == 'text/yaml'
45
+ result = YAML::load(result[0]['data']) rescue nil
46
+ elsif result[0]['mimetype'] == 'application/xml' || result[0].mimetype == 'text/xml'
47
+ result = XML::Smart::string(result[0]['data']) rescue nil
48
+ elsif result[0]['mimetype'] == 'text/plain'
49
+ result = result[0]['data']
50
+ if result.start_with?("<?xml version=")
51
+ result = XML::Smart::string(result)
52
+ else
53
+ result = result.to_f if result == result.to_f.to_s
54
+ result = result.to_i if result == result.to_i.to_s
55
+ end
56
+ elsif result[0].mimetype == 'text/html'
57
+ result = result[0]['data']
58
+ result = result.to_f if result == result.to_f.to_s
59
+ result = result.to_i if result == result.to_i.to_s
60
+ else
61
+ result = result[0]
62
+ end
63
+ else
64
+ result = result[0]['data']
65
+ end
66
+ else
67
+ result = ParamArray[*result]
68
+ end
69
+ if result.is_a? String
70
+ enc = CPEE::EvalRuby::Translation::detect_encoding(result)
71
+ enc == 'OTHER' ? result : (result.encode('UTF-8',enc) rescue CPEE::EvalRuby::Translation::convert_to_base64(result))
72
+ else
73
+ result
74
+ end
75
+ end
76
+
77
+ def self::simplify_result(result)
78
+ if result.length == 1
79
+ if result[0].is_a? Riddl::Parameter::Simple
80
+ result = result[0].value
81
+ elsif result[0].is_a? Riddl::Parameter::Complex
82
+ if result[0].mimetype == 'application/json'
83
+ result = JSON::parse(result[0].value.read) rescue nil
84
+ elsif result[0].mimetype == 'text/csv'
85
+ result = result[0].value.read
86
+ elsif result[0].mimetype == 'text/yaml'
87
+ result = YAML::load(result[0].value.read) rescue nil
88
+ elsif result[0].mimetype == 'application/xml' || result[0].mimetype == 'text/xml'
89
+ result = XML::Smart::string(result[0].value.read) rescue nil
90
+ elsif result[0].mimetype == 'text/plain'
91
+ result = result[0].value.read
92
+ if result.start_with?("<?xml version=")
93
+ result = XML::Smart::string(result)
94
+ else
95
+ result = result.to_f if result == result.to_f.to_s
96
+ result = result.to_i if result == result.to_i.to_s
97
+ end
98
+ elsif result[0].mimetype == 'text/html'
99
+ result = result[0].value.read
100
+ result = result.to_f if result == result.to_f.to_s
101
+ result = result.to_i if result == result.to_i.to_s
102
+ else
103
+ result = result[0]
104
+ end
105
+ end
106
+ else
107
+ result = Riddl::Parameter::Array[*result]
108
+ end
109
+ if result.is_a? String
110
+ enc = CPEE::EvalRuby::Translation::detect_encoding(result)
111
+ enc == 'OTHER' ? result : (result.encode('UTF-8',enc) rescue CPEE::EvalRuby::Translation::convert_to_base64(result))
112
+ else
113
+ result
114
+ end
115
+ end
116
+
117
+ def self::detect_encoding(text)
118
+ if text.is_a? String
119
+ if text.valid_encoding? && text.encoding.name == 'UTF-8'
120
+ 'UTF-8'
121
+ else
122
+ res = CharlockHolmes::EncodingDetector.detect(text)
123
+ if res.is_a?(Hash) && res[:type] == :text && res[:ruby_encoding] != "binary"
124
+ res[:encoding]
125
+ elsif res.is_a?(Hash) && res[:type] == :binary
126
+ 'BINARY'
127
+ else
128
+ 'ISO-8859-1'
129
+ end
130
+ end
131
+ else
132
+ 'OTHER'
133
+ end
134
+ end
135
+
136
+ def self::convert_to_base64(text)
137
+ ('data:' + MimeMagic.by_magic(text).type + ';base64,' + Base64::encode64(text)) rescue ('data:application/octet-stream;base64,' + Base64::encode64(text))
138
+ end
139
+
140
+ def self::structurize_result(result)
141
+ result.map do |r|
142
+ if r.is_a? Riddl::Parameter::Simple
143
+ { 'name' => r.name, 'data' => r.value }
144
+ elsif r.is_a? Riddl::Parameter::Complex
145
+ res = if r.mimetype == 'application/json'
146
+ ttt = r.value.read
147
+ enc = CPEE::EvalRuby::Translation::detect_encoding(ttt)
148
+ enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue CPEE::EvalRuby::Translation::convert_to_base64(ttt))
149
+ elsif r.mimetype == 'text/csv'
150
+ ttt = r.value.read
151
+ enc = CPEE::EvalRuby::Translation::detect_encoding(ttt)
152
+ enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue CPEE::EvalRuby::Translation::convert_to_base64(ttt))
153
+ elsif r.mimetype == 'text/plain' || r.mimetype == 'text/html'
154
+ ttt = r.value.read
155
+ ttt = ttt.to_f if ttt == ttt.to_f.to_s
156
+ ttt = ttt.to_i if ttt == ttt.to_i.to_s
157
+ enc = CPEE::EvalRuby::Translation::detect_encoding(ttt)
158
+ enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue CPEE::EvalRuby::Translation::convert_to_base64(ttt))
159
+ else
160
+ CPEE::EvalRuby::Translation::convert_to_base64(r.value.read)
161
+ end
162
+
163
+ tmp = {
164
+ 'name' => r.name == '' ? 'result' : r.name,
165
+ 'mimetype' => r.mimetype,
166
+ 'data' => res.to_s
167
+ }
168
+ r.value.rewind
169
+ tmp
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+ end
176
+ end
177
+
data/server/eval-ruby ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # This file is part of CPEE-EVAL-RUBY.
4
+ #
5
+ # CPEE-INSTANTIATION is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the Free
7
+ # Software Foundation, either version 3 of the License, or (at your option) any
8
+ # later version.
9
+ #
10
+ # CPEE-EVAL-RUBY is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13
+ # details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # CPEE-EVAL-RUBY (file LICENSE in the main directory). If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ require 'rubygems'
20
+ require_relative './lib/implementation'
21
+
22
+ options = {
23
+ :host => 'localhost',
24
+ :port => 9302,
25
+ :secure => false
26
+ }
27
+
28
+ Riddl::Server.new(CPEE::EvalRuby::SERVER, options) do
29
+ accessible_description true
30
+ cross_site_xhr true
31
+
32
+ use CPEE::EvalRuby::implementation(@riddl_opts)
33
+ end.loop!
data/server/output.err ADDED
File without changes
data/server/output.txt ADDED
File without changes
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # This file is part of CPEE-EVAL-RUBY`.
4
+ #
5
+ # CPEE-EVAL-RUBY is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the Free
7
+ # Software Foundation, either version 3 of the License, or (at your option) any
8
+ # later version.
9
+ #
10
+ # CPEE-EVAL-RUBY is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
+ # more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along with
16
+ # CPEE-EVAL-RUBY (file LICENSE in the main directory). If not, see
17
+ # <http://www.gnu.org/licenses/>.
18
+
19
+ curpath = __dir__
20
+ require 'rubygems'
21
+ require 'optparse'
22
+ require 'fileutils'
23
+ require 'xml/smart'
24
+
25
+ def wrap(s, width=78, indent=18)
26
+ lines = []
27
+ line, s = s[0..indent-2], s[indent..-1]
28
+ s.split(/\n/).each do |ss|
29
+ ss.split(/[ \t]+/).each do |word|
30
+ if line.size + word.size >= width
31
+ lines << line
32
+ line = (" " * (indent)) + word
33
+ else
34
+ line << " " << word
35
+ end
36
+ end
37
+ lines << line if line
38
+ line = (" " * (indent-1))
39
+ end
40
+ return lines.join "\n"
41
+ end
42
+
43
+ ARGV.options { |opt|
44
+ opt.summary_indent = ' ' * 2
45
+ opt.summary_width = 15
46
+ opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} [options] new DIR\n"
47
+ opt.on("Options:")
48
+ opt.on("--help", "-h", "This text") { puts opt; exit }
49
+ opt.on("")
50
+ opt.on(wrap("[new DIR] scaffolds a sample eval ruby service. Send a request to it, see modifications to data elements and endpoints."))
51
+ opt.parse!
52
+ }
53
+ if (ARGV.length < 2) ||
54
+ (ARGV.length == 2 && !(%w(new).include?(ARGV[0]))) ||
55
+ (ARGV.length > 2)
56
+ puts ARGV.options
57
+ exit
58
+ end
59
+ command = ARGV[0]
60
+ p1 = ARGV[1]
61
+
62
+ if command == 'new'
63
+ insta = "#{curpath}/../server/"
64
+ if !File.exist?(p1)
65
+ FileUtils.cp_r(insta,p1)
66
+ else
67
+ FileUtils.cp_r(Dir.glob(File.join(insta,'*')).delete_if{|e| e =~ /\.conf/ },p1,remove_destination: true)
68
+ puts 'Directory already exists, updating ...'
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cpee-eval-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juergen eTM Mangler
8
+ autorequire:
9
+ bindir: tools
10
+ cert_chain: []
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riddl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: see http://cpee.org
28
+ email: juergen.mangler@gmail.com
29
+ executables:
30
+ - cpee-eval-ruby
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - README.md
34
+ files:
35
+ - AUTHORS
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - cpee-eval-ruby.gemspec
40
+ - lib/cpee-eval-ruby/implementation.rb
41
+ - lib/cpee-eval-ruby/implementation.xml
42
+ - lib/cpee-eval-ruby/translation.rb
43
+ - server/eval-ruby
44
+ - server/output.err
45
+ - server/output.txt
46
+ - tools/cpee-eval-ruby
47
+ homepage: http://cpee.org/
48
+ licenses:
49
+ - LGPL-3.0-or-later
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.4.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.5.11
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Ruby eval for the cloud process execution engine (cpee.org)
70
+ test_files: []