Module: Dradis::Plugins::Templates::MigrateTemplates::ClassMethods

Defined in:
lib/dradis/plugins/templates/migrate_templates.rb

Instance Method Summary collapse

Instance Method Details

#migrate_templates_to_mappings(args = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dradis/plugins/templates/migrate_templates.rb', line 29

def migrate_templates_to_mappings(args = {})
  # return if the integration doesn't provide any templates ex. projects, cve
  return unless paths['dradis/templates'].existent.any?
  @integration_name = plugin_name.to_s
  # return if templates have already been migrated (mappings exist for the integration)
  return if ::Mapping.where(component: @integration_name).any?

  templates_dir = args.fetch(:from)
  integration_templates_dir = File.join(templates_dir, @integration_name)

  if uploaders.count > 1
    migrate_multiple_uploaders(@integration_name, integration_templates_dir)
  else
    template_files = Dir["#{integration_templates_dir}/*.template"]
    return unless template_files.any?

    template_files.each do |template_file|
      next unless File.exist?(template_file)
      source = File.basename(template_file, '.template')
      # create a mapping & mapping_fields for each field in the file
      migrate(template_file, source)
      rename_file(template_file)
    end
  end
end