mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Slight rework of data param validation
This commit is contained in:
parent
c1099a8273
commit
0c3f84e072
1 changed files with 9 additions and 16 deletions
|
|
@ -124,29 +124,22 @@ module Vmpooler
|
||||||
daily: [] # used for daily info
|
daily: [] # used for daily info
|
||||||
}
|
}
|
||||||
|
|
||||||
from_param, to_param = params[:from], params[:to]
|
from_param = params[:from] || Date.today.to_s
|
||||||
|
to_param = params[:to] || Date.today.to_s
|
||||||
|
|
||||||
# Check date formats.
|
# Validate date formats
|
||||||
# It is ok if to_param is nil, we will assume this means 'today'
|
[from_param, to_param].each do |param|
|
||||||
if to_param.nil?
|
if !validate_date_str(param.to_s)
|
||||||
to_param = Date.today.to_s
|
halt 400, "Invalid date format '#{param}', must match YYYY-MM-DD."
|
||||||
elsif !validate_date_str(to_param.to_s)
|
|
||||||
halt 400, 'Invalid "to" date format, must match YYYY-MM-DD'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# It is also ok if from_param is nil, we will assume this also means 'today'
|
|
||||||
if from_param.nil?
|
|
||||||
from_param = Date.today.to_s
|
|
||||||
elsif !validate_date_str(from_param.to_s)
|
|
||||||
halt 400, 'Invalid "from" date format, must match YYYY-MM-DD'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
from_date, to_date = Date.parse(from_param), Date.parse(to_param)
|
from_date, to_date = Date.parse(from_param), Date.parse(to_param)
|
||||||
|
|
||||||
if to_date < from_date
|
if to_date < from_date
|
||||||
halt 400, 'Date range is invalid, "to" cannot come before "from".'
|
halt 400, 'Date range is invalid, \'to\' cannot come before \'from\'.'
|
||||||
elsif from_date > Date.today
|
elsif from_date > Date.today
|
||||||
halt 400, 'Date range is invalid, "from" must be in the past.'
|
halt 400, 'Date range is invalid, \'from\' must be in the past.'
|
||||||
end
|
end
|
||||||
|
|
||||||
# total clone time for entire duration requested.
|
# total clone time for entire duration requested.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue