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
f811f67c
Commit
f811f67c
authored
Oct 06, 2021
by
Hordur Freyr Yngvason
Committed by
Mayra Cabrera
Oct 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add agent project authorizations to finder
parent
6d5147b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
5 deletions
+44
-5
ee/app/finders/clusters/agent_authorizations_finder.rb
ee/app/finders/clusters/agent_authorizations_finder.rb
+14
-1
ee/spec/finders/clusters/agent_authorizations_finder_spec.rb
ee/spec/finders/clusters/agent_authorizations_finder_spec.rb
+30
-4
No files found.
ee/app/finders/clusters/agent_authorizations_finder.rb
View file @
f811f67c
...
...
@@ -9,7 +9,9 @@ module Clusters
def
execute
return
[]
unless
feature_available?
implicit_authorizations
+
group_authorizations
# closest, most-specific authorization for a given agent wins
(
project_authorizations
+
implicit_authorizations
+
group_authorizations
)
.
uniq
(
&
:agent_id
)
end
private
...
...
@@ -27,6 +29,17 @@ module Clusters
end
# rubocop: disable CodeReuse/ActiveRecord
def
project_authorizations
ancestor_ids
=
project
.
group
?
project
.
ancestors
.
select
(
:id
)
:
project
.
namespace_id
Clusters
::
Agents
::
ProjectAuthorization
.
where
(
project_id:
project
.
id
)
.
joins
(
agent: :project
)
.
preload
(
agent: :project
)
.
where
(
cluster_agents:
{
projects:
{
namespace_id:
ancestor_ids
}
})
.
to_a
end
def
group_authorizations
return
[]
unless
project
.
group
...
...
ee/spec/finders/clusters/agent_authorizations_finder_spec.rb
View file @
f811f67c
...
...
@@ -29,15 +29,41 @@ RSpec.describe Clusters::AgentAuthorizationsFinder do
it
{
is_expected
.
to
be_empty
}
end
describe
'project authorizations'
do
context
'agent configuration project does not share a root namespace with the given project'
do
let
(
:unrelated_agent
)
{
create
(
:cluster_agent
)
}
before
do
create
(
:agent_project_authorization
,
agent:
unrelated_agent
,
project:
requesting_project
)
end
it
{
is_expected
.
to
be_empty
}
end
context
'with project authorizations present'
do
let!
(
:authorization
)
{
create
(
:agent_project_authorization
,
agent:
production_agent
,
project:
requesting_project
)
}
it
{
is_expected
.
to
match_array
[
authorization
]
}
end
context
'with overlapping authorizations'
do
let!
(
:agent
)
{
create
(
:cluster_agent
,
project:
requesting_project
)
}
let!
(
:project_authorization
)
{
create
(
:agent_project_authorization
,
agent:
agent
,
project:
requesting_project
)
}
let!
(
:group_authorization
)
{
create
(
:agent_group_authorization
,
agent:
agent
,
group:
bottom_level_group
)
}
it
{
is_expected
.
to
match_array
[
project_authorization
]
}
end
end
describe
'implicit authorizations'
do
let!
(
:associated_agent
)
{
create
(
:cluster_agent
,
project:
requesting_project
)
}
it
'returns author
a
zations for agents directly associated with the project'
do
it
'returns author
i
zations for agents directly associated with the project'
do
expect
(
subject
.
count
).
to
eq
(
1
)
author
a
zation
=
subject
.
first
expect
(
author
a
zation
).
to
be_a
(
Clusters
::
Agents
::
ImplicitAuthorization
)
expect
(
author
a
zation
.
agent
).
to
eq
(
associated_agent
)
author
i
zation
=
subject
.
first
expect
(
author
i
zation
).
to
be_a
(
Clusters
::
Agents
::
ImplicitAuthorization
)
expect
(
author
i
zation
.
agent
).
to
eq
(
associated_agent
)
end
end
...
...
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