Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
41eef88b
Commit
41eef88b
authored
Mar 08, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exposing watchers to API
parent
7fc0daa4
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
85 additions
and
3 deletions
+85
-3
app.rb
lib/noah/app.rb
+1
-1
application_routes.rb
lib/noah/application_routes.rb
+8
-0
configuration_routes.rb
lib/noah/configuration_routes.rb
+8
-0
ephemeral_routes.rb
lib/noah/ephemeral_routes.rb
+4
-0
host_routes.rb
lib/noah/host_routes.rb
+8
-0
watchers.rb
lib/noah/models/watchers.rb
+1
-1
service_routes.rb
lib/noah/service_routes.rb
+8
-0
version.rb
lib/noah/version.rb
+1
-1
watcher_routes.rb
lib/noah/watcher_routes.rb
+12
-0
em-hiredis-0.0.1.gem
lib/vendor/em-hiredis/em-hiredis-0.0.1.gem
+0
-0
noahapp_watcher_spec.rb
spec/noahapp_watcher_spec.rb
+34
-0
No files found.
lib/noah/app.rb
View file @
41eef88b
...
...
@@ -62,7 +62,7 @@ module Noah
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'service_routes.rb'
)
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'application_routes.rb'
)
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'configuration_routes.rb'
)
#
load File.join(File.dirname(__FILE__), 'watcher_routes.rb')
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'watcher_routes.rb'
)
#load File.joint(File.dirname(__FILE__), 'ephemeral_routes.rb')
end
...
...
lib/noah/application_routes.rb
View file @
41eef88b
...
...
@@ -19,6 +19,14 @@ class Noah::App
end
end
put
'/a/:appname/watch'
do
|
appname
|
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
a
=
Noah
::
Application
.
find
(:
name
=>
appname
).
first
)
:
(
raise
"Missing Parameters"
)
a
.
nil?
?
(
halt
404
)
:
(
w
=
a
.
watch!
(
:endpoint
=>
data
[
'endpoint'
]))
w
.
to_json
end
put
'/a/:appname/?'
do
|
appname
|
required_params
=
[
"name"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
lib/noah/configuration_routes.rb
View file @
41eef88b
...
...
@@ -38,6 +38,14 @@ class Noah::App
end
end
put
'/c/:configname/watch'
do
|
configname
|
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
c
=
Noah
::
Configuration
.
find
(:
name
=>
configname
).
first
)
:
(
raise
"Missing Parameters"
)
c
.
nil?
?
(
halt
404
)
:
(
w
=
c
.
watch!
(
:endpoint
=>
data
[
'endpoint'
]))
w
.
to_json
end
put
'/c/:appname/:element?'
do
|
appname
,
element
|
app
=
Noah
::
Application
.
find_or_create
(
:name
=>
appname
)
config
=
Noah
::
Configuration
.
find_or_create
(
:name
=>
element
,
:application_id
=>
app
.
id
)
...
...
lib/noah/ephemeral_routes.rb
View file @
41eef88b
...
...
@@ -5,6 +5,10 @@ class Noah::App
# Eventually I'll move to root path
end
put
'/e/*/watch'
do
# Logic for adding watches to ephemerals
end
put
'/e/*'
do
# Some logic for creating ephemerals
end
...
...
lib/noah/host_routes.rb
View file @
41eef88b
...
...
@@ -33,6 +33,14 @@ class Noah::App
end
end
put
'/h/:hostname/watch'
do
|
hostname
|
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
h
=
Noah
::
Host
.
find
(:
name
=>
hostname
).
first
)
:
(
raise
"Missing Parameters"
)
h
.
nil?
?
(
halt
404
)
:
(
w
=
h
.
watch!
(
:endpoint
=>
data
[
'endpoint'
]))
w
.
to_json
end
put
'/h/:hostname/?'
do
|
hostname
|
required_params
=
[
"name"
,
"status"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
lib/noah/models/watchers.rb
View file @
41eef88b
...
...
@@ -25,7 +25,7 @@ module Noah
end
def
to_hash
h
=
{
:pattern
=>
pattern
,
:endpoint
=>
endpoint
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
}
h
=
{
:pattern
=>
pattern
,
:
name
=>
name
,
:
endpoint
=>
endpoint
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
}
super
.
merge
(
h
)
end
...
...
lib/noah/service_routes.rb
View file @
41eef88b
...
...
@@ -30,6 +30,14 @@ class Noah::App
end
end
put
'/s/:servicename/watch'
do
|
servicename
|
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
s
=
Noah
::
Service
.
find
(:
name
=>
servicename
).
first
)
:
(
raise
"Missing Parameters"
)
s
.
nil?
?
(
halt
404
)
:
(
w
=
s
.
watch!
(
:endpoint
=>
data
[
'endpoint'
]))
w
.
to_json
end
put
'/s/:servicename/?'
do
|
servicename
|
required_params
=
[
"status"
,
"host"
,
"name"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
...
...
lib/noah/version.rb
View file @
41eef88b
module
Noah
VERSION
=
"0.0.
7
"
VERSION
=
"0.0.
9
"
end
lib/noah/watcher_routes.rb
0 → 100644
View file @
41eef88b
class
Noah
::
App
get
'/w/?'
do
w
=
Noah
::
Watcher
.
all
.
sort_by
(
:pattern
)
if
w
.
size
==
0
halt
404
else
w
.
to_json
end
end
end
lib/vendor/em-hiredis/em-hiredis-0.0.1.gem
0 → 100644
View file @
41eef88b
File added
spec/noahapp_watcher_spec.rb
0 → 100644
View file @
41eef88b
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Watcher API"
,
:reset_redis
=>
true
do
before
(
:each
)
do
endpoint
=
'http://localhost:4567/webhook'
Ohm
.
redis
.
flushdb
a
=
Noah
::
Application
.
create
:name
=>
'fooapp'
a
.
watch!
:endpoint
=>
endpoint
c
=
Noah
::
Configuration
.
create
:name
=>
'fooconfig'
c
.
watch!
:endpoint
=>
endpoint
h
=
Noah
::
Host
.
create
:name
=>
'localhost'
,
:status
=>
'up'
h
.
watch!
:endpoint
=>
endpoint
s
=
Noah
::
Service
.
create
:name
=>
'localhostservice'
,
:status
=>
'up'
,
:host
=>
h
s
.
watch!
:endpoint
=>
endpoint
end
after
(
:all
)
do
Ohm
.
redis
.
flushdb
end
describe
"calling"
do
describe
"GET"
do
it
"all watches should work"
do
get
'/w'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
is_a?
(
Array
).
should
==
true
response
.
size
.
should
==
4
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment