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
41913163
Commit
41913163
authored
Mar 18, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor routes (minus ephemerals) to match patterns
parent
88e0d993
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
108 additions
and
108 deletions
+108
-108
noah.rb
lib/noah.rb
+1
-1
application_routes.rb
lib/noah/application_routes.rb
+6
-6
configuration_routes.rb
lib/noah/configuration_routes.rb
+6
-6
host_routes.rb
lib/noah/host_routes.rb
+6
-6
service_routes.rb
lib/noah/service_routes.rb
+6
-6
watcher_routes.rb
lib/noah/watcher_routes.rb
+4
-4
noahapp_application_spec.rb
spec/noahapp_application_spec.rb
+10
-10
noahapp_configuration_spec.rb
spec/noahapp_configuration_spec.rb
+12
-12
noahapp_host_spec.rb
spec/noahapp_host_spec.rb
+10
-10
noahapp_service_spec.rb
spec/noahapp_service_spec.rb
+12
-12
noahapp_watcher_spec.rb
spec/noahapp_watcher_spec.rb
+20
-20
index.haml
views/index.haml
+15
-15
No files found.
lib/noah.rb
View file @
41913163
module
Noah
PROTECTED_PATHS
=
%w[a
c h s w
]
PROTECTED_PATHS
=
%w[a
pplications configurations hosts services watches
]
end
begin
require
'yajl'
...
...
lib/noah/application_routes.rb
View file @
41913163
class
Noah
::
App
# Application URIs
get
'/a/:appname/:config/?'
do
|
appname
,
config
|
get
'/a
pplications
/:appname/:config/?'
do
|
appname
,
config
|
app
=
Noah
::
Application
.
find
(
:name
=>
appname
).
first
if
app
.
nil?
halt
404
...
...
@@ -10,7 +10,7 @@ class Noah::App
end
end
get
'/a/:appname/?'
do
|
appname
|
get
'/a
pplications
/:appname/?'
do
|
appname
|
app
=
Noah
::
Application
.
find
(
:name
=>
appname
).
first
if
app
.
nil?
halt
404
...
...
@@ -19,7 +19,7 @@ class Noah::App
end
end
put
'/a/:appname/watch'
do
|
appname
|
put
'/a
pplications
/: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"
)
...
...
@@ -27,7 +27,7 @@ class Noah::App
w
.
to_json
end
put
'/a/:appname/?'
do
|
appname
|
put
'/a
pplications
/:appname/?'
do
|
appname
|
required_params
=
[
"name"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
if
data
.
keys
.
sort
==
required_params
.
sort
&&
data
[
'name'
]
==
appname
...
...
@@ -45,7 +45,7 @@ class Noah::App
end
end
delete
'/a/:appname/?'
do
|
appname
|
delete
'/a
pplications
/:appname/?'
do
|
appname
|
app
=
Noah
::
Application
.
find
(
:name
=>
appname
).
first
if
app
.
nil?
halt
404
...
...
@@ -58,7 +58,7 @@ class Noah::App
end
end
get
'/a/?'
do
get
'/a
pplications
/?'
do
apps
=
[]
Noah
::
Application
.
all
.
sort
.
each
{
|
a
|
apps
<<
a
.
to_hash
}
if
apps
.
empty?
...
...
lib/noah/configuration_routes.rb
View file @
41913163
...
...
@@ -6,7 +6,7 @@ class Noah::App
:string
=>
"text/plain"
}
# Configuration URIs
get
'/c/:appname/:element/?'
do
|
appname
,
element
|
get
'/c
onfigurations
/:appname/:element/?'
do
|
appname
,
element
|
a
=
Noah
::
Application
.
find
(
:name
=>
appname
).
first
if
a
.
nil?
halt
404
...
...
@@ -17,7 +17,7 @@ class Noah::App
end
end
get
'/c/:appname/?'
do
|
appname
|
get
'/c
onfigurations
/:appname/?'
do
|
appname
|
config
=
[]
a
=
Noah
::
Application
.
find
(
:name
=>
appname
).
first
if
a
.
nil?
...
...
@@ -28,7 +28,7 @@ class Noah::App
end
end
get
'/c/?'
do
get
'/c
onfigurations
/?'
do
configs
=
[]
Noah
::
Configuration
.
all
.
sort
.
each
{
|
c
|
configs
<<
c
.
to_hash
}
if
configs
.
empty?
...
...
@@ -38,7 +38,7 @@ class Noah::App
end
end
put
'/c/:configname/watch'
do
|
configname
|
put
'/c
onfigurations
/: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"
)
...
...
@@ -46,7 +46,7 @@ class Noah::App
w
.
to_json
end
put
'/c/:appname/:element?'
do
|
appname
,
element
|
put
'/c
onfigurations
/: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
)
required_params
=
[
"format"
,
"body"
]
...
...
@@ -63,7 +63,7 @@ class Noah::App
end
end
delete
'/c/:appname/:element?'
do
|
appname
,
element
|
delete
'/c
onfigurations
/:appname/:element?'
do
|
appname
,
element
|
app
=
Noah
::
Application
.
find
(
:name
=>
appname
).
first
if
app
config
=
Noah
::
Configuration
.
find
(
:name
=>
element
,
:application_id
=>
app
.
id
).
first
...
...
lib/noah/host_routes.rb
View file @
41913163
...
...
@@ -2,7 +2,7 @@ class Noah::App
# Host URIs
# GET named {Service} for named {Host}
get
'/h/:hostname/:servicename/?'
do
|
hostname
,
servicename
|
get
'/h
osts
/:hostname/:servicename/?'
do
|
hostname
,
servicename
|
h
=
host_service
(
hostname
,
servicename
)
if
h
.
nil?
halt
404
...
...
@@ -14,7 +14,7 @@ class Noah::App
# GET named {Host}
# @param :hostname name of {Host}
# @return [JSON] representation of {Host}
get
'/h/:hostname/?'
do
|
hostname
|
get
'/h
osts
/:hostname/?'
do
|
hostname
|
h
=
host
(
:name
=>
hostname
)
if
h
.
nil?
halt
404
...
...
@@ -24,7 +24,7 @@ class Noah::App
end
# GET all {Hosts}
get
'/h/?'
do
get
'/h
osts
/?'
do
hosts
.
map
{
|
h
|
h
.
to_hash
}
if
hosts
.
size
==
0
halt
404
...
...
@@ -33,7 +33,7 @@ class Noah::App
end
end
put
'/h/:hostname/watch'
do
|
hostname
|
put
'/h
osts
/: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"
)
...
...
@@ -41,7 +41,7 @@ class Noah::App
w
.
to_json
end
put
'/h/:hostname/?'
do
|
hostname
|
put
'/h
osts
/:hostname/?'
do
|
hostname
|
required_params
=
[
"name"
,
"status"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
&&
data
[
'name'
]
==
hostname
)
?
(
host
=
Noah
::
Host
.
find_or_create
(:
name
=>
data
[
'name'
],
:status
=>
data
[
'status'
]))
:
(
raise
"Missing Parameters"
)
...
...
@@ -53,7 +53,7 @@ class Noah::App
end
end
delete
'/h/:hostname/?'
do
|
hostname
|
delete
'/h
osts
/:hostname/?'
do
|
hostname
|
host
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
if
host
services
=
[]
...
...
lib/noah/service_routes.rb
View file @
41913163
...
...
@@ -2,7 +2,7 @@ class Noah::App
# Service URIs
# get named {Service} for named {Host}
get
'/s/:servicename/:hostname/?'
do
|
servicename
,
hostname
|
get
'/s
ervices
/:servicename/:hostname/?'
do
|
servicename
,
hostname
|
hs
=
host_service
(
hostname
,
servicename
)
if
hs
.
nil?
halt
404
...
...
@@ -11,7 +11,7 @@ class Noah::App
end
end
get
'/s/:servicename/?'
do
|
servicename
|
get
'/s
ervices
/:servicename/?'
do
|
servicename
|
s
=
services
(
:name
=>
servicename
)
s
.
map
{
|
x
|
x
.
to_hash
}
if
s
.
empty?
...
...
@@ -21,7 +21,7 @@ class Noah::App
end
end
get
'/s/?'
do
get
'/s
ervices
/?'
do
if
services
.
empty?
halt
404
else
...
...
@@ -30,7 +30,7 @@ class Noah::App
end
end
put
'/s/:servicename/watch'
do
|
servicename
|
put
'/s
ervices
/: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"
)
...
...
@@ -38,7 +38,7 @@ class Noah::App
w
.
to_json
end
put
'/s/:servicename/?'
do
|
servicename
|
put
'/s
ervices
/:servicename/?'
do
|
servicename
|
required_params
=
[
"status"
,
"host"
,
"name"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
if
data
.
keys
.
sort
==
required_params
.
sort
...
...
@@ -57,7 +57,7 @@ class Noah::App
end
end
delete
'/s/:servicename/:hostname/?'
do
|
servicename
,
hostname
|
delete
'/s
ervices
/:servicename/:hostname/?'
do
|
servicename
,
hostname
|
host
=
Noah
::
Host
.
find
(
:name
=>
hostname
).
first
||
(
halt
404
)
service
=
Noah
::
Service
.
find
(
:name
=>
servicename
,
:host_id
=>
host
.
id
).
first
||
(
halt
404
)
if
host
&&
service
...
...
lib/noah/watcher_routes.rb
View file @
41913163
class
Noah
::
App
get
'/w/:name'
do
|
name
|
get
'/w
atches
/:name'
do
|
name
|
w
=
Noah
::
Watcher
.
find_by_name
(
name
)
w
.
nil?
?
(
halt
404
)
:
w
.
to_json
end
get
'/w/?'
do
get
'/w
atches
/?'
do
w
=
Noah
::
Watcher
.
all
.
sort_by
(
:pattern
)
if
w
.
size
==
0
halt
404
...
...
@@ -14,7 +14,7 @@ class Noah::App
end
end
put
'/w/?'
do
put
'/w
atches
/?'
do
required_params
=
%w[endpoint pattern]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
pattern
,
endpoint
=
data
[
'pattern'
],
data
[
'endpoint'
])
:
(
raise
"Missing Parameters"
)
...
...
@@ -28,7 +28,7 @@ class Noah::App
end
end
delete
'/w/?'
do
delete
'/w
atches
/?'
do
required_params
=
%w[endpoint pattern]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
pattern
,
endpoint
=
data
[
'pattern'
],
data
[
'endpoint'
])
:
(
raise
"Missing Parameters"
)
...
...
spec/noahapp_application_spec.rb
View file @
41913163
...
...
@@ -11,13 +11,13 @@ describe "Using the Application API", :reset_redis => false do
describe
"GET"
do
it
"all applications should work"
do
get
'/a'
get
'/a
pplications
'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
is_a?
(
Array
).
should
==
true
end
it
"named application should work"
do
get
'/a/rspec_sample_app'
get
'/a
pplications
/rspec_sample_app'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -30,7 +30,7 @@ describe "Using the Application API", :reset_redis => false do
c
[
"format"
].
should
==
@c
.
format
end
it
"named configuration for application should work"
do
get
"/a/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
get
"/a
pplications
/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -41,11 +41,11 @@ describe "Using the Application API", :reset_redis => false do
response
[
"application"
].
should
==
@a
.
name
end
it
"invalid application should not work"
do
get
"/a/should_not_exist"
get
"/a
pplications
/should_not_exist"
last_response
.
should
be_missing
end
it
"invalid configuration for application should not work"
do
get
"/a/should_not_exist/should_not_exist"
get
"/a
pplications
/should_not_exist/should_not_exist"
last_response
.
should
be_missing
end
end
...
...
@@ -55,7 +55,7 @@ describe "Using the Application API", :reset_redis => false do
@appdata
=
{
:name
=>
"should_now_exist"
}
end
it
"new application should work"
do
put
"/a/
#{
@appdata
[
:name
]
}
"
,
@appdata
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/a
pplications
/
#{
@appdata
[
:name
]
}
"
,
@appdata
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -66,13 +66,13 @@ describe "Using the Application API", :reset_redis => false do
Noah
::
Application
.
find
(
:name
=>
@appdata
[
:name
]).
first
.
is_new?
.
should
==
true
end
it
"new application with missing name should not work"
do
put
"/a/should_not_work"
,
'{"foo":"bar"}'
,
"CONTENT_TYPE"
=>
"application/json"
put
"/a
pplications
/should_not_work"
,
'{"foo":"bar"}'
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"existing application should work"
do
sleep
3
put
"/a/
#{
@appdata
[
:name
]
}
"
,
@appdata
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/a
pplications
/
#{
@appdata
[
:name
]
}
"
,
@appdata
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -89,7 +89,7 @@ describe "Using the Application API", :reset_redis => false do
@appdata
=
{
:name
=>
"should_now_exist"
}
end
it
"existing application should work"
do
delete
"/a/
#{
@appdata
[
:name
]
}
"
delete
"/a
pplications
/
#{
@appdata
[
:name
]
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -99,7 +99,7 @@ describe "Using the Application API", :reset_redis => false do
response
[
"configurations"
].
should
==
"0"
end
it
"invalid application should not work"
do
delete
"/a/should_not_work"
delete
"/a
pplications
/should_not_work"
last_response
.
should
be_missing
end
end
...
...
spec/noahapp_configuration_spec.rb
View file @
41913163
...
...
@@ -5,12 +5,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe
"GET"
do
it
"all configurations should work"
do
get
'/c'
get
'/c
onfigurations
'
last_response
.
should
be_ok
last_response
.
should
return_json
end
it
"named application should work"
do
get
'/c/noah'
get
'/c
onfigurations
/noah'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -21,14 +21,14 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response
.
first
[
"application"
].
should
==
"noah"
end
it
"named configuration for application should work"
do
get
'/c/noah/redis'
get
'/c
onfigurations
/noah/redis'
last_response
.
should
be_ok
response
=
last_response
.
body
response
.
should
==
"redis://127.0.0.1:6379/0"
end
it
"named configuration should work with mime-type"
do
require
'yaml'
get
'/c/myrailsapp1/database.yml'
get
'/c
onfigurations
/myrailsapp1/database.yml'
last_response
.
should
be_ok
last_response
.
headers
[
"Content-Type"
].
should
==
"text/x-yaml;charset=utf-8"
response
=
YAML
.
load
(
last_response
.
body
)
...
...
@@ -38,11 +38,11 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response
[
"development"
].
values
.
sort
.
should
==
[
"dev_password"
,
"dev_user"
,
"development_database"
,
"mysql"
]
end
it
"invalid application should not work"
do
get
'/c/badapp'
get
'/c
onfigurations
/badapp'
last_response
.
should
be_missing
end
it
"invalid configuration for application should not work"
do
get
'/c/badapp/badconfig'
get
'/c
onfigurations
/badapp/badconfig'
last_response
.
should
be_missing
end
end
...
...
@@ -50,7 +50,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe
"PUT"
do
it
"new configuration should work"
do
config_data
=
{
:format
=>
"string"
,
:body
=>
"sample_config_entry"
}.
to_json
put
'/c/newapp/newconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/c
onfigurations
/newapp/newconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -62,7 +62,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
it
"existing configuration should work"
do
config_data
=
{
:format
=>
"string"
,
:body
=>
"sample_config_entry"
}.
to_json
sleep
3
put
'/c/newapp/newconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/c
onfigurations
/newapp/newconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -73,12 +73,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
end
it
"new configuration with missing format should not work"
do
config_data
=
{
:body
=>
"a string"
}.
to_json
put
'/c/newnewapp/someconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/c
onfigurations
/newnewapp/someconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"new configuration with missing body should not work"
do
config_data
=
{
:body
=>
"a string"
}.
to_json
put
'/c/newnewapp/someconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/c
onfigurations
/newnewapp/someconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
end
...
...
@@ -93,7 +93,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
end
it
"existing configuration should work"
do
delete
"/c/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
delete
"/c
onfigurations
/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -103,7 +103,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response
[
"item"
].
should
==
@c
.
name
end
it
"invalid configuration should not work"
do
delete
"/c/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
delete
"/c
onfigurations
/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
last_response
.
should
be_missing
end
end
...
...
spec/noahapp_host_spec.rb
View file @
41913163
...
...
@@ -5,13 +5,13 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
describe
"GET"
do
it
"all hosts should work"
do
get
'/h'
get
'/h
osts
'
last_response
.
should
be_ok
last_response
.
should
return_json
end
it
"existing host should work"
do
get
'/h/localhost'
get
'/h
osts
/localhost'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -29,7 +29,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
it
"named service for host should work"
do
get
'/h/localhost/noah'
get
'/h
osts
/localhost/noah'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -42,7 +42,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
describe
"PUT"
do
it
"new host should work"
do
host_data
=
{
:name
=>
"host99.domain.com"
,
:status
=>
"down"
}.
to_json
put
'/h/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/h
osts
/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -56,7 +56,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
it
"existing host should work"
do
sleep
3
host_data
=
{
:name
=>
"host99.domain.com"
,
:status
=>
"pending"
}.
to_json
put
'/h/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/h
osts
/host99.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -65,19 +65,19 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
it
"host missing name parameter should not work"
do
host_data
=
{
:status
=>
"pending"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/h
osts
/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"host missing status parameter should not work"
do
host_data
=
{
:name
=>
"host100.domain.com"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/h
osts
/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"host with invalid status parameter should not work"
do
host_data
=
{
:name
=>
"host100.domain.com"
,
:status
=>
"fscked"
}.
to_json
put
'/h/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
put
'/h
osts
/host100.domain.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -96,7 +96,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
it
"existing host should work"
do
svc_size
=
@h
.
services
.
size
delete
"/h/
#{
@h
.
name
}
"
delete
"/h
osts
/
#{
@h
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -107,7 +107,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
it
"invalid host should not work"
do
delete
"/h/
#{
@h
.
name
}
"
delete
"/h
osts
/
#{
@h
.
name
}
"
last_response
.
should
be_missing
end
end
...
...
spec/noahapp_service_spec.rb
View file @
41913163
...
...
@@ -13,13 +13,13 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
describe
"GET"
do
it
"all services should work"
do
get
'/s'
get
'/s
ervices
'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
is_a?
(
Array
).
should
==
true
end
it
"all named services should work"
do
get
"/s/
#{
@sample_service
[
:name
]
}
"
get
"/s
ervices
/
#{
@sample_service
[
:name
]
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
is_a?
(
Array
).
should
==
true
...
...
@@ -30,7 +30,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
s
[
"host"
].
should
==
@h
.
name
end
it
"named service for host should work"
do
get
"/s/
#{
@sample_service
[
:name
]
}
/
#{
@sample_host
[
:name
]
}
"
get
"/s
ervices
/
#{
@sample_service
[
:name
]
}
/
#{
@sample_host
[
:name
]
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"id"
].
should
==
@s
.
id
...
...
@@ -39,7 +39,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
response
[
"host"
].
should
==
@h
.
name
end
it
"missing service for host should not work"
do
get
'/s/foobar/baz'
get
'/s
ervices
/foobar/baz'
last_response
.
should
be_missing
end
end
...
...
@@ -49,7 +49,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
@payload
=
{
:name
=>
'another_rspec_service'
,
:status
=>
'up'
,
:host
=>
@h
.
name
}
end
it
"new service should work"
do
put
"/s/
#{
@payload
[
:name
]
}
/"
,
@payload
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/s
ervices
/
#{
@payload
[
:name
]
}
/"
,
@payload
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -61,26 +61,26 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
Noah
::
Service
.
find
(
:name
=>
@payload
[
:name
]).
first
.
is_new?
.
should
==
true
end
it
"new service without host should not work"
do
put
"/s/foobar"
,
{
:name
=>
"foobar"
,
:status
=>
"up"
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/s
ervices
/foobar"
,
{
:name
=>
"foobar"
,
:status
=>
"up"
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"new service with invalid status should not work"
do
put
"/s/foobar"
,
{
:name
=>
"foobar"
,
:status
=>
"fsck"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/s
ervices
/foobar"
,
{
:name
=>
"foobar"
,
:status
=>
"fsck"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"error_message"
].
should
==
"Status must be up, down or pending"
end
it
"new service with missing name should not work"
do
put
"/s/foobar"
,
{
:status
=>
"fsck"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/s
ervices
/foobar"
,
{
:status
=>
"fsck"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"new service with missing status should not work"
do
put
"/s/foobar"
,
{
:name
=>
"foobar"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/s
ervices
/foobar"
,
{
:name
=>
"foobar"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"existing service should work"
do
sleep
3
put
"/s/
#{
@payload
[
:name
]
}
"
,
{
:name
=>
@payload
[
:name
],
:status
=>
"down"
,
:host
=>
@payload
[
:host
]}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
"/s
ervices
/
#{
@payload
[
:name
]
}
"
,
{
:name
=>
@payload
[
:name
],
:status
=>
"down"
,
:host
=>
@payload
[
:host
]}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
...
...
@@ -101,7 +101,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
@s
=
@h
.
services
.
first
end
it
"existing host should work"
do
delete
"/s/
#{
@s
.
name
}
/
#{
@h
.
name
}
"
delete
"/s
ervices
/
#{
@s
.
name
}
/
#{
@h
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
...
...
@@ -112,7 +112,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
response
[
"service"
].
should
==
@s
.
name
end
it
"invalid host should not work"
do
delete
"/s/
#{
@s
.
name
}
/
#{
@h
.
name
}
"
delete
"/s
ervices
/
#{
@s
.
name
}
/
#{
@h
.
name
}
"
last_response
.
should
be_missing
end
end
...
...
spec/noahapp_watcher_spec.rb
View file @
41913163
...
...
@@ -22,7 +22,7 @@ describe "Using the Watcher API", :reset_redis => true do
describe
"GET"
do
it
"all watches should work"
do
get
'/w'
get
'/w
atches
'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
is_a?
(
Array
).
should
==
true
...
...
@@ -30,8 +30,8 @@ describe "Using the Watcher API", :reset_redis => true do
end
it
"named watch should work"
do
w
=
Noah
::
Watcher
.
create
(
:pattern
=>
'//noah/application/myapp'
,
:endpoint
=>
'http://localhost/webhook'
)
get
"/w/
#{
w
.
name
}
"
w
=
Noah
::
Watcher
.
create
(
:pattern
=>
'//noah/application/myapp'
,
:endpoint
=>
'http://localhost/w
atchers
ebhook'
)
get
"/w
atches
/
#{
w
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
'pattern'
].
should
==
w
.
pattern
...
...
@@ -39,15 +39,15 @@ describe "Using the Watcher API", :reset_redis => true do
end
it
"invalid watch should not work"
do
get
'/w/asdfasdfasdfasdfasdfsdf'
get
'/w
atches
/asdfasdfasdfasdfasdfsdf'
last_response
.
should
be_missing
end
end
describe
"PUT"
do
it
"new watch should work"
do
data
=
{
:pattern
=>
"//noah/application"
,
:endpoint
=>
"http://myendpoint/webhook"
}
put
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
data
=
{
:pattern
=>
"//noah/application"
,
:endpoint
=>
"http://myendpoint/w
atchers
ebhook"
}
put
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
'pattern'
].
should
==
data
[
:pattern
]
...
...
@@ -58,30 +58,30 @@ describe "Using the Watcher API", :reset_redis => true do
end
it
"new watch without pattern should not work"
do
data
=
{
:endpoint
=>
"http://myendpoint/webhook"
}
put
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
data
=
{
:endpoint
=>
"http://myendpoint/w
atchers
ebhook"
}
put
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"new watch without endpoint should not work"
do
data
=
{
:pattern
=>
"//noah/application"
}
put
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
put
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"new watch that supercedes existing should not work"
do
Noah
::
Watcher
.
create
(
:endpoint
=>
'http://myendpoint/webhook'
,
:pattern
=>
'//noah/application/foo'
)
data
=
{
:endpoint
=>
"http://myendpoint/webhook"
,
:pattern
=>
'//noah/application'
}
put
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
Noah
::
Watcher
.
create
(
:endpoint
=>
'http://myendpoint/w
atchers
ebhook'
,
:pattern
=>
'//noah/application/foo'
)
data
=
{
:endpoint
=>
"http://myendpoint/w
atchers
ebhook"
,
:pattern
=>
'//noah/application'
}
put
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
'error_message'
].
should
==
'Pattern would overwrite existing'
end
it
"new watch that subsets an existing should not work"
do
Noah
::
Watcher
.
create
(
:endpoint
=>
'http://myendpoint/webhook'
,
:pattern
=>
'//noah/application'
)
data
=
{
:endpoint
=>
"http://myendpoint/webhook"
,
:pattern
=>
'//noah/application/foo'
}
put
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
Noah
::
Watcher
.
create
(
:endpoint
=>
'http://myendpoint/w
atchers
ebhook'
,
:pattern
=>
'//noah/application'
)
data
=
{
:endpoint
=>
"http://myendpoint/w
atchers
ebhook"
,
:pattern
=>
'//noah/application/foo'
}
put
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
'error_message'
].
should
==
'Pattern is already provided'
...
...
@@ -90,9 +90,9 @@ describe "Using the Watcher API", :reset_redis => true do
describe
"DELETE"
do
it
"delete an existing watch should work"
do
data
=
{
:endpoint
=>
"http://myendpoint/webhookd"
,
:pattern
=>
'//noah/application/d'
}
data
=
{
:endpoint
=>
"http://myendpoint/w
atchers
ebhookd"
,
:pattern
=>
'//noah/application/d'
}
w
=
Noah
::
Watcher
.
create
(
data
)
delete
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
delete
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
'pattern'
].
should
==
data
[
:pattern
]
...
...
@@ -103,19 +103,19 @@ describe "Using the Watcher API", :reset_redis => true do
it
"delete an invalid watch should not work"
do
data
=
{
:endpoint
=>
'missing'
,
:pattern
=>
'//noah/application/dag'
}
delete
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
delete
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_missing
end
it
"delete without pattern should not work"
do
data
=
{
:endpoint
=>
"invalid"
}
delete
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
delete
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
it
"delete without endpoint should not work"
do
data
=
{
:pattern
=>
"//noah/invalid"
}
delete
'/w'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
delete
'/w
atches
'
,
data
.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_invalid
end
end
...
...
views/index.haml
View file @
41913163
...
...
@@ -14,42 +14,42 @@
%h2
Hosts
%ul
%li
%a
{
:href
=>
"h/"
}
All registered Hosts
%a
{
:href
=>
"h
osts
/"
}
All registered Hosts
%li
%a
{
:href
=>
"h/localhost"
}
localhost (this server)
%a
{
:href
=>
"h
osts
/localhost"
}
localhost (this server)
%li
%a
{
:href
=>
"h/localhost/noah"
}
localhost noah service
%a
{
:href
=>
"h
osts
/localhost/noah"
}
localhost noah service
#header
%h2
Services
%ul
%li
%a
{
:href
=>
"s/"
}
All registered Services
%a
{
:href
=>
"s
ervices
/"
}
All registered Services
%li
%a
{
:href
=>
"s/http"
}
All hosts providing 'http'
%a
{
:href
=>
"s
ervices
/http"
}
All hosts providing 'http'
%li
%a
{
:href
=>
"s/noah/localhost"
}
localhost noah service
%a
{
:href
=>
"s
ervices
/noah/localhost"
}
localhost noah service
#header
%h2
Applications
%ul
%li
%a
{
:href
=>
"a/"
}
All registered Applications
%a
{
:href
=>
"a
pplications
/"
}
All registered Applications
%li
%a
{
:href
=>
"a/noah"
}
Noah Application entry
%a
{
:href
=>
"a
pplications
/noah"
}
Noah Application entry
%li
%a
{
:href
=>
"a/noah/redis"
}
Noah Redis configuration entry
%a
{
:href
=>
"a
pplications
/noah/redis"
}
Noah Redis configuration entry
#header
%h2
Configurations
%ul
%li
%a
{
:href
=>
"c/"
}
All registered Configurations
%a
{
:href
=>
"c
onfigurations
/"
}
All registered Configurations
%li
%a
{
:href
=>
"c/noah"
}
Noah Configuration entry
%a
{
:href
=>
"c
onfigurations
/noah"
}
Noah Configuration entry
%li
%a
{
:href
=>
"c/myrailsapp1"
}
myrailsapp1 Configuration entry
%a
{
:href
=>
"c
onfigurations
/myrailsapp1"
}
myrailsapp1 Configuration entry
%li
%a
{
:href
=>
"c/myrestapp1"
}
myrestapp1 Configuration entry
%a
{
:href
=>
"c
onfigurations
/myrestapp1"
}
myrestapp1 Configuration entry
%li
%a
{
:href
=>
"c/myrailsapp1/database.yml"
}
database.yml file for myrailsapp1 (should return the proper content-type)
%a
{
:href
=>
"c
onfigurations
/myrailsapp1/database.yml"
}
database.yml file for myrailsapp1 (should return the proper content-type)
%li
%a
{
:href
=>
"c/myrestapp1/config.json"
}
config.json file for myrestapp1
%a
{
:href
=>
"c
onfigurations
/myrestapp1/config.json"
}
config.json file for myrestapp1
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