63 lines
1.8 KiB
Ruby
63 lines
1.8 KiB
Ruby
require "devops-client/handler/handler"
|
|
require "devops-client/options/stack_preset_options"
|
|
require "devops-client/output/stack_preset"
|
|
|
|
class StackPreset < Handler
|
|
|
|
output_with Output::StackPreset
|
|
|
|
def initialize(host, def_options={})
|
|
@host, @options = host, def_options
|
|
@options_parser = StackPresetOptions.new(ARGV, def_options)
|
|
end
|
|
|
|
def handle
|
|
@options, @args = @options_parser.parse_options_for!(current_command)
|
|
case current_command
|
|
when :list
|
|
list_handler
|
|
output
|
|
when :show
|
|
show_handler
|
|
output
|
|
when :apply
|
|
apply_handler
|
|
output
|
|
end
|
|
end
|
|
|
|
def show_handler
|
|
wrong_params = inspect_parameters(@options_parser.show_params, @args[2])
|
|
if wrong_params
|
|
@options_parser.invalid_show_command
|
|
abort(wrong_params)
|
|
end
|
|
@show = get "/stack_presets/#{@args[2]}"
|
|
end
|
|
|
|
def list_handler
|
|
@list = get('/stack_presets')
|
|
end
|
|
|
|
def apply_handler
|
|
wrong_params = inspect_parameters(@options_parser.apply_params, @args[2])
|
|
if wrong_params
|
|
@options_parser.invalid_apply_command
|
|
abort(wrong_params)
|
|
end
|
|
|
|
params = {}
|
|
params[:id] = @args[2]
|
|
params[:provider] = options[:provider] || resources_selector.select_available_provider
|
|
params[:stack] = options[:stack] || enter_parameter(I18n.t('handler.stack_preset.create.stack'))
|
|
params[:project] = options[:project] || resources_selector.select_available_project
|
|
params[:deploy_env] = options[:deploy_env] || enter_parameter(I18n.t('handler.stack.create.deploy_env'))
|
|
|
|
filepath = options[:parameters_file] || enter_parameter(I18n.t('handler.stack_preset.create.parameters_file'))
|
|
params[:parameters] = JSON.parse(File.read(filepath))
|
|
|
|
@list = post_body("/stack_presets/#{params[:id]}/apply", JSON.pretty_generate(params))
|
|
end
|
|
|
|
end
|