@@ -558,8 +558,8 @@ def render_template(name)
558
558
#
559
559
# @todo danielp 2013-06-26: this should be some sort of discovery, not a
560
560
# hand-coded list, but ... it will do, for now.
561
- COLLECTIONS = [ :brokers , :repos , :tags , :policies ,
562
- [ :nodes , { 'start' => { "type" => "number" } , 'limit' => { "type" => "number" } } ] , :tasks , :commands ,
561
+ COLLECTIONS = [ :brokers , :repos , :tags , :policies , [ :nodes , { 'start' => { "type" => "number" } , 'limit' => { "type" => "number" } } ] ,
562
+ :tasks , :commands ,
563
563
[ :events , { 'start' => { "type" => "number" } , 'limit' => { "type" => "number" } } ] , :hooks ]
564
564
565
565
#
@@ -692,8 +692,7 @@ def render_template(name)
692
692
end
693
693
694
694
get '/api/collections/commands' do
695
- collection_view Razor ::Data ::Command . order ( :submitted_at ) . reverse ,
696
- 'commands'
695
+ collection_view Razor ::Data ::Command . order ( :submitted_at ) . order ( :id ) , 'commands'
697
696
end
698
697
699
698
get '/api/collections/commands/:id' do
@@ -708,47 +707,73 @@ def render_template(name)
708
707
end
709
708
710
709
get '/api/collections/events' do
711
- check_permissions! ( "query:events" )
710
+ limit = params [ :limit ]
711
+ start = params [ :start ]
712
+
713
+ raise TypeError , _ ( 'limit must be a number, but was %{limit}' ) %
714
+ { limit : limit } unless limit . to_i . to_s == limit or limit . nil?
715
+ raise TypeError , _ ( 'start must be a number, but was %{start}' ) %
716
+ { start : start } unless start . to_i . to_s == start or start . nil?
717
+ limit = Integer ( limit ) if limit
718
+ start = Integer ( start ) if start
712
719
713
720
# Need to also order by ID here in case the granularity of timestamp is
714
721
# not enough to maintain a consistent ordering.
715
- cursor = Razor ::Data ::Event . order ( :timestamp ) . order ( :id ) . reverse
716
- collection_view cursor , 'events' , limit : params [ : limit] , start : params [ : start]
722
+ cursor = Razor ::Data ::Event . order ( :timestamp ) . order ( :id )
723
+ collection_view cursor , 'events' , limit : limit , start : start , facts : true
717
724
end
718
725
719
726
get '/api/collections/events/:id' do
720
727
params [ :id ] =~ /[0-9]+/ or error 400 , :error => _ ( "id must be a number but was %{id}" ) % { id : params [ :id ] }
721
- check_permissions! ( "query:events: #{ params [ :id ] } " )
728
+
722
729
event = Razor ::Data ::Event [ :id => params [ :id ] ] or
723
730
error 404 , :error => _ ( "no event matched id=%{id}" ) % { id : params [ :id ] }
724
731
event_hash ( event ) . to_json
725
732
end
726
733
727
734
get '/api/collections/hooks' do
728
- check_permissions! ( "query:hooks" )
729
-
730
735
collection_view Razor ::Data ::Hook , 'hooks'
731
736
end
732
737
733
738
get '/api/collections/hooks/:name' do
734
- check_permissions! ( "query:hooks:#{ params [ :name ] } " )
735
739
hook = Razor ::Data ::Hook [ :name => params [ :name ] ] or
736
740
error 404 , :error => _ ( "no hook matched name=%{name}" ) % { name : params [ :name ] }
737
741
hook_hash ( hook ) . to_json
738
742
end
739
743
740
744
get '/api/collections/hooks/:name/log' do
741
- check_permissions! ( "query:hooks:#{ params [ :name ] } " )
745
+ check_permissions! ( "query:hooks:#{ params [ :name ] } :log" )
746
+ limit = params [ :limit ]
747
+ start = params [ :start ]
748
+
749
+ raise TypeError , _ ( 'limit must be a number, but was %{limit}' ) %
750
+ { limit : limit } unless limit . to_i . to_s == limit or limit . nil?
751
+ raise TypeError , _ ( 'start must be a number, but was %{start}' ) %
752
+ { start : start } unless start . to_i . to_s == start or start . nil?
753
+ limit = Integer ( limit ) if limit
754
+ start = Integer ( start ) if start
755
+
742
756
hook = Razor ::Data ::Hook [ :name => params [ :name ] ] or
743
757
error 404 , :error => _ ( "no hook matched name=%{name}" ) % { name : params [ :name ] }
744
758
{
745
759
"spec" => spec_url ( "collections" , "hooks" , "log" ) ,
746
- "items" => hook . log ( limit : params [ : limit] , start : params [ : start] )
760
+ "items" => hook . log ( limit : limit , start : start )
747
761
} . to_json
748
762
end
749
763
750
764
get '/api/collections/nodes' do
751
- collection_view Razor ::Data ::Node . search ( params ) . order ( :id ) , 'nodes' , limit : params [ :limit ] , start : params [ :start ]
765
+ limit = params [ :limit ]
766
+ start = params [ :start ]
767
+
768
+ raise TypeError , _ ( 'limit must be a number, but was %{limit}' ) %
769
+ { limit : limit } unless limit . to_i . to_s == limit or limit . nil?
770
+ raise TypeError , _ ( 'start must be a number, but was %{start}' ) %
771
+ { start : start } unless start . to_i . to_s == start or start . nil?
772
+ limit = Integer ( limit ) if limit
773
+ start = Integer ( start ) if start
774
+
775
+ collection_view Razor ::Data ::Node . search ( params ) . order ( :id ) , 'nodes' ,
776
+ limit : limit , start : start
752
777
end
753
778
754
779
get '/api/collections/nodes/:name' do
@@ -760,6 +785,16 @@ def render_template(name)
760
785
get '/api/collections/nodes/:name/log' do
761
786
check_permissions! ( "query:nodes:#{ params [ :name ] } :log" )
762
787
788
+ limit = params [ :limit ]
789
+ start = params [ :start ]
790
+
791
+ raise TypeError , _ ( 'limit must be a number, but was %{limit}' ) %
792
+ { limit : limit } unless limit . to_i . to_s == limit or limit . nil?
793
+ raise TypeError , _ ( 'start must be a number, but was %{start}' ) %
794
+ { start : start } unless start . to_i . to_s == start or start . nil?
795
+ limit = Integer ( limit ) if limit
796
+ start = Integer ( start ) if start
797
+
763
798
# @todo lutter 2013-08-20: There are no tests for this handler
764
799
# @todo lutter 2013-08-20: Do we need to send the log through a view ?
765
800
node = Razor ::Data ::Node [ :name => params [ :name ] ] or
@@ -769,7 +804,7 @@ def render_template(name)
769
804
# view worthwhile without extra querying.
770
805
{
771
806
"spec" => spec_url ( "collections" , "nodes" , "log" ) ,
772
- "items" => node . log ( limit : params [ : limit] , start : params [ : start] )
807
+ "items" => node . log ( limit : limit , start : start )
773
808
} . to_json
774
809
end
775
810
0 commit comments