Module: Dradis::Plugins::CSV
- Defined in:
- lib/dradis/plugins/csv.rb,
lib/dradis/plugins/csv/engine.rb,
lib/dradis/plugins/csv/mapping.rb,
lib/dradis/plugins/csv/version.rb,
lib/dradis/plugins/csv/importer.rb,
lib/dradis/plugins/csv/gem_version.rb,
lib/dradis/plugins/csv/mapping_form.rb,
lib/dradis/plugins/csv/field_processor.rb,
app/jobs/dradis/plugins/csv/mapping_import_job.rb,
app/controllers/dradis/plugins/csv/upload_controller.rb
Defined Under Namespace
Modules: Mapping, VERSION Classes: Engine, FieldProcessor, FileExtensionError, Importer, MappingForm, MappingImportJob, UploadController
Class Method Summary collapse
- .default_mapping(_source) ⇒ Object
-
.field_names(source:, destination: nil, field_type: 'destination') ⇒ Object
Excludes the reserved identifier/node fields from the destination field list: they carry row metadata, not entity content (see Importer#mapped_fields, which excludes them the same way when building the import template).
-
.gem_version ⇒ Object
Returns the version of the currently loaded Dradis as a Gem::Version.
-
.mapping_exists?(headers:, destination:) ⇒ Boolean
Whether a format matching these headers has already been mapped for this destination, i.e.
-
.mapping_source(headers:, entity:) ⇒ Object
The source name for a CSV format: the entity (issue/evidence) the mapping populates, plus its normalized headers joined with '/', so the Mappings Manager shows something recognizable (e.g. issue_severity/title) instead of an opaque digest.
- .mapping_sources ⇒ Object
- .normalize_header(header) ⇒ Object
-
.sample(source) ⇒ Object
We're building a dynamic source here since we can't rely on a fixed set of sources unlike the other integrations.
- .source_fields(source) ⇒ Object
-
.version ⇒ Object
Returns the version of the currently loaded CSV as a Gem::Version.
Class Method Details
.default_mapping(_source) ⇒ Object
18 19 20 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 18 def self.default_mapping(_source) {} end |
.field_names(source:, destination: nil, field_type: 'destination') ⇒ Object
Excludes the reserved identifier/node fields from the destination field list: they carry row metadata, not entity content (see Importer#mapped_fields, which excludes them the same way when building the import template).
25 26 27 28 29 30 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 25 def self.field_names(source:, destination: nil, field_type: 'destination') super.reject do |field| field_type == 'destination' && [Mapping::IDENTIFIER_FIELD, Mapping::NODE_LABEL_FIELD].include?(field) end end |
.gem_version ⇒ Object
Returns the version of the currently loaded Dradis as a Gem::Version
5 6 7 |
# File 'lib/dradis/plugins/csv/gem_version.rb', line 5 def self.gem_version Gem::Version.new VERSION::STRING end |
.mapping_exists?(headers:, destination:) ⇒ Boolean
Whether a format matching these headers has already been mapped for this destination, i.e. whether either its issue or evidence Mapping (or both) was saved. Shared by Importer#import (to recognize a format on upload) and UploadController (to skip the mapper for a recognized format).
36 37 38 39 40 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 36 def self.mapping_exists?(headers:, destination:) sources = %i[issue evidence].map { |entity| mapping_source(headers: headers, entity: entity) } ::Mapping.exists?(component: component, source: sources, destination: destination) end |
.mapping_source(headers:, entity:) ⇒ Object
The source name for a CSV format: the entity (issue/evidence) the mapping populates, plus its normalized headers joined with '/', so the Mappings Manager shows something recognizable (e.g. issue_severity/title) instead of an opaque digest. Headers are sorted so reordering columns doesn't produce a new source; any '/' inside a header name is replaced so it can't be mistaken for the join separator. The entity prefix also lets Importer.templates group sources by entity with a simple regex.
53 54 55 56 57 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 53 def self.mapping_source(headers:, entity:) normalized = headers.map { |header| normalize_header(header).gsub('/', '-') }.sort "#{entity}_#{normalized.join('/')}" end |
.mapping_sources ⇒ Object
42 43 44 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 42 def self.mapping_sources ::Mapping.where(component: component).distinct.pluck(:source).map(&:to_sym) end |
.normalize_header(header) ⇒ Object
59 60 61 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 59 def self.normalize_header(header) header.to_s.delete(" \t\r\n") end |
.sample(source) ⇒ Object
We're building a dynamic source here since we can't rely on a fixed set of sources unlike the other integrations.
65 66 67 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 65 def self.sample(source) source_fields(source).index_with { |field| field }.to_json end |
.source_fields(source) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/dradis/plugins/csv/mapping.rb', line 69 def self.source_fields(source) ::MappingField. joins(:mapping). where(mappings: { component: component, source: source.to_s }). where.not(source_field: 'Custom Text'). distinct. pluck(:source_field) end |
.version ⇒ Object
Returns the version of the currently loaded CSV as a Gem::Version.
8 9 10 |
# File 'lib/dradis/plugins/csv/version.rb', line 8 def self.version gem_version end |