fluke/devops-service/app/api3/parsers/project.rb

123 lines
3.7 KiB
Ruby
Raw Normal View History

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 ProjectParser < RequestParser
2018-04-04 22:44:39 +03:00
include Devops::API3::Helpers
2015-08-03 15:09:04 +03:00
def projects
fields = []
if @params.key?("fields") and @params["fields"].is_a?(Array)
2018-04-04 22:44:39 +03:00
Devops::Model::Project.list_fields.each do |k|
2015-08-03 15:09:04 +03:00
fields.push k if @params["fields"].include?(k)
end
end
fields
end
def archived_projects
@params.include?("archived")
end
2015-07-30 15:37:43 +03:00
def project_servers
2018-04-04 22:44:39 +03:00
@params["environment"]
2015-07-30 15:37:43 +03:00
end
def project_stacks
2018-04-04 22:44:39 +03:00
@params["environment"]
2015-07-30 15:37:43 +03:00
end
def create_project
body = create_object_from_json_body
2018-04-04 22:44:39 +03:00
project = Devops::Model::Project.new(body)
#project.validate!
project
end
def users
create_object_from_json_body(Array)
end
def set_description
body = create_object_from_json_body
body["description"]
2015-07-30 15:37:43 +03:00
end
2015-09-14 17:47:11 +03:00
def set_project_components
c = create_object_from_json_body(Hash)
raise InvalidRecord.new("'components' key not found") if c["components"].nil?
c
end
2018-04-04 22:44:39 +03:00
def add_environment
2015-10-05 14:54:47 +03:00
body = create_object_from_json_body
2018-04-04 22:44:39 +03:00
Devops::Model::Environment.new(body)
2015-10-05 14:54:47 +03:00
end
2018-04-04 22:44:39 +03:00
def update_environment_field
body = create_object_from_json_body
raise InvalidRecord.new("'value' key not found") if body["value"].nil?
body["value"]
end
2018-04-04 22:44:39 +03:00
def update_environment
body = create_object_from_json_body
# rl = check_array(body["run_list"], "Parameter 'run_list' should be an array of string", String, false, true)
# Validators::Helpers::RunList.new(rl).validate!
2018-04-04 22:44:39 +03:00
Devops::Model::EnvironmentFactory.create(body)
end
2015-07-30 15:37:43 +03:00
def update
body = create_object_from_json_body
2018-04-04 22:44:39 +03:00
=begin
2015-09-15 13:06:25 +03:00
check_string(body["description"], "Parameter 'description' must be a string", true, true)
2015-09-15 14:12:39 +03:00
rl = check_array(body["run_list"], "Parameter 'run_list' must be an array of string", String, true, true)
2015-09-15 13:06:25 +03:00
Validators::Helpers::RunList.new(rl).validate! unless rl.nil?
#Devops::Model::Project.new(body)
2018-04-04 22:44:39 +03:00
=end
2015-09-15 13:06:25 +03:00
body
2015-07-30 15:37:43 +03:00
end
2018-04-04 22:44:39 +03:00
def add_category
Devops::Model::Category.new(create_object_from_json_body)
end
2015-07-30 15:37:43 +03:00
def delete
body = create_object_from_json_body(Hash, true)
2018-04-04 22:44:39 +03:00
environment = unless body.nil?
check_string(body["environment"], "Parameter 'environment' should be a not empty string", true)
2015-07-30 15:37:43 +03:00
end
end
def project_users
body = create_object_from_json_body
users = check_array(body["users"], "Parameter 'users' must be a not empty array of strings")
2018-04-04 22:44:39 +03:00
environment = check_string(body["environment"], "Parameter 'environment' must be a not empty string", true)
return environment, users
2015-07-30 15:37:43 +03:00
end
def run_list
list = create_object_from_json_body(Array)
2018-04-04 22:44:39 +03:00
RunListArrayValidator.validate_list(list)
list
2015-07-30 15:37:43 +03:00
end
def deploy
obj = create_object_from_json_body
2018-04-04 22:44:39 +03:00
environment = check_string(obj["environment"], "Parameter 'environment' should be a not empty string", true)
2015-07-30 15:37:43 +03:00
servers = check_array(obj["servers"], "Parameter 'servers' should be a not empty array of strings", String, true)
2018-04-04 22:44:39 +03:00
return environment, servers
2015-07-30 15:37:43 +03:00
end
2018-04-04 22:44:39 +03:00
def delete_project_env_servers
body = create_object_from_json_body
dry_run = check_boolean(body["dry_run"], "Parameter 'dry_run' must be a boolean")
2018-04-04 22:44:39 +03:00
dry_run
end
2015-07-30 15:37:43 +03:00
end
end
end
end