Commit e3a29f0a authored by Kerri Miller's avatar Kerri Miller

Merge branch 'sh-pvs-add-provisioning-group' into 'master'

Add provisioning group to pipeline validation payload

See merge request gitlab-org/gitlab!63606
parents dce513a5 43d8c865
......@@ -128,6 +128,17 @@ required number of seconds.
"plan": { "type": "string" },
"trial": { "type": "boolean" }
}
},
"provisioning_group": {
"type": "object",
"required": [
"plan",
"trial"
],
"properties": {
"plan": { "type": "string" },
"trial": { "type": "boolean" }
}
}
}
}
......
......@@ -8,6 +8,7 @@ module EE
module Validate
module External
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private
......@@ -15,12 +16,34 @@ module EE
override :validation_service_payload
def validation_service_payload
super.deep_merge(
namespace: {
plan: namespace.actual_plan_name,
trial: namespace.root_ancestor.trial_active?
super.deep_merge(namespace_payload.merge(provisioning_group_payload))
end
def namespace_payload
{
namespace: plan_and_trial_payload(namespace)
}
end
def provisioning_group_payload
return {} unless provisioning_group
{
provisioning_group: plan_and_trial_payload(provisioning_group)
}
end
def provisioning_group
strong_memoize(:provisioning_group) do
current_user.provisioned_by_group
end
end
def plan_and_trial_payload(group_or_namespace)
{
plan: group_or_namespace.actual_plan_name,
trial: group_or_namespace.root_ancestor.trial_active?
}
)
end
end
end
......
......@@ -17,6 +17,17 @@
"plan": { "type": "string" },
"trial": { "type": "boolean" }
}
},
"provisioning_group": {
"type": "object",
"required": [
"plan",
"trial"
],
"properties": {
"plan": { "type": "string" },
"trial": { "type": "boolean" }
}
}
}
}
......
......@@ -65,13 +65,36 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
it 'returns an Ultimate plan on trial' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
expect(params[:body]).to match_schema('/external_validation', dir: 'ee')
payload = Gitlab::Json.parse(params[:body])
expect(payload.dig('namespace', 'plan')).to eq('ultimate')
expect(payload.dig('namespace', 'trial')).to be true
expect(payload.dig('provisioning_group')).be_nil
end
step.perform!
end
context 'when user is provisioned by group' do
let(:user) { create(:user) }
before do
user.provisioned_by_group = group
end
it 'returns the provisioned group with an Ultimate plan' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
expect(params[:body]).to match_schema('/external_validation', dir: 'ee')
payload = Gitlab::Json.parse(params[:body])
expect(payload.dig('provisioning_group', 'plan')).to eq('ultimate')
expect(payload.dig('provisioning_group', 'trial')).to be true
end
step.perform!
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