Class: Dradis::Plugins::MappingService

Inherits:
Object
  • Object
show all
Defined in:
lib/dradis/plugins/mapping_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination: nil, integration:) ⇒ MappingService

Returns a new instance of MappingService.



6
7
8
9
10
11
# File 'lib/dradis/plugins/mapping_service.rb', line 6

def initialize(destination: nil, integration:)
  @destination = destination
  @integration = integration
  @component = @integration.meta[:name].to_s
  @sample_dir = default_sample_dir
end

Instance Attribute Details

#componentObject

Returns the value of attribute component.



4
5
6
# File 'lib/dradis/plugins/mapping_service.rb', line 4

def component
  @component
end

#destinationObject

Returns the value of attribute destination.



4
5
6
# File 'lib/dradis/plugins/mapping_service.rb', line 4

def destination
  @destination
end

#integrationObject

Returns the value of attribute integration.



4
5
6
# File 'lib/dradis/plugins/mapping_service.rb', line 4

def integration
  @integration
end

#sourceObject

Returns the value of attribute source.



4
5
6
# File 'lib/dradis/plugins/mapping_service.rb', line 4

def source
  @source
end

Instance Method Details

#apply_mapping(data:, source:, mapping_fields: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dradis/plugins/mapping_service.rb', line 13

def apply_mapping(data:, source:, mapping_fields: nil)
  @source = source
  return unless valid_source?

  field_processor = integration::FieldProcessor.new(data: data)
  mapping_fields = mapping_fields || get_mapping_fields

  mapping_fields.map do |field|
    field_name = field.destination_field
    field_content = process_content(
      field.content,
      field_processor
    )

    "#[#{field_name}]#\n#{field_content}"
  end&.join("\n\n")
end

#sampleObject

This returns a sample of valid entry for the Mappings Manager



32
33
34
35
36
37
38
39
40
# File 'lib/dradis/plugins/mapping_service.rb', line 32

def sample
  @sample ||= {}
  if valid_source?
    @sample[source] ||= begin
      sample_file = File.join(@sample_dir, "#{source}.sample")
      File.read(sample_file)
    end
  end
end