Commit 7baa1f32 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Fabio Pitino

Remove the usage of yaml_variables in SastParser

parent ec87f32f
......@@ -109,17 +109,17 @@ module Security
yaml_result = Gitlab::Ci::YamlProcessor.new(content, options).execute
return {} unless yaml_result.valid?
sast_attributes = yaml_result.build_attributes(:sast)
extract_required_attributes(sast_attributes)
extract_required_attributes(yaml_result)
end
def extract_required_attributes(attributes)
def extract_required_attributes(yaml_result)
result = {}
attributes[:yaml_variables].each do |variable|
yaml_result.yaml_variables_for(:sast).each do |variable|
result[variable[:key]] = variable[:value]
end
result[:stage] = attributes[:stage]
result[:stage] = yaml_result.stage_for(:sast)
result.with_indifferent_access
end
end
......
......@@ -111,6 +111,22 @@ module Gitlab
@ci_config.variables_with_data
end
def yaml_variables_for(job_name)
job = jobs.fetch(job_name)
Gitlab::Ci::Variables::Helpers.inherit_yaml_variables(
from: root_variables,
to: transform_to_yaml_variables(job[:job_variables]),
inheritance: job.fetch(:root_variables_inheritance, true)
)
end
def stage_for(job_name)
job = jobs.fetch(job_name)
job[:stage]
end
private
def variables
......
......@@ -39,6 +39,45 @@ module Gitlab
expect(expanded_config).to include(*included_config.keys)
end
end
describe '#yaml_variables_for' do
let(:config_content) do
<<~YAML
variables:
VAR1: value 1
VAR2: value 2
job:
script: echo 'hello'
variables:
VAR1: value 11
YAML
end
subject(:yaml_variables_for) { result.yaml_variables_for(:job) }
it do
is_expected.to match_array([
{ key: 'VAR1', value: 'value 11', public: true },
{ key: 'VAR2', value: 'value 2', public: true }
])
end
end
describe '#stage_for' do
let(:config_content) do
<<~YAML
job:
script: echo 'hello'
YAML
end
subject(:stage_for) { result.stage_for(:job) }
it do
is_expected.to eq('test')
end
end
end
end
end
......
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