-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig_test.rb
More file actions
325 lines (274 loc) · 11.3 KB
/
config_test.rb
File metadata and controls
325 lines (274 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env ruby
# Copyright 2002-2012 Rally Software Development Corp. All Rights Reserved.
# Rally Connector for <VersionControlSystem_X_) configuration checker
dir = File.dirname(__FILE__)
app_path = File.expand_path("#{dir}/lib/")
unless $LOAD_PATH.include?(app_path)
$LOAD_PATH.unshift app_path
end
$LOAD_PATH.unshift "."
require 'scm_config_reader'
require 'rally_api'
###################################################################################
#
# has to check for:
#
# Ruby version must be 1.9.2 or better
# rally_api gem must be installed and 0.4.1 or better
# path the directory this script lives in should be searchable for 'other' ie., r-xr-xr-x
# RallyWrapper.sh should be readable and executable by process owner
# <vcs>2rally.rb should be readable by the process owner
# path to log file must be writable by process owner (who is probably not owner/group member)
# Rally URL check server value one that is known?
# Rally Connection check credentials valid?
# Rally Workspace check does the Workspace specified in the config exist?
# The Build and Changeset flag must be enabled
# Email validation check
#
###################################################################################
@rally = nil
@workspace = nil
@warnings = 0
CHECK_ITEM_FORMAT = "%-48.48s %-8.8s"
GENERAL_WARNING_NOTE = %{
Several WARNING conditions were detected during this check. These warning
conditions are associated with directories and files not being "world"
searchable or readable or executable. If the post-commit process runs as
the owner of the directory where the connector is installed and executed
then you can safely disregard these warnings. However, if the process that
runs the post-commit hook (the UID) is not the same as the UID of the user
that owns the directory where the connector is installed, then you must
rectify any WARNING condition noted above.
}
###################################################################################
def main()
puts " 1. %s" % [check_ruby_version()]
puts " 2. %s" % [check_rally_api_gem()]
puts " 3. %s" % [check_directory_searchability(Dir.pwd)]
puts " 4. %s" % [check_wrapper_world_executability('RallyWrapper.sh')]
puts " 5. %s" % [check_vcs_connector_script_world_readability()]
puts " 6. %s" % [check_log_write()]
puts " 7. %s" % [check_rally_url(@config)]
puts " 8. %s" % [check_can_connect(@config)]
puts " 9. %s" % [check_valid_workspace(@config)]
puts "10. %s" % [check_build_and_changeset_enabled(@config)]
puts "11. %s" % [check_valid_email(@config.user_name)]
if @warnings > 0
puts GENERAL_WARNING_NOTE
end
end
###################################################################################
def check_ruby_version()
check_name = "Ruby version check"
if RUBY_VERSION[0..3] != "1.9" and RUBY_VERSION[-1].to_i < 2
problem = "Ruby version must be 1.9.2 or greater (yours is #{RUBY_VERSION})"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_rally_api_gem()
check_name = "Ruby rally_api gem check"
result = %x[gem list rally_api]
if result.length < 1
problem = "no rally_api found"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
result.chop!
if result =~ /rally_api \((\d\.\d\.\d+)\)/
gem_version = $1
else
problem = "gem list rally_api result string in unexpected format: |#{result}|"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
major, minor, point = gem_version.split('.').map {|level| level.to_i}
if major == 0
if minor < 4
problem = "rally_api version insufficient: |#{gem_version}|"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
else
if point < 1
problem = "rally_api version insufficient: |#{gem_version}|"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
end
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_directory_searchability(path)
check_name = "Current directory world searchability check"
path_components = path.to_s.split('/').select {|comp| comp and comp.length > 0}
directory_path = ''
path_components.each_with_index do |component, ix|
prepend = '/'
prepend = '' if ix == 0 and component.count(':') > 0 # which will happen on Windows
directory_path += (prepend + path_components.shift)
mode = File::Stat.new(directory_path).mode
if (mode % 2) == 0
@warnings += 1
problem = "this directory is not searchable for non user/group process owner"
return (CHECK_ITEM_FORMAT % [check_name, "WARNING"] + " -- #{problem}")
end
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_wrapper_world_executability(wrapper)
check_name = "Wrapper script world executability check"
full_path = File.join(Dir.pwd, wrapper)
if !File::file?(full_path)
problem = "wrapper script not present or not a file"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
temp = "%o" % File::Stat.new(full_path).mode
world = temp[-1].to_i
executable = (world % 2 > 0)
if !executable
@warnings += 1
problem = "wrapper script %s not world executable" % wrapper
return (CHECK_ITEM_FORMAT % [check_name, "WARNING"] + " -- #{problem}")
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_vcs_connector_script_world_readability()
check_name = "<vcs>2rally.rb driver world readability check"
matches = Dir.glob('*2rally.rb')
if matches.length == 0
problem = "<vcs>2rally.rb script not present"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
# TODO: what if matches has more than 1 item?
driver = matches.first
full_path = File.join(Dir.pwd, driver)
if !File::file?(full_path)
problem = "%s script not present or not a file" % driver
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
temp = "%o" % File::Stat.new(full_path).mode
world = temp[-1].to_i
readable = (world & 4 > 0)
if !readable
@warnings += 1
problem = "driver script %s not world readable" % driver
return (CHECK_ITEM_FORMAT % [check_name, "WARNING"] + " -- #{problem}")
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_log_write
check_name = "Log file write check"
begin
@config = ScmConfigReader.new()
@config.read_xml_config(File.dirname(__FILE__) + "/config.xml")
rescue Exception => ex
problem = "Unable to find/read config.xml file"
puts " 5. Log file write check FAILED -- #{problem}"
Process.exit
end
begin
logger = @config.logger
logger.level = 0
rescue Errno::EACCES
problem = "Unable to write/open to log file (Rally_Connector_Error.log)"
puts " 5. Log file write check FAILED -- #{problem}"
Process.exit
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_rally_url(config)
check_name = "Rally Url check"
valid_url = false
case config.rally_base_url
when "https://test1cluster.rallydev.com/slm"
valid_url = true
when "https://rally1.rallydev.com/slm"
valid_url = true
when "https://sandbox.rallydev.com/slm"
valid_url = true
when "https://trial.rallydev.com/slm"
valid_url = true
when "https://preview.rallydev.com/slm"
valid_url = true
when "https://demo.rallydev.com/slm"
valid_url = true
when "https://demo2.rallydev.com/slm"
valid_url = true
end
if !valid_url
problem = "Server appears to be outside of Rally. Do you have an on-premise installation?"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{problem}")
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_can_connect(config)
check_name = "Rally Connection check"
custom_headers = RallyAPI::CustomHttpHeader.new()
custom_headers.name = 'Rally SCM Config Checker'
custom_headers.version = "2.0"
custom_headers.vendor = 'Rally Software'
rally_config = { :base_url => config.rally_base_url,
:username => config.user_name,
:password => config.password,
:workspace => config.workspace_name,
:headers => custom_headers,
:version => '1.27'
}
begin
@rally = RallyAPI::RallyRestJson.new(rally_config)
rescue Exception => ex
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{ex.to_s}")
end
if @rally.nil?
return CHECK_ITEM_FORMAT % [check_name, "FAILED"]
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_valid_workspace(config)
check_name = "Rally Workspace check"
@workspace = nil
begin
@workspace = @rally.find_workspace(config.workspace_name)
rescue Exception => ex
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{ex.to_s}")
return "Rally Workspace Error - " + e.to_s
end
if @workspace.nil?
condition = "No Open Rally workspace named #{config.workspace_name} found. "
note = 'Note: Workspace names are case sensitive.'
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{condition} #{note}")
else
@workspace.read()
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_build_and_changeset_enabled(config)
check_name = "Rally Build and Changeset flag enabled check"
if @workspace.nil?
condition = "Specified Workspace invalid or non-existent"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{condition}")
end
wksp_conf = @workspace.WorkspaceConfiguration
wksp_conf.read()
if wksp_conf.BuildandChangesetEnabled != true
condition = "Build and Changeset flag not enabled for your workspace"
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- #{condition}")
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
def check_valid_email(email)
check_name = "Email validation check"
unless email =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
return (CHECK_ITEM_FORMAT % [check_name, "FAILED"] + " -- Username is not a valid email address")
end
return CHECK_ITEM_FORMAT % [check_name, "PASSED"]
end
###################################################################################
###################################################################################
main()