Commit 59d45d87 authored by Alper Akgun's avatar Alper Akgun

Namespace onboarding action for license scanning

Changelog: added
EE: true
parent 1b5ea408
...@@ -27,7 +27,8 @@ class OnboardingProgress < ApplicationRecord ...@@ -27,7 +27,8 @@ class OnboardingProgress < ApplicationRecord
:secure_secret_detection_run, :secure_secret_detection_run,
:secure_coverage_fuzzing_run, :secure_coverage_fuzzing_run,
:secure_api_fuzzing_run, :secure_api_fuzzing_run,
:secure_cluster_image_scanning_run :secure_cluster_image_scanning_run,
:license_scanning_run
].freeze ].freeze
scope :incomplete_actions, -> (actions) do scope :incomplete_actions, -> (actions) do
......
# frozen_string_literal: true
class AddLicenseScanningActionToOnboardingProgresses < Gitlab::Database::Migration[1.0]
def change
add_column :onboarding_progresses, :license_scanning_run_at, :datetime_with_timezone
end
end
2b20f2c3bb8dd5d3ba27dcb8854108763a40be9393f4799f16e9c10daf9fff75
\ No newline at end of file
...@@ -17697,7 +17697,8 @@ CREATE TABLE onboarding_progresses ( ...@@ -17697,7 +17697,8 @@ CREATE TABLE onboarding_progresses (
secure_secret_detection_run_at timestamp with time zone, secure_secret_detection_run_at timestamp with time zone,
secure_coverage_fuzzing_run_at timestamp with time zone, secure_coverage_fuzzing_run_at timestamp with time zone,
secure_cluster_image_scanning_run_at timestamp with time zone, secure_cluster_image_scanning_run_at timestamp with time zone,
secure_api_fuzzing_run_at timestamp with time zone secure_api_fuzzing_run_at timestamp with time zone,
license_scanning_run_at timestamp with time zone
); );
CREATE SEQUENCE onboarding_progresses_id_seq CREATE SEQUENCE onboarding_progresses_id_seq
...@@ -21,6 +21,8 @@ module SCA ...@@ -21,6 +21,8 @@ module SCA
end end
def find_policies(detected_only: false, classification: [], sort: { by: :name, direction: :asc }) def find_policies(detected_only: false, classification: [], sort: { by: :name, direction: :asc })
record_onboarding_progress
classifications = Array(classification || []) classifications = Array(classification || [])
matching_policies = policies.reject do |policy| matching_policies = policies.reject do |policy|
(detected_only && policy.dependencies.none?) || (detected_only && policy.dependencies.none?) ||
...@@ -102,5 +104,11 @@ module SCA ...@@ -102,5 +104,11 @@ module SCA
direction = SORT_DIRECTION[direction] || SORT_DIRECTION[:asc] direction = SORT_DIRECTION[direction] || SORT_DIRECTION[:asc]
direction.call(items.sort_by { |item| attribute.call(item) }) direction.call(items.sort_by { |item| attribute.call(item) })
end end
def record_onboarding_progress
return unless pipeline
OnboardingProgress.register(pipeline.project.root_namespace, :license_scanning_run)
end
end end
end end
...@@ -206,7 +206,23 @@ RSpec.describe SCA::LicenseCompliance do ...@@ -206,7 +206,23 @@ RSpec.describe SCA::LicenseCompliance do
expect(actual).to eql(expected) expect(actual).to eql(expected)
end end
context "when searching for policies for licenses that were detected in a scan report" do it 'records an onboarding progress action for license scanning' do
expect(OnboardingProgress).to receive(:register).with(pipeline.project.root_namespace, :license_scanning_run).and_call_original
license_compliance.find_policies
end
context 'when pipeline is not present' do
let!(:pipeline) { nil }
it 'records an onboarding progress action for license scanning' do
expect(OnboardingProgress).not_to receive(:register).with(anything)
license_compliance.find_policies
end
end
context 'when searching for policies for licenses that were detected in a scan report' do
let(:results) { license_compliance.find_policies(detected_only: true) } let(:results) { license_compliance.find_policies(detected_only: true) }
it 'only includes licenses that appear in the latest license scan report' do it 'only includes licenses that appear in the latest license scan report' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment