Skip to content
Snippets Groups Projects
Verified Commit 2850d4d9 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
sudo: false
language: ruby
rvm:
- 2.3.8
before_install: gem install bundler -v 1.16.1
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in foreman_template_task.gemspec
gemspec
This diff is collapsed.
# Foreman Template Tasks
A small [Foreman](https://theforeman.org/) plugin to add tasks for automatic template handling.
## Contributing
Bug reports and pull requests are welcome [on GitHub](https://github.com/ananace/foreman_template_tasks).
## License
The gem is available as open source under the terms of the [GPL-3.0 License](https://opensource.org/licenses/GPL-3.0).
Rakefile 0 → 100644
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task :default => :test
# frozen_string_literal: true
module Actions
module ForemanTemplateTasks
class TemplateAction < Actions::Base
middleware.use Actions::Middleware::KeepCurrentUser
def plan(template_params = {})
input.update task_params: template_params
plan_self
end
def humanized_output
return unless output[:results]
exceptions = output[:results]
.reject { |r| r[:exception].nil? }
.group_by { |r| [r[:type], r[:additional_errors] || r[:exception]] }
.map do |k, v|
"#{v.size} templates#{k.first.nil? ? '' : " of type #{k.first}"} skipped: #{k.last}"
end
out = "#{humanized_action} finished, #{output[:results].select { |r| r[:exception].nil? }.count} templates handled"
if exceptions.empty?
out += '.'
else
out += ", #{output[:results].reject { |r| r[:exception].nil? }.count} skipped;"
out += "\n\n" + exceptions.join("\n")
end
out
end
def humanized_action
''
end
def task_output
(output[:results] || []).map do |r|
{
name: r[:name],
type: r[:type],
changed: r[:changed],
imported: r[:imported],
error: r[:additional_errors] || r[:exception]
}
end
end
def rescue_strategy
Dynflow::Action::Rescue::Skip
end
def self.cleanup_after
'1d'
end
end
end
end
# frozen_string_literal: true
module Actions
module ForemanTemplateTasks
class TemplateExportAction < TemplateAction
def run
exporter = ForemanTemplates::TemplateExporter.new(input[:task_params])
output[:results] = exporter.export![:results].map(&:to_h)
end
def humanized_action
'Export'
end
def humanized_name
_('Export Foreman Templates')
end
end
end
end
# frozen_string_literal: true
module Actions
module ForemanTemplateTasks
class TemplateImportAction < TemplateAction
def run
importer = ForemanTemplates::TemplateImporter.new(input[:task_params])
output[:results] = importer.import![:results].map(&:to_h)
end
def humanized_action
'Import'
end
def humanized_name
_('Import Foreman Templates')
end
end
end
end
# frozen_string_literal: true
require File.expand_path('lib/foreman_template_tasks/version', __dir__)
Gem::Specification.new do |spec|
spec.name = 'foreman_template_tasks'
spec.version = ForemanTemplateTasks::VERSION
spec.authors = ['Alexander Olofsson']
spec.email = ['alexander.olofsson@liu.se']
spec.summary = 'Foreman plug-in to automatically sync templates'
spec.homepage = 'https://github.com/ananace/foreman_template_tasks'
spec.license = 'GPL-3.0'
spec.files = Dir['{app,lib}/**/*'] + %w[LICENSE Rakefile README.md]
spec.add_runtime_dependency 'foreman-tasks'
spec.add_runtime_dependency 'foreman_templates'
end
# frozen_string_literal: true
require 'foreman_template_tasks/engine'
module ForemanTemplateTasks
end
# frozen_string_literal: true
require 'dynflow'
require 'foreman-tasks'
module ForemanTemplateTasks
class Engine < ::Rails::Engine
engine_name 'foreman_template_tasks'
config.autoload_paths += Dir["#{config.root}/app/lib"]
initializer 'foreman_template_tasks.register_paths' do |_app|
::ForemanTasks.dynflow.config.eager_load_paths.concat(%W[#{ForemanTemplateTasks::Engine.root}/app/lib/actions])
end
initializer 'foreman_template_tasks.register_plugin', before: :finisher_hook do |_app|
Foreman::Plugin.register :foreman_template_tasks do
requires_foreman '>= 1.19'
end
end
initializer 'foreman_template_tasks.dynflow_world', before: 'foreman_tasks.initialize_dynflow' do |_app|
::ForemanTasks.dynflow.require!
end
# Include concerns in this config.to_prepare block
config.to_prepare do
begin
# ::
rescue StandardError => e
Rails.logger.warn "ForemanTemplateTasks: skipping engine hook (#{e})"
end
end
end
end
# frozen_string_literal: true
module ForemanTemplateTasks
VERSION = '0.1.0'.freeze
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment