def _get(id, options)
task_name = id
begin
@tasks_interface.setopts(options)
if options[:dry_run]
if task_name.to_s =~ /\A\d{1,}\Z/
print_dry_run @tasks_interface.dry.get(task_name.to_i)
else
print_dry_run @tasks_interface.dry.get({name: task_name})
end
return
end
task = find_task_by_name_or_id(task_name)
exit 1 if task.nil?
json_response = {'task' => task}
unless task_name.to_s =~ /\A\d{1,}\Z/
json_response = @tasks_interface.get(task['id'])
end
if options[:json]
puts as_json(json_response, options, "task")
return 0
elsif options[:yaml]
puts as_yaml(json_response, options, "task")
return 0
elsif options[:csv]
puts records_as_csv([json_response['task']], options)
return 0
else
task_type = task['taskType'] ? find_task_type_by_name(task['taskType']['name']) : nil
print_h1 "Task Details"
print cyan
description_cols = {
"ID" => 'id',
"Name" => 'name',
"Code" => 'code',
"Type" => lambda {|it| it['taskType']['name'] },
"Labels" => lambda {|it| format_list(it['labels'], '', 3) rescue '' },
"Visibility" => 'visibility',
"Execute Target" => lambda {|it|
if it['executeTarget'] == 'local'
git_info = []
if it['taskOptions']
if it['taskOptions']['localScriptGitId']
git_info << "Git Repo: #{it['taskOptions']['localScriptGitId']}"
end
if it['taskOptions']['localScriptGitRef']
git_info << "Git Ref: #{it['taskOptions']['localScriptGitRef']}"
end
end
"Local #{git_info.join(', ')}"
elsif it['executeTarget'] == 'remote'
remote_url = ""
if it['taskOptions']
remote_url = "#{it['taskOptions']['username']}@#{it['taskOptions']['host']}:#{it['taskOptions']['port']}"
end
"Remote #{remote_url}"
elsif it['executeTarget'] == 'resource'
"Resource"
else
it['executeTarget']
end
},
"Result Type" => 'resultType',
"Retryable" => lambda {|it|
if it['retryable']
format_boolean(it['retryable']).to_s + " Count: #{it['retryCount']}, Delay: #{it['retryDelaySeconds']}"
else
format_boolean(it['retryable'])
end
},
"Allow Custom Config" => lambda {|it| format_boolean(it['allowCustomConfig']) },
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
}
print_description_list(description_cols, task)
if task_type
script_content = nil
task_option_types = []
task_option_config = {}
task_option_columns = []
task_type['optionTypes'].sort { |x,y| x['displayOrder'].to_i <=> y['displayOrder'].to_i }.each do |optionType|
if optionType['code'] == 'script'
script_content = task['taskOptions'][optionType['fieldName']]
elsif optionType['fieldName'] == 'httpHeaders' || optionType['fieldName'] == 'webHeaders'
http_headers = task['taskOptions']['httpHeaders'] || task['taskOptions']['webHeaders']
begin
if http_headers.is_a?(String)
http_headers = JSON.parse(http_headers)
end
task_option_columns << {(optionType['fieldLabel']) => lambda {|it| http_headers.collect {|h| "#{h['key']}: #{h['value']}"}.join(", ") } }
rescue => ex
Morpheus::Logging::DarkPrinter.puts("Failed to parse httpHeaders task option as JSON") if Morpheus::Logging.debug?
end
else
task_option_types << optionType
task_option_columns << {(optionType['fieldLabel']) => lambda {|it|
value = task['taskOptions'][optionType['code']] || task['taskOptions'][optionType['fieldName']] || optionType['defaultValue']
if optionType['type'] == 'checkbox'
value.to_s.empty? ? 'off' : value.to_s
else
value.to_s
end
} }
end
end
else
print yellow,"Task type not found.",reset,"\n"
end
if !task_option_columns.empty?
print_h2 "Task Options"
print_description_list(task_option_columns, task["taskOptions"])
end
if script_content
print_h2 "Script"
print reset,script_content,"\n",reset
end
file_content = task['file']
if file_content && options[:no_content] != true
print_h2 "Script Content"
if file_content['sourceType'] == 'local'
puts file_content['content']
elsif file_content['sourceType'] == 'url'
puts "URL: #{file_content['contentPath']}"
elsif file_content['sourceType'] == 'repository'
puts "Repository: #{file_content['repository']['name'] rescue 'n/a'}"
puts "Path: #{file_content['contentPath']}"
if file_content['contentRef']
puts "Ref: #{file_content['contentRef']}"
end
else
puts "Source: #{file_content['sourceType']}"
puts "Path: #{file_content['contentPath']}"
end
end
print reset,"\n"
return 0
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end