2015-07-30 15:37:43 +03:00
|
|
|
require_relative "request_parser"
|
|
|
|
|
|
|
|
|
|
module Devops
|
2018-04-04 22:44:39 +03:00
|
|
|
module API3
|
2015-07-30 15:37:43 +03:00
|
|
|
module Parser
|
|
|
|
|
class StackParser < RequestParser
|
|
|
|
|
|
|
|
|
|
def create
|
2015-08-12 13:32:26 +03:00
|
|
|
@body ||= create_object_from_json_body
|
2018-04-04 22:44:39 +03:00
|
|
|
|
|
|
|
|
stack_attributes = @body.fetch('stack_attributes')
|
|
|
|
|
check_string(stack_attributes['project'], "Parameter 'project' must be a not empty string")
|
|
|
|
|
check_string(stack_attributes['environment'], "Parameter 'environment' must be a not empty string")
|
|
|
|
|
check_string(stack_attributes['category'], "Parameter 'category' must be a not empty string")
|
|
|
|
|
check_string(stack_attributes['name'], "Parameter 'name' must be a not empty string", true, false)
|
|
|
|
|
list = check_array(stack_attributes['run_list'], "Parameter 'run_list' is invalid, it should be not empty array of strings", String, true, true)
|
2015-08-04 12:36:10 +03:00
|
|
|
Validators::Helpers::RunList.new(list).validate! unless list.nil?
|
2015-08-12 13:32:26 +03:00
|
|
|
@body
|
2015-08-04 12:36:10 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def run_list
|
|
|
|
|
list = check_array(create_object_from_json_body(Array), "Body must contains not empty array of strings")
|
|
|
|
|
Validators::Helpers::RunList.new(list).validate!
|
|
|
|
|
list
|
2015-07-30 15:37:43 +03:00
|
|
|
end
|
|
|
|
|
|
2015-09-15 17:14:26 +03:00
|
|
|
def tags
|
|
|
|
|
@body ||= create_object_from_json_body
|
|
|
|
|
raise InvalidRecord.new("Request body should be an object") unless @body.is_a?(Hash)
|
|
|
|
|
@body.each do |k, v|
|
|
|
|
|
raise InvalidRecord.new("Invalid key '#{k}', it should be a String") unless k.is_a?(String)
|
|
|
|
|
raise InvalidRecord.new("Invalid value '#{v}' for key '#{k}', it should be a String") unless v.is_a?(String)
|
|
|
|
|
end
|
|
|
|
|
@body
|
|
|
|
|
end
|
|
|
|
|
|
2015-08-14 13:28:03 +03:00
|
|
|
def deploy
|
|
|
|
|
@body ||= create_object_from_json_body
|
|
|
|
|
names = check_array(@body["names"], "Parameter 'names' should be a not empty array of strings", String, true)
|
|
|
|
|
tags = check_array(@body["tags"], "Parameter 'tags' should be an array of strings", String, true)
|
|
|
|
|
@body
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-17 18:08:38 +03:00
|
|
|
def change_stack_template
|
|
|
|
|
template_id = create_object_from_json_body['stack_template']
|
|
|
|
|
check_string(template_id, "Parameter 'stack_template' must be a not empty string")
|
|
|
|
|
template_id
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-30 15:37:43 +03:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|