rubysdk 0.0.1.pre4 → 0.0.1.pre5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/interface/interface.rb +16 -19
- data/lib/rubysdk.rb +20 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a1f3ca13463948e53df0160b0564d0e94db8cdce16b49a9d0981f4c8f7b40b4
|
4
|
+
data.tar.gz: bcd44d408657979cb8124d73b0d08abe5b13d7c684ff76f43676c43fc630262c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66e79ad9faadac21dcc94eee9955e24049bbb9cee038c0f926cbc7441533f6fa73778c24e1da6df16d476ab373030f52cc229e8d225a0bff227ba71f339aff6
|
7
|
+
data.tar.gz: a6dc88a4a699520f455b2b10b3a5a3cb3781679d385ebe9ec0e38eb9f89bdef619d5a0fcbd240b11522ad808c6c8517c4c2663410b7450088123f56f5e6aaf42
|
data/lib/interface/interface.rb
CHANGED
@@ -4,43 +4,40 @@ module Interface
|
|
4
4
|
class Job
|
5
5
|
attr_accessor :handler, :title, :desc, :dependson, :args, :interaction
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@dependson = dependson
|
12
|
-
@args = args
|
13
|
-
@interaction = interaction
|
7
|
+
def initialize(params)
|
8
|
+
params.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value)
|
10
|
+
end
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
17
14
|
class Argument
|
18
15
|
attr_accessor :desc, :type, :key, :value
|
19
16
|
|
20
|
-
def initialize(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@value = value
|
17
|
+
def initialize(params)
|
18
|
+
params.each do |key, value|
|
19
|
+
instance_variable_set("@#{key}", value)
|
20
|
+
end
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
24
|
class ManualInteraction
|
29
25
|
attr_accessor :desc, :type, :value
|
30
26
|
|
31
|
-
def initialize(
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
def initialize(params)
|
28
|
+
params.each do |key, value|
|
29
|
+
instance_variable_set("@#{key}", value)
|
30
|
+
end
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
34
|
class JobsWrapper
|
39
35
|
attr_accessor :handler, :job
|
40
36
|
|
41
|
-
def initialize(
|
42
|
-
|
43
|
-
|
37
|
+
def initialize(params)
|
38
|
+
params.each do |key, value|
|
39
|
+
instance_variable_set("@#{key}", value)
|
40
|
+
end
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
data/lib/rubysdk.rb
CHANGED
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift(proto_dir) unless $LOAD_PATH.include?(proto_dir)
|
|
5
5
|
$LOAD_PATH.unshift(interface_dir) unless $LOAD_PATH.include?(interface_dir)
|
6
6
|
|
7
7
|
require 'grpc'
|
8
|
+
require 'grpc/health/checker'
|
8
9
|
require 'fnv'
|
9
10
|
require 'plugin_services_pb'
|
10
11
|
require 'interface'
|
@@ -16,13 +17,15 @@ module RubySDK
|
|
16
17
|
@cached_jobs = cached_jobs
|
17
18
|
end
|
18
19
|
|
19
|
-
#
|
20
|
-
def
|
21
|
-
|
20
|
+
# get_jobs returns all registered jobs.
|
21
|
+
def get_jobs(empty, _call)
|
22
|
+
jobs = []
|
23
|
+
@cached_jobs.each { |job| jobs.push job.job }
|
24
|
+
jobs.each
|
22
25
|
end
|
23
26
|
|
24
|
-
#
|
25
|
-
def
|
27
|
+
# execute_job executes the given job and returns a result.
|
28
|
+
def execute_job(job, _call)
|
26
29
|
cjob = nil
|
27
30
|
@cached_jobs.each do |cached_job|
|
28
31
|
cjob = cached_job unless cached_job.unique_id == job.unique_id
|
@@ -112,15 +115,14 @@ module RubySDK
|
|
112
115
|
end
|
113
116
|
|
114
117
|
# Create wrapper object
|
115
|
-
wrapper_job = Interface::JobsWrapper.new(handler: job.handler,
|
116
|
-
job: proto_job)
|
118
|
+
wrapper_job = Interface::JobsWrapper.new(handler: job.handler, job: proto_job)
|
117
119
|
cached_jobs.push wrapper_job
|
118
120
|
end
|
119
121
|
|
120
122
|
# Check if two jobs have the same title which is restricted.
|
121
|
-
|
123
|
+
dup_map = {}
|
122
124
|
cached_jobs.each do |job|
|
123
|
-
dup_map[job.job.unique_id] = (
|
125
|
+
dup_map[job.job.unique_id] = (dup_map[job.job.unique_id] || 0) + 1
|
124
126
|
|
125
127
|
if dup_map[job.job.unique_id] > 1
|
126
128
|
raise "duplicate job with the title #{job.title} found which is not allowed"
|
@@ -132,14 +134,19 @@ module RubySDK
|
|
132
134
|
key_path = ENV["GAIA_PLUGIN_KEY"]
|
133
135
|
root_ca_path = ENV["GAIA_PLUGIN_CA_CERT"]
|
134
136
|
|
137
|
+
# Check if variable is empty.
|
138
|
+
raise "GAIA_PLUGIN_CERT not set" unless cert_path
|
139
|
+
raise "GAIA_PLUGIN_KEY not set" unless key_path
|
140
|
+
raise "GAIA_PLUGIN_CA_CERT not set" unless root_ca_path
|
141
|
+
|
135
142
|
# Check if all certs are available.
|
136
143
|
raise "cannot find path to certificate" unless File.file?(cert_path)
|
137
144
|
raise "cannot find path to key" unless File.file?(key_path)
|
138
145
|
raise "cannot find path to root CA certificate" unless File.file?(root_ca_path)
|
139
146
|
|
140
147
|
# Implement health service.
|
141
|
-
|
142
|
-
|
148
|
+
health_svc = Grpc::Health::Checker.new
|
149
|
+
health_svc.add_status("plugin", Grpc::Health::V1::HealthCheckResponse::ServingStatus::SERVING)
|
143
150
|
|
144
151
|
# Load certificates and create credentials.
|
145
152
|
credentials = GRPC::Core::ServerCredentials.new(
|
@@ -156,10 +163,12 @@ module RubySDK
|
|
156
163
|
s = GRPC::RpcServer.new
|
157
164
|
port = s.add_http2_port(host+':0', credentials)
|
158
165
|
s.handle(GRPCServer.new(cached_jobs))
|
166
|
+
s.handle(health_svc)
|
159
167
|
|
160
168
|
# Output the address and service name to stdout.
|
161
169
|
# hashicorp go-plugin will use that to establish a connection.
|
162
170
|
puts "1|2|tcp|#{host}:#{port}|grpc"
|
171
|
+
GRPC.logger.info("1|2|tcp|#{host}:#{port}|grpc")
|
163
172
|
STDOUT.sync = true
|
164
173
|
|
165
174
|
s.run_till_terminated
|