ocular 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ocular/dsl/dsl.rb +4 -0
- data/lib/ocular/dsl/etcd.rb +28 -0
- data/lib/ocular/dsl/runcontext.rb +2 -0
- data/lib/ocular/event/eventbase.rb +22 -10
- data/lib/ocular/event/eventfactory.rb +2 -0
- data/lib/ocular/inputs/http_input.rb +36 -17
- data/lib/ocular/ocular.rb +1 -3
- data/lib/ocular/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba3d7f05bc363f6bde68a3499ac349554297e908
|
4
|
+
data.tar.gz: 4b9e52b2e61dbf40f3af58357086bb9bafe6c1db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73554edcfac13aee2be802f97d04357b795940ec552fefcae627a5fb8488148b608df5c187e6b06aaee8d8895a153f99c6f0a8023622711aca5458454689b5c
|
7
|
+
data.tar.gz: 4c2eb3ca28d08d38057963cf0b0da384f4f020f7feeafade71c0edd7fe0bae85df6d113cdf89fd618eec0f7e5313a9615beb578dc38213dc4076926ad22b91cb
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'etcd'
|
3
|
+
|
4
|
+
class Ocular
|
5
|
+
module DSL
|
6
|
+
module Etcd
|
7
|
+
@@__etcd_instance = nil
|
8
|
+
|
9
|
+
def etcd()
|
10
|
+
if @@__etcd_instance
|
11
|
+
return @@__etcd_instance
|
12
|
+
end
|
13
|
+
|
14
|
+
settings = ::Ocular::Settings::get(:inputs)[:etcd] || {}
|
15
|
+
@@__etcd_instance = ::Etcd.client(
|
16
|
+
host: (settings[:host] || "localhost"),
|
17
|
+
port: (settings[:port] || 2379),
|
18
|
+
usern_name: (settings[:port] || nil),
|
19
|
+
password: (settings[:port] || nil),
|
20
|
+
)
|
21
|
+
|
22
|
+
return @@__etcd_instance
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -35,13 +35,8 @@ class Ocular
|
|
35
35
|
r = Results.new
|
36
36
|
|
37
37
|
begin
|
38
|
-
|
39
|
-
|
40
|
-
# This check is to make sure that whatever we return that it can be serialised
|
41
|
-
if String === retval or Array === retval
|
42
|
-
r.response = retval
|
43
|
-
end
|
44
|
-
|
38
|
+
r.response = __call(context, @callback)
|
39
|
+
#r.response = context.instance_eval(&@callback)
|
45
40
|
rescue Exception => error
|
46
41
|
r.error = error
|
47
42
|
end
|
@@ -49,12 +44,15 @@ class Ocular
|
|
49
44
|
response_data = Marshal.dump(r)
|
50
45
|
writer.puts(response_data)
|
51
46
|
writer.close
|
47
|
+
|
52
48
|
end
|
53
49
|
writer.close
|
54
50
|
|
55
|
-
|
56
|
-
r = Marshal.load(
|
51
|
+
data = reader.read
|
52
|
+
r = Marshal.load(data)
|
57
53
|
reader.close
|
54
|
+
Process.wait(child_pid)
|
55
|
+
|
58
56
|
|
59
57
|
if r.error
|
60
58
|
raise r.error
|
@@ -63,7 +61,21 @@ class Ocular
|
|
63
61
|
end
|
64
62
|
|
65
63
|
def exec_nofork(context)
|
66
|
-
return context
|
64
|
+
return __call(context, @callback)
|
65
|
+
#context.instance_eval(&@callback)
|
66
|
+
end
|
67
|
+
|
68
|
+
def __call(context, callback)
|
69
|
+
# we use this trickery to workaround the LocalJumpError so that we can use return
|
70
|
+
context.define_singleton_method(:_, &callback)
|
71
|
+
p = context.method(:_).to_proc
|
72
|
+
|
73
|
+
reply = p.call()
|
74
|
+
if context.respond_to?(:exec_wrapper)
|
75
|
+
return context.exec_wrapper(reply)
|
76
|
+
else
|
77
|
+
return reply
|
78
|
+
end
|
67
79
|
end
|
68
80
|
|
69
81
|
end
|
@@ -5,6 +5,7 @@ require 'rack/protection'
|
|
5
5
|
require 'uri'
|
6
6
|
|
7
7
|
require 'ocular/inputs/base.rb'
|
8
|
+
require 'ocular/dsl/dsl.rb'
|
8
9
|
require 'ocular/dsl/runcontext.rb'
|
9
10
|
|
10
11
|
# Some of this code is copied from the excellent Sinatra Ruby web library by
|
@@ -40,6 +41,27 @@ class Ocular
|
|
40
41
|
|
41
42
|
class WebRunContext < ::Ocular::DSL::RunContext
|
42
43
|
attr_accessor :request, :response, :params, :env
|
44
|
+
|
45
|
+
def initialize()
|
46
|
+
super()
|
47
|
+
@headers = {}
|
48
|
+
end
|
49
|
+
|
50
|
+
def content_type(type)
|
51
|
+
@headers["Content-Type"] = type
|
52
|
+
end
|
53
|
+
|
54
|
+
def exec_wrapper(res)
|
55
|
+
if Fixnum === res
|
56
|
+
res = [res, @headers, nil]
|
57
|
+
end
|
58
|
+
|
59
|
+
if String === res
|
60
|
+
res = [200, @headers, res]
|
61
|
+
end
|
62
|
+
|
63
|
+
return res
|
64
|
+
end
|
43
65
|
end
|
44
66
|
|
45
67
|
|
@@ -258,7 +280,6 @@ class Ocular
|
|
258
280
|
end
|
259
281
|
end
|
260
282
|
|
261
|
-
|
262
283
|
def safe_ignore(ignore)
|
263
284
|
unsafe_ignore = []
|
264
285
|
ignore = ignore.gsub(/%[\da-fA-F]{2}/) do |hex|
|
@@ -388,6 +409,20 @@ class Ocular
|
|
388
409
|
end
|
389
410
|
ensure
|
390
411
|
|
412
|
+
end
|
413
|
+
|
414
|
+
def invoke(context)
|
415
|
+
res = catch(:halt) { yield(context) }
|
416
|
+
|
417
|
+
if Array === res and Fixnum === res.first
|
418
|
+
res = res.dup
|
419
|
+
status(context, res.shift)
|
420
|
+
body(context, res.pop)
|
421
|
+
headers(context, *res)
|
422
|
+
elsif res.respond_to? :each
|
423
|
+
body(context, res)
|
424
|
+
end
|
425
|
+
nil # avoid double setting the same response tuple twice
|
391
426
|
end
|
392
427
|
|
393
428
|
def handle_exception!(context, error)
|
@@ -400,7 +435,6 @@ class Ocular
|
|
400
435
|
puts "Internal Server Error: #{error}"
|
401
436
|
puts error.backtrace
|
402
437
|
end
|
403
|
-
|
404
438
|
end
|
405
439
|
|
406
440
|
def call_block(context)
|
@@ -443,21 +477,6 @@ class Ocular
|
|
443
477
|
@params = original if original
|
444
478
|
end
|
445
479
|
|
446
|
-
def invoke(context)
|
447
|
-
res = catch(:halt) { yield(context) }
|
448
|
-
|
449
|
-
res = [res] if Fixnum === res or String === res
|
450
|
-
if Array === res and Fixnum === res.first
|
451
|
-
res = res.dup
|
452
|
-
status(context, res.shift)
|
453
|
-
body(context, res.pop)
|
454
|
-
headers(context, *res)
|
455
|
-
elsif res.respond_to? :each
|
456
|
-
body(context, res)
|
457
|
-
end
|
458
|
-
nil # avoid double setting the same response tuple twice
|
459
|
-
end
|
460
|
-
|
461
480
|
# Creates a Hash with indifferent access.
|
462
481
|
def indifferent_hash
|
463
482
|
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
data/lib/ocular/ocular.rb
CHANGED
@@ -3,9 +3,7 @@ require 'ocular/version'
|
|
3
3
|
require 'ocular/settings'
|
4
4
|
require 'ocular/event/eventbase'
|
5
5
|
require 'ocular/event/eventfactory'
|
6
|
-
require 'ocular/dsl/
|
7
|
-
require 'ocular/dsl/fog'
|
8
|
-
require 'ocular/dsl/ssh'
|
6
|
+
require 'ocular/dsl/dsl'
|
9
7
|
require 'ocular/dsl/runcontext'
|
10
8
|
require 'ocular/inputs/handlers'
|
11
9
|
require 'ocular/inputs/base'
|
data/lib/ocular/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juho Mäkinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rye
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.9.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: etcd
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.3.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.3.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +142,8 @@ files:
|
|
128
142
|
- lib/blocktest.rb
|
129
143
|
- lib/ocular.rb
|
130
144
|
- lib/ocular/daemon.rb
|
145
|
+
- lib/ocular/dsl/dsl.rb
|
146
|
+
- lib/ocular/dsl/etcd.rb
|
131
147
|
- lib/ocular/dsl/fog.rb
|
132
148
|
- lib/ocular/dsl/logging.rb
|
133
149
|
- lib/ocular/dsl/runcontext.rb
|