ocular 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ocular +6 -3
- data/lib/ocular/daemon.rb +1 -0
- data/lib/ocular/dsl/dsl.rb +1 -0
- data/lib/ocular/dsl/etcd.rb +8 -3
- data/lib/ocular/dsl/mysql.rb +28 -0
- data/lib/ocular/dsl/runcontext.rb +1 -0
- data/lib/ocular/event/eventbase.rb +1 -2
- data/lib/ocular/event/eventfactory.rb +2 -0
- data/lib/ocular/inputs/cron_input.rb +0 -1
- data/lib/ocular/inputs/handlers.rb +2 -0
- data/lib/ocular/inputs/http_input.rb +40 -1
- data/lib/ocular/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b75a01c08fb7b6a2ff960807a32756141e464168
|
4
|
+
data.tar.gz: 37aaefaa23b2948b71e08ab2d9b1b3a869ddb68a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e88d5e11511d01257c91a8437435ef910c530b2fa18e8d4e2d60e26a5d444b4e567ccf1d59ba04b82ae490e39e5c95526ca17a1dff194b3dd6842854c5a38eff
|
7
|
+
data.tar.gz: cc915062ae0f0eac29ff93a3d9ea96b7ca1e9f25cfea0b757cc303fea89b126fae9703c9d5f718634ef596af7c4d2deae7f9fb2220b48e5272e2082626baf345
|
data/bin/ocular
CHANGED
@@ -24,7 +24,7 @@ class OptparseExample
|
|
24
24
|
options.settings = nil
|
25
25
|
options.root = nil
|
26
26
|
options.check = nil
|
27
|
-
options.level = "
|
27
|
+
options.level = "INFO"
|
28
28
|
|
29
29
|
opt_parser = OptionParser.new do |opts|
|
30
30
|
opts.banner = "Usage in shell mode: \"ocular [options] <script file>\" or server mode: \"ocular --server [options]\""
|
@@ -78,9 +78,10 @@ class OptparseExample
|
|
78
78
|
end # class OptparseExample
|
79
79
|
|
80
80
|
options = OptparseExample.parse(ARGV)
|
81
|
-
|
81
|
+
settings_file = nil
|
82
82
|
begin
|
83
|
-
Ocular::Settings.
|
83
|
+
settings_file = Ocular::Settings.find_settings_file_from_system(options.settings)
|
84
|
+
Ocular::Settings.load_from_file(settings_file)
|
84
85
|
rescue Errno::ENOENT
|
85
86
|
puts "Could not find #{options.settings} in any search path."
|
86
87
|
puts "Please create a yaml settings file in either ~/.ocular.yaml or /etc/ocular.yaml"
|
@@ -127,6 +128,8 @@ end
|
|
127
128
|
|
128
129
|
Ocular.set_global_logger(logger)
|
129
130
|
|
131
|
+
logger.debug("- Loaded ocular settings from #{settings_file}")
|
132
|
+
|
130
133
|
if options.server or options.syntax
|
131
134
|
if !options.root && !Ocular::Settings.get(:script_root)
|
132
135
|
puts "Please specify --root or set script_root in the settings.yaml"
|
data/lib/ocular/daemon.rb
CHANGED
data/lib/ocular/dsl/dsl.rb
CHANGED
data/lib/ocular/dsl/etcd.rb
CHANGED
@@ -13,12 +13,17 @@ class Ocular
|
|
13
13
|
return @@__etcd_instance
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
|
17
|
+
datasources = ::Ocular::Settings::get(:datasources)
|
18
|
+
if !datasources
|
19
|
+
raise "No etcd client settings"
|
20
|
+
end
|
21
|
+
settings = datasources[:etcd] || {}
|
17
22
|
@@__etcd_instance = ::Etcd.client(
|
18
23
|
host: (settings[:host] || "localhost"),
|
19
24
|
port: (settings[:port] || 2379),
|
20
|
-
|
21
|
-
password: (settings[:
|
25
|
+
user_name: (settings[:user_name] || nil),
|
26
|
+
password: (settings[:password] || nil),
|
22
27
|
)
|
23
28
|
|
24
29
|
return @@__etcd_instance
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'mysql2'
|
3
|
+
|
4
|
+
class Ocular
|
5
|
+
module DSL
|
6
|
+
module MySQL
|
7
|
+
|
8
|
+
add_help "mysql", "Returns a mysql client instance"
|
9
|
+
|
10
|
+
def mysql()
|
11
|
+
datasources = ::Ocular::Settings::get(:datasources)
|
12
|
+
if !datasources or !datasources[:mysql]
|
13
|
+
raise "No mysql client settings"
|
14
|
+
end
|
15
|
+
settings = datasources[:mysql] || {}
|
16
|
+
return Mysql2::Client.new(
|
17
|
+
host: (settings[:host] || "localhost"),
|
18
|
+
port: (settings[:port] || 3306),
|
19
|
+
username: (settings[:username] || nil),
|
20
|
+
password: (settings[:password] || nil),
|
21
|
+
database: (settings[:database] || "ocular")
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -24,8 +24,10 @@ class Ocular
|
|
24
24
|
include Ocular::DSL::SSH
|
25
25
|
include Ocular::DSL::Fog
|
26
26
|
include Ocular::DSL::Etcd
|
27
|
+
include Ocular::DSL::MySQL
|
27
28
|
|
28
29
|
include Ocular::Inputs::HTTP::DSL
|
30
|
+
include Ocular::Inputs::HTTP::ErrorDSL
|
29
31
|
include Ocular::Inputs::Cron::DSL
|
30
32
|
include Ocular::Inputs::Trigger::DSL
|
31
33
|
|
@@ -84,7 +84,6 @@ class Ocular
|
|
84
84
|
::Ocular.logger.debug "Scheduling cron.every(#{rule}) for block #{block}"
|
85
85
|
|
86
86
|
id = @handler.scheduler.every(rule, :overlap => false) do
|
87
|
-
puts "derp!"
|
88
87
|
context = ::Ocular::DSL::RunContext.new(@logger)
|
89
88
|
context.log_cause("cron.every", {:rule => rule})
|
90
89
|
eventbase.exec(context)
|
@@ -18,7 +18,6 @@ class Ocular
|
|
18
18
|
|
19
19
|
module DSL
|
20
20
|
|
21
|
-
|
22
21
|
def onGET(path, opts = {}, &block)
|
23
22
|
handler = handlers.get(::Ocular::Inputs::HTTP::Input)
|
24
23
|
handler.add_get(script_name, path, opts, self, &block)
|
@@ -35,13 +34,35 @@ class Ocular
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
37
|
+
module ErrorDSL
|
38
|
+
class ClientError < ::Exception
|
39
|
+
def initialize(status, message)
|
40
|
+
@status = status
|
41
|
+
@message = message
|
42
|
+
end
|
43
|
+
|
44
|
+
def http_status
|
45
|
+
puts "http_status called: #{@status}"
|
46
|
+
return @status
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
puts "to_s called: #{@message}"
|
51
|
+
return @message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
38
56
|
class Input < ::Ocular::Inputs::Base
|
39
57
|
|
40
58
|
attr_reader :routes
|
41
59
|
|
60
|
+
|
42
61
|
class WebRunContext < ::Ocular::DSL::RunContext
|
43
62
|
attr_accessor :request, :response, :params, :env
|
44
63
|
|
64
|
+
include ::Ocular::Inputs::HTTP::ErrorDSL
|
65
|
+
|
45
66
|
def initialize()
|
46
67
|
super(Ocular::Logging::ConsoleLogger.new)
|
47
68
|
@headers = {}
|
@@ -268,6 +289,8 @@ class Ocular
|
|
268
289
|
end
|
269
290
|
|
270
291
|
def route(verb, path, options, proxy, &block)
|
292
|
+
::Ocular.logger.debug("Binding #{verb} #{path} to block #{block}")
|
293
|
+
|
271
294
|
eventbase = Ocular::DSL::EventBase.new(proxy, &block)
|
272
295
|
(proxy.events[verb] ||= {})[path] = eventbase
|
273
296
|
|
@@ -369,6 +392,17 @@ class Ocular
|
|
369
392
|
end
|
370
393
|
end
|
371
394
|
|
395
|
+
def encoded(char)
|
396
|
+
enc = URI_INSTANCE.escape(char)
|
397
|
+
enc = "(?:#{escaped(char, enc).join('|')})" if enc == char
|
398
|
+
enc = "(?:#{enc}|#{encoded('+')})" if char == " "
|
399
|
+
enc
|
400
|
+
end
|
401
|
+
|
402
|
+
def escaped(char, enc = URI_INSTANCE.escape(char))
|
403
|
+
[Regexp.escape(enc), URI_INSTANCE.escape(char, /./)]
|
404
|
+
end
|
405
|
+
|
372
406
|
def call(env)
|
373
407
|
dup.call!(env)
|
374
408
|
end
|
@@ -413,6 +447,7 @@ class Ocular
|
|
413
447
|
invoke(context) do |context|
|
414
448
|
route!(context)
|
415
449
|
end
|
450
|
+
|
416
451
|
rescue ::Exception => error
|
417
452
|
invoke(context) do |context|
|
418
453
|
handle_exception!(context, error)
|
@@ -440,6 +475,10 @@ class Ocular
|
|
440
475
|
|
441
476
|
if error.respond_to? :http_status
|
442
477
|
context.response.status = error.http_status
|
478
|
+
|
479
|
+
if error.respond_to? :to_s
|
480
|
+
puts error.to_s
|
481
|
+
end
|
443
482
|
else
|
444
483
|
context.response.status = 500
|
445
484
|
puts "Internal Server Error: #{error}"
|
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.14
|
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-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rye
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 0.3.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mysql2
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.4.3
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.4.3
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rspec
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +188,7 @@ files:
|
|
174
188
|
- lib/ocular/dsl/etcd.rb
|
175
189
|
- lib/ocular/dsl/fog.rb
|
176
190
|
- lib/ocular/dsl/logging.rb
|
191
|
+
- lib/ocular/dsl/mysql.rb
|
177
192
|
- lib/ocular/dsl/orbit.rb
|
178
193
|
- lib/ocular/dsl/runcontext.rb
|
179
194
|
- lib/ocular/dsl/ssh.rb
|