rubysdk 0.0.1.pre4 → 0.0.1.pre5

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: 2c5b85676563dc95d387185bb11fd5bd0fc5163b0e949b12c8b78a29d2f2898c
4
- data.tar.gz: 8619a87faf820cb985ff248d4e7193a98b5e35f5665e5671c99acef27130898a
3
+ metadata.gz: 8a1f3ca13463948e53df0160b0564d0e94db8cdce16b49a9d0981f4c8f7b40b4
4
+ data.tar.gz: bcd44d408657979cb8124d73b0d08abe5b13d7c684ff76f43676c43fc630262c
5
5
  SHA512:
6
- metadata.gz: 1f0e97d3f0941169e631303f5a1cb8f694af62052ef1aba3c757a6ff1ebe030e9bed78a775471fb9326d05471d4921a2708bd10afa7ba5f1521bcf78e0ac9838
7
- data.tar.gz: 26fc56efd112c540c0452d015b91f12007d92f8290ca72aea588c1a9f0ad70ae566a6d941bf36cb73e059e88d33831e0fcaff3811605eb8b1ab75d1b5d288884
6
+ metadata.gz: d66e79ad9faadac21dcc94eee9955e24049bbb9cee038c0f926cbc7441533f6fa73778c24e1da6df16d476ab373030f52cc229e8d225a0bff227ba71f339aff6
7
+ data.tar.gz: a6dc88a4a699520f455b2b10b3a5a3cb3781679d385ebe9ec0e38eb9f89bdef619d5a0fcbd240b11522ad808c6c8517c4c2663410b7450088123f56f5e6aaf42
@@ -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(handler=nil, title="", desc="", dependson=[], args=[], interaction=nil)
8
- @handler = handler
9
- @title = title
10
- @desc = desc
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(desc="", type=nil, key="", value="")
21
- @desc = desc
22
- @type = type
23
- @key = key
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(desc="", type=nil, value="")
32
- @desc = desc
33
- @type = type
34
- @value = value
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(handler=nil, job=nil)
42
- @handler = handler
43
- @job = job
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
- # GetJobs returns all registered jobs.
20
- def GetJobs(empty)
21
- @cached_jobs.each { |job| yield job.job }
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
- # ExecuteJob executes the given job and returns a result.
25
- def ExecuteJob(job)
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
- #dup_map = {}
123
+ dup_map = {}
122
124
  cached_jobs.each do |job|
123
- dup_map[job.job.unique_id] = (map[job.job.unique_id] || 0) + 1
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
- #health_svc = GRPC::Health::Checker.new
142
- #health_svc.add_status("plugin", GRPC::Core::StatusCodes::SERVING)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre4
4
+ version: 0.0.1.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Vocks