Commit 629543bd authored by David Kim's avatar David Kim

Merge branch 'clarify-agent-auth-projects' into 'master'

Return the correct project in job/allowed_agents API response

See merge request gitlab-org/gitlab!71876
parents ff23f450 95364c46
...@@ -10,7 +10,9 @@ module Clusters ...@@ -10,7 +10,9 @@ module Clusters
validates :config, json_schema: { filename: 'cluster_agent_authorization_configuration' } validates :config, json_schema: { filename: 'cluster_agent_authorization_configuration' }
delegate :project, to: :agent def config_project
agent.project
end
end end
end end
end end
...@@ -6,12 +6,15 @@ module Clusters ...@@ -6,12 +6,15 @@ module Clusters
attr_reader :agent attr_reader :agent
delegate :id, to: :agent, prefix: true delegate :id, to: :agent, prefix: true
delegate :project, to: :agent
def initialize(agent:) def initialize(agent:)
@agent = agent @agent = agent
end end
def config_project
agent.project
end
def config def config
nil nil
end end
......
...@@ -9,6 +9,10 @@ module Clusters ...@@ -9,6 +9,10 @@ module Clusters
belongs_to :project, class_name: '::Project', optional: false belongs_to :project, class_name: '::Project', optional: false
validates :config, json_schema: { filename: 'cluster_agent_authorization_configuration' } validates :config, json_schema: { filename: 'cluster_agent_authorization_configuration' }
def config_project
agent.project
end
end end
end end
end end
...@@ -5,7 +5,7 @@ module API ...@@ -5,7 +5,7 @@ module API
module Clusters module Clusters
class AgentAuthorization < Grape::Entity class AgentAuthorization < Grape::Entity
expose :agent_id, as: :id expose :agent_id, as: :id
expose :project, with: Entities::ProjectIdentity, as: :config_project expose :config_project, with: Entities::ProjectIdentity
expose :config, as: :configuration expose :config, as: :configuration
end end
end end
......
...@@ -3,15 +3,34 @@ ...@@ -3,15 +3,34 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe API::Entities::Clusters::AgentAuthorization do RSpec.describe API::Entities::Clusters::AgentAuthorization do
let_it_be(:authorization) { create(:agent_group_authorization) }
subject { described_class.new(authorization).as_json } subject { described_class.new(authorization).as_json }
it 'includes basic fields' do shared_examples 'generic authorization' do
expect(subject).to include( it 'includes shared fields' do
id: authorization.agent_id, expect(subject).to include(
config_project: a_hash_including(id: authorization.agent.project_id), id: authorization.agent_id,
configuration: authorization.config config_project: a_hash_including(id: authorization.agent.project_id),
) configuration: authorization.config
)
end
end
context 'project authorization' do
let(:authorization) { create(:agent_project_authorization) }
include_examples 'generic authorization'
end
context 'group authorization' do
let(:authorization) { create(:agent_group_authorization) }
include_examples 'generic authorization'
end
context 'implicit authorization' do
let(:agent) { create(:cluster_agent) }
let(:authorization) { Clusters::Agents::ImplicitAuthorization.new(agent: agent) }
include_examples 'generic authorization'
end end
end end
...@@ -7,4 +7,10 @@ RSpec.describe Clusters::Agents::GroupAuthorization do ...@@ -7,4 +7,10 @@ RSpec.describe Clusters::Agents::GroupAuthorization do
it { is_expected.to belong_to(:group).class_name('::Group').required } it { is_expected.to belong_to(:group).class_name('::Group').required }
it { expect(described_class).to validate_jsonb_schema(['config']) } it { expect(described_class).to validate_jsonb_schema(['config']) }
describe '#config_project' do
let(:record) { create(:agent_group_authorization) }
it { expect(record.config_project).to eq(record.agent.project) }
end
end end
...@@ -9,6 +9,6 @@ RSpec.describe Clusters::Agents::ImplicitAuthorization do ...@@ -9,6 +9,6 @@ RSpec.describe Clusters::Agents::ImplicitAuthorization do
it { expect(subject.agent).to eq(agent) } it { expect(subject.agent).to eq(agent) }
it { expect(subject.agent_id).to eq(agent.id) } it { expect(subject.agent_id).to eq(agent.id) }
it { expect(subject.project).to eq(agent.project) } it { expect(subject.config_project).to eq(agent.project) }
it { expect(subject.config).to be_nil } it { expect(subject.config).to be_nil }
end end
...@@ -7,4 +7,10 @@ RSpec.describe Clusters::Agents::ProjectAuthorization do ...@@ -7,4 +7,10 @@ RSpec.describe Clusters::Agents::ProjectAuthorization do
it { is_expected.to belong_to(:project).class_name('Project').required } it { is_expected.to belong_to(:project).class_name('Project').required }
it { expect(described_class).to validate_jsonb_schema(['config']) } it { expect(described_class).to validate_jsonb_schema(['config']) }
describe '#config_project' do
let(:record) { create(:agent_project_authorization) }
it { expect(record.config_project).to eq(record.agent.project) }
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