Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4c9cae15
Commit
4c9cae15
authored
Apr 22, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move CSV exporter to exporters namespace
parent
6d151372
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
38 deletions
+40
-38
ee/app/services/vulnerability_exports/export_csv_service.rb
ee/app/services/vulnerability_exports/export_csv_service.rb
+0
-34
ee/app/services/vulnerability_exports/exporters/csv_service.rb
...p/services/vulnerability_exports/exporters/csv_service.rb
+36
-0
ee/spec/services/vulnerability_exports/exporters/csv_service_spec.rb
...vices/vulnerability_exports/exporters/csv_service_spec.rb
+4
-4
No files found.
ee/app/services/vulnerability_exports/export_csv_service.rb
deleted
100644 → 0
View file @
6d151372
# frozen_string_literal: true
module
VulnerabilityExports
class
ExportCsvService
attr_reader
:vulnerabilities
def
initialize
(
vulnerabilities_relation
)
@vulnerabilities
=
vulnerabilities_relation
end
def
csv_data
(
&
block
)
csv_builder
.
render
(
&
block
)
end
def
csv_builder
@csv_builder
||=
CsvBuilder
.
new
(
vulnerabilities
.
with_findings_and_scanner
,
header_to_value_hash
)
end
private
def
header_to_value_hash
{
'Scanner Type'
=>
'report_type'
,
'Scanner Name'
=>
'finding_scanner_name'
,
'Status'
=>
'state'
,
'Vulnerability'
=>
'title'
,
'Details'
=>
'description'
,
'Additional Info'
=>
->
(
vulnerability
)
{
vulnerability
.
finding_metadata
&
.
fetch
(
'message'
,
nil
)
},
'Severity'
=>
'severity'
,
'CVE'
=>
->
(
vulnerability
)
{
vulnerability
.
finding_metadata
&
.
fetch
(
'cve'
,
nil
)
}
}
end
end
end
ee/app/services/vulnerability_exports/exporters/csv_service.rb
0 → 100644
View file @
4c9cae15
# frozen_string_literal: true
module
VulnerabilityExports
module
Exporters
class
CsvService
attr_reader
:vulnerabilities
def
initialize
(
vulnerabilities_relation
)
@vulnerabilities
=
vulnerabilities_relation
end
def
generate
(
&
block
)
csv_builder
.
render
(
&
block
)
end
private
def
csv_builder
@csv_builder
||=
CsvBuilder
.
new
(
vulnerabilities
.
with_findings_and_scanner
,
header_to_value_hash
)
end
def
header_to_value_hash
{
'Scanner Type'
=>
'report_type'
,
'Scanner Name'
=>
'finding_scanner_name'
,
'Status'
=>
'state'
,
'Vulnerability'
=>
'title'
,
'Details'
=>
'description'
,
'Additional Info'
=>
->
(
vulnerability
)
{
vulnerability
.
finding_metadata
&
.
fetch
(
'message'
,
nil
)
},
'Severity'
=>
'severity'
,
'CVE'
=>
->
(
vulnerability
)
{
vulnerability
.
finding_metadata
&
.
fetch
(
'cve'
,
nil
)
}
}
end
end
end
end
ee/spec/services/vulnerability_exports/export
_
csv_service_spec.rb
→
ee/spec/services/vulnerability_exports/export
ers/
csv_service_spec.rb
View file @
4c9cae15
...
...
@@ -2,23 +2,23 @@
require
'spec_helper'
describe
VulnerabilityExports
::
ExportCsvService
do
describe
VulnerabilityExports
::
Export
ers
::
CsvService
do
let_it_be
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:vulnerability
)
{
create
(
:vulnerability
,
:with_findings
,
project:
project
)
}
let
(
:export_csv_service
)
{
described_class
.
new
(
Vulnerability
.
all
)
}
subject
(
:csv
)
{
CSV
.
parse
(
export_csv_service
.
csv_data
,
headers:
true
)
}
subject
(
:csv
)
{
CSV
.
parse
(
export_csv_service
.
generate
,
headers:
true
)
}
context
'when block is not given'
do
it
'renders csv to string'
do
expect
(
export_csv_service
.
csv_data
).
to
be_a
String
expect
(
export_csv_service
.
generate
).
to
be_a
String
end
end
context
'when block is given'
do
it
'returns handle to Tempfile'
do
expect
(
export_csv_service
.
csv_data
{
|
file
|
file
}).
to
be_a
Tempfile
expect
(
export_csv_service
.
generate
{
|
file
|
file
}).
to
be_a
Tempfile
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment