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
4d719fc2
Commit
4d719fc2
authored
Jul 09, 2019
by
Tetiana Chupryna
Committed by
Nick Thomas
Jul 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter DependencyList by package_manager
parent
b4f8e281
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
1 deletion
+28
-1
ee/app/services/security/dependency_list_service.rb
ee/app/services/security/dependency_list_service.rb
+12
-1
ee/changelogs/unreleased/10078-add-filtering-to-service.yml
ee/changelogs/unreleased/10078-add-filtering-to-service.yml
+5
-0
ee/lib/gitlab/ci/parsers/security/formatters/dependency_list.rb
.../gitlab/ci/parsers/security/formatters/dependency_list.rb
+1
-0
ee/spec/lib/gitlab/ci/parsers/security/formatters/dependency_list_spec.rb
...ab/ci/parsers/security/formatters/dependency_list_spec.rb
+1
-0
ee/spec/services/security/dependency_list_service_spec.rb
ee/spec/services/security/dependency_list_service_spec.rb
+9
-0
No files found.
ee/app/services/security/dependency_list_service.rb
View file @
4d719fc2
...
@@ -4,11 +4,13 @@ module Security
...
@@ -4,11 +4,13 @@ module Security
class
DependencyListService
class
DependencyListService
SORT_BY_VALUES
=
%w(name packager)
.
freeze
SORT_BY_VALUES
=
%w(name packager)
.
freeze
SORT_VALUES
=
%w(asc desc)
.
freeze
SORT_VALUES
=
%w(asc desc)
.
freeze
FILTER_PACKAGE_MANAGERS_VALUES
=
%w(bundler yarn npm maven composer pip)
.
freeze
# @param pipeline [Ci::Pipeline]
# @param pipeline [Ci::Pipeline]
# @param [Hash] params to sort dependencies
# @param [Hash] params to sort
and filter
dependencies
# @option params ['asc', 'desc'] :sort ('asc') Order
# @option params ['asc', 'desc'] :sort ('asc') Order
# @option params ['name', 'packager'] :sort_by ('name') Field to sort
# @option params ['name', 'packager'] :sort_by ('name') Field to sort
# @option params ['bundler', 'yarn', 'npm', 'maven', 'composer', 'pip'] :package_manager ('bundler') Field to filter
def
initialize
(
pipeline
:,
params:
{})
def
initialize
(
pipeline
:,
params:
{})
@pipeline
=
pipeline
@pipeline
=
pipeline
@params
=
params
@params
=
params
...
@@ -17,6 +19,7 @@ module Security
...
@@ -17,6 +19,7 @@ module Security
# @return [Array<Hash>] collection of found dependencies
# @return [Array<Hash>] collection of found dependencies
def
execute
def
execute
collection
=
init_collection
collection
=
init_collection
collection
=
filter
(
collection
)
collection
=
sort
(
collection
)
collection
=
sort
(
collection
)
collection
collection
end
end
...
@@ -29,6 +32,14 @@ module Security
...
@@ -29,6 +32,14 @@ module Security
pipeline
.
dependency_list_report
.
dependencies
pipeline
.
dependency_list_report
.
dependencies
end
end
def
filter
(
collection
)
return
collection
unless
params
[
:package_manager
]
collection
.
select
do
|
dependency
|
params
[
:package_manager
].
include?
(
dependency
[
:package_manager
])
end
end
def
sort
(
collection
)
def
sort
(
collection
)
if
params
[
:sort_by
]
==
'packager'
if
params
[
:sort_by
]
==
'packager'
collection
.
sort_by!
{
|
a
|
a
[
:packager
]
}
collection
.
sort_by!
{
|
a
|
a
[
:packager
]
}
...
...
ee/changelogs/unreleased/10078-add-filtering-to-service.yml
0 → 100644
View file @
4d719fc2
---
title
:
Add filtering by package manager for dependencies
merge_request
:
14562
author
:
type
:
added
ee/lib/gitlab/ci/parsers/security/formatters/dependency_list.rb
View file @
4d719fc2
...
@@ -14,6 +14,7 @@ module Gitlab
...
@@ -14,6 +14,7 @@ module Gitlab
{
{
name:
dependency
[
'package'
][
'name'
],
name:
dependency
[
'package'
][
'name'
],
packager:
packager
(
package_manager
),
packager:
packager
(
package_manager
),
package_manager:
package_manager
,
location:
{
location:
{
blob_path:
blob_path
(
file_path
),
blob_path:
blob_path
(
file_path
),
path:
file_path
path:
file_path
...
...
ee/spec/lib/gitlab/ci/parsers/security/formatters/dependency_list_spec.rb
View file @
4d719fc2
...
@@ -26,6 +26,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DependencyList do
...
@@ -26,6 +26,7 @@ describe Gitlab::Ci::Parsers::Security::Formatters::DependencyList do
expect
(
data
[
:name
]).
to
eq
(
'mini_portile2'
)
expect
(
data
[
:name
]).
to
eq
(
'mini_portile2'
)
expect
(
data
[
:packager
]).
to
eq
(
'Ruby (Bundler)'
)
expect
(
data
[
:packager
]).
to
eq
(
'Ruby (Bundler)'
)
expect
(
data
[
:package_manager
]).
to
eq
(
'bundler'
)
expect
(
data
[
:location
][
:blob_path
]).
to
eq
(
blob_path
)
expect
(
data
[
:location
][
:blob_path
]).
to
eq
(
blob_path
)
expect
(
data
[
:location
][
:path
]).
to
eq
(
'rails/Gemfile.lock'
)
expect
(
data
[
:location
][
:path
]).
to
eq
(
'rails/Gemfile.lock'
)
expect
(
data
[
:version
]).
to
eq
(
'2.2.0'
)
expect
(
data
[
:version
]).
to
eq
(
'2.2.0'
)
...
...
ee/spec/services/security/dependency_list_service_spec.rb
View file @
4d719fc2
...
@@ -27,6 +27,15 @@ describe Security::DependencyListService do
...
@@ -27,6 +27,15 @@ describe Security::DependencyListService do
end
end
context
'with params'
do
context
'with params'
do
context
'filtered by package_managers'
do
let
(
:params
)
{
{
package_manager:
'bundler'
}
}
it
'returns filtered items'
do
expect
(
subject
.
size
).
to
eq
(
2
)
expect
(
subject
.
first
[
:packager
]).
to
eq
(
'Ruby (Bundler)'
)
end
end
context
'sorted desc by packagers'
do
context
'sorted desc by packagers'
do
let
(
:params
)
do
let
(
:params
)
do
{
{
...
...
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