104 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require "app/api2/helpers/version_2"
 | |
| require_relative "request_parser"
 | |
| 
 | |
| module Devops
 | |
|   module API2_0
 | |
|     module Parser
 | |
|       class ProjectParser < RequestParser
 | |
| 
 | |
|         include Devops::API2_0::Helpers
 | |
| 
 | |
|         def projects
 | |
|           fields = []
 | |
|           if @params.key?("fields") and @params["fields"].is_a?(Array)
 | |
|             Devops::Model::Project.fields.each do |k|
 | |
|               fields.push k if @params["fields"].include?(k)
 | |
|             end
 | |
|           end
 | |
|           fields
 | |
|         end
 | |
| 
 | |
|         def archived_projects
 | |
|           @params.include?("archived")
 | |
|         end
 | |
| 
 | |
|         def project_servers
 | |
|           @params["deploy_env"]
 | |
|         end
 | |
| 
 | |
|         def project_stacks
 | |
|           @params["deploy_env"]
 | |
|         end
 | |
| 
 | |
|         def create_project
 | |
|           body = create_object_from_json_body
 | |
|           check_string(body["name"], "Parameter 'name' must be a not empty string")
 | |
|           check_array(body["deploy_envs"], "Parameter 'deploy_envs' must be a not empty array of objects", Hash)
 | |
|           rl = check_array(body["run_list"], "Parameter 'run_list' should be an array of string", String, true, true)
 | |
|           Validators::Helpers::RunList.new(rl).validate! unless rl.nil?
 | |
|           Devops::Model::Project.new(body)
 | |
|         end
 | |
| 
 | |
|         def set_project_components
 | |
|           c = create_object_from_json_body(Hash)
 | |
|           raise InvalidRecord.new("'components' key not found") if c["components"].nil?
 | |
|           c
 | |
|         end
 | |
| 
 | |
|         def add_deploy_env
 | |
|           body = create_object_from_json_body
 | |
|           Devops::Model::DeployEnvFactory.create(body)
 | |
|         end
 | |
| 
 | |
|         def update_deploy_env_field
 | |
|           body = create_object_from_json_body
 | |
|           raise InvalidRecord.new("'value' key not found") if body["value"].nil?
 | |
|           body["value"]
 | |
|         end
 | |
| 
 | |
|         def update_deploy_env
 | |
|           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!
 | |
|           Devops::Model::DeployEnvFactory.create(body)
 | |
|         end
 | |
| 
 | |
|         def update
 | |
|           body = create_object_from_json_body
 | |
|           check_string(body["description"], "Parameter 'description' must be a string", true, true)
 | |
|           rl = check_array(body["run_list"], "Parameter 'run_list' must be an array of string", String, true, true)
 | |
|           Validators::Helpers::RunList.new(rl).validate! unless rl.nil?
 | |
|           #Devops::Model::Project.new(body)
 | |
|           body
 | |
|         end
 | |
| 
 | |
|         def delete
 | |
|           body = create_object_from_json_body(Hash, true)
 | |
|           deploy_env = unless body.nil?
 | |
|             check_string(body["deploy_env"], "Parameter 'deploy_env' should be a not empty string", true)
 | |
|           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")
 | |
|           deploy_env = check_string(body["deploy_env"], "Parameter 'deploy_env' must be a not empty string", true)
 | |
|           return deploy_env, users
 | |
|         end
 | |
| 
 | |
|         def run_list
 | |
|           list = create_object_from_json_body(Array)
 | |
|           check_array(list, "Body must contains not empty array of strings")
 | |
|         end
 | |
| 
 | |
|         def deploy
 | |
|           obj = create_object_from_json_body
 | |
|           deploy_env = check_string(obj["deploy_env"], "Parameter 'deploy_env' should be a not empty string", true)
 | |
|           servers = check_array(obj["servers"], "Parameter 'servers' should be a not empty array of strings", String, true)
 | |
|           return deploy_env, servers
 | |
|         end
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 | 
