Class: Ci::JobToken::Allowlist

Inherits:
Object
  • Object
show all
Defined in:
app/models/ci/job_token/allowlist.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_project, direction: :inbound) ⇒ Allowlist

Returns a new instance of Allowlist.



5
6
7
8
# File 'app/models/ci/job_token/allowlist.rb', line 5

def initialize(source_project, direction: :inbound)
  @source_project = source_project
  @direction = direction
end

Instance Method Details

#add!(target_project, user:, policies: []) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/ci/job_token/allowlist.rb', line 33

def add!(target_project, user:, policies: [])
  job_token_policies = add_policies_to_ci_job_token_enabled ? policies : []

  Ci::JobToken::ProjectScopeLink.create!(
    source_project: @source_project,
    direction: @direction,
    target_project: target_project,
    added_by: user,
    job_token_policies: job_token_policies
  )
end

#add_group!(target_group, user:, policies: []) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'app/models/ci/job_token/allowlist.rb', line 45

def add_group!(target_group, user:, policies: [])
  job_token_policies = add_policies_to_ci_job_token_enabled ? policies : []

  Ci::JobToken::GroupScopeLink.create!(
    source_project: @source_project,
    target_group: target_group,
    added_by: user,
    job_token_policies: job_token_policies
  )
end

#groupsObject



29
30
31
# File 'app/models/ci/job_token/allowlist.rb', line 29

def groups
  ::Group.id_in(group_links.pluck(:target_group_id))
end

#includes_group?(target_project) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/ci/job_token/allowlist.rb', line 16

def includes_group?(target_project)
  group_links_for_target(target_project).any?
end

#includes_project?(target_project) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'app/models/ci/job_token/allowlist.rb', line 10

def includes_project?(target_project)
  source_links
    .with_target(target_project)
    .exists?
end

#nearest_scope_for_target_project(target_project) ⇒ Object



20
21
22
23
# File 'app/models/ci/job_token/allowlist.rb', line 20

def nearest_scope_for_target_project(target_project)
  source_links.with_target(target_project).first ||
    group_links_for_target(target_project).first
end

#projectsObject



25
26
27
# File 'app/models/ci/job_token/allowlist.rb', line 25

def projects
  Project.from_union(target_projects, remove_duplicates: false)
end