Src C0 Coverage Information - RCov

configserver.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
configserver.rb 219 149
96.80%
95.30%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 #
2 #   Copyright [2011] [Red Hat, Inc.]
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #   http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #  limitations under the License.
15 #
16 require 'cgi'
17 require 'rubygems'
18 require 'sinatra'
19 
20 require 'lib/config_handler' # I don't like this name
21 require 'lib/application_helper'
22 
23 helpers ApplicationHelper
24 
25 configure :development do
26   enable :logging, :dump_errors
27   set :raise_errors, true
28 end
29 
30 configure :production do
31   enable :logging
32 end
33 
34 error 400 do
35   #FIXME: point the requestor to the relaxNG document used to parse the XML
36   # document.
37   #FIXME: show the requestor the set of errors that occured
38   "Could not parse the given XML document.\n"
39 end
40 
41 ## GET /version
42 # Retrieve the Application and API version for this config server
43 get '/version', :provides => ['text', 'xml'] do
44   logger.debug("Getting the version as text or XML")
45   "<config-server>\n" +
46   "  <application-version>#{app_version}</application-version>\n" +
47   "  <api-version>#{api_version}</api-version>\n" +
48   "</config-server>"
49 end
50 
51 get '/version' do
52   logger.debug("Getting the version as HTML")
53   "<html><body>\n" +
54   "<li>Application Version: #{app_version}</li>\n" +
55   "<li>API Version: #{api_version}<li/>\n" +
56   "</body></html>"
57 end
58 
59 # OAuth protected URLs
60 before '/configs/*' do
61   authenticate!
62 end
63 before '/params/*' do
64   authenticate!
65 end
66 before '/files/*' do
67   authenticate!
68 end
69 before '/auth*' do
70   authenticate!
71 end
72 
73 # Test OAuth
74 get '/auth' do
75   logger.debug("Client is testing auth credentials")
76   "Authentication test successful"
77 end
78 
79 #
80 # API Methods
81 #
82 
83 ## GET /ip/
84 # Retrieve the IP address for an instance that has reported its IP
85 get '/ip/:version/:uuid', :provides => ['text', 'html'] do
86   configs.exists?(params[:uuid]) ?
87     configs.get_ip(params[:uuid]) :
88     not_found
89 end
90 
91 ## GET /configs/
92 # Retrieve the configuration information for an instance
93 get '/configs/:version/:uuid', :provides => 'text' do
94   if not api_version_valid?(request, params[:version]) or
95       not configs.exists?(params[:uuid])
96     not_found
97   else
98     confs, more_configs = configs.get_configs(params[:uuid], :as => :text)
99     status = more_configs ? 202 : 200
100     [status, confs]
101   end
102 end
103 
104 get '/configs/:version/:uuid', :provides => 'xml' do
105   if not api_version_valid?(request, params[:version]) or
106       not configs.exists?(params[:uuid])
107     not_found
108   else
109     confs, more_configs = configs.get_configs(params[:uuid], :as => :xml)
110     status = more_configs ? 202 : 200
111     [status, confs]
112   end
113 end
114 
115 get '/configs/:version/:uuid' do
116   if not api_version_valid?(request, params[:version]) or
117       not configs.exists?(params[:uuid])
118     not_found
119   else
120     confs, more_configs = configs.get_configs(params[:uuid], :as => :xml)
121     status = more_configs ? 202 : 200
122     [status, confs]
123   end
124 end
125 
126 ## POST /configs/
127 # Create (or completely replace) the configuration data for an instance
128 post '/configs/:version/:uuid' do
129   # For now, we're not going to validate the version here
130   # The current XML validation should be enough for the moment
131   # Really handling version checking here will require a patch to conductor
132   #if not api_version_valid?(request, params[:version])
133     #not_found
134   #else
135     logger.debug("Post data: #{params[:data]}")
136     begin
137       configs.create(params[:uuid], params[:data])
138     rescue ConfigServer::Model::InvalidInstanceConfigError
139       400
140     end
141   #end
142 end
143 
144 ## DELETE /deployment/
145 # Permanently delete the configuration data for an entire deployment
146 #  - delete all instance configurations under that deployment
147 delete '/deployment/:version/:uuid' do
148   if not configs.deployment_exists?(params[:uuid])
149     not_found
150   else
151     configs.delete_deployment(params[:uuid])
152   end
153 end
154 
155 ## GET /files/
156 # Retrieve the configuration files for an instance
157 get '/files/:version/:uuid' do
158   if not api_version_valid?(request, params[:version])
159     not_found
160   else
161     file = configs.get_file(params[:uuid])
162     if file.nil?
163       not_found
164     else
165       send_file file,
166         :filename => "#{params[:uuid]}.tgz",
167         :type => "application/x-tar"
168     end
169   end
170 end
171 
172 ## PUT /files/
173 # Add configuration files for an instance
174 put '/files/:version/:uuid' do
175   if not api_version_valid?(request, params[:version]) or
176       not configs.exists?(params[:uuid])
177     not_found
178   else
179     uuid = params[:uuid]
180     file = params[:file]
181     configs.save_file(uuid, file)
182   end
183 end
184 
185 ## GET /params/
186 # Retrieve the list of "return" parameters names for an instance
187 get '/params/:version/:uuid', :provides => 'text' do
188   if not api_version_valid?(request, params[:version]) or
189       not configs.exists?(params[:uuid])
190     not_found
191   else
192     provides = configs.get_provides(params[:uuid], :as => :text)
193     provides
194   end
195 end
196 
197 get '/params/:version/:uuid', :provides => 'xml' do
198   if not api_version_valid?(request, params[:version]) or
199       not configs.exists?(params[:uuid])
200     not_found
201   else
202     provides = configs.get_provides(params[:uuid], :as => :xml)
203     provides
204   end
205 end
206 
207 ## PUT /params/
208 # Set the live of "return" parameter values for an instance
209 put '/params/:version/:uuid' do
210   if not api_version_valid?(request, params[:version]) or
211       not configs.exists?(params[:uuid])
212     not_found
213   else
214     logger.debug("PUT params: #{params[:audrey_data]}")
215     provides = configs.update(params[:uuid], params[:audrey_data], request.ip)
216     status = ("||" == provides) ? 200 : 202
217     [status, provides]
218   end
219 end

Generated on Wed Dec 14 16:00:31 -0500 2011 with rcov 0.9.11