Class: Clusters::Agent

Inherits:
ApplicationRecord show all
Includes:
FromUnion, Gitlab::Utils::StrongMemoize
Defined in:
app/models/clusters/agent.rb

Constant Summary collapse

INACTIVE_AFTER =
1.hour.freeze
ACTIVITY_EVENT_LIMIT =
200

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#activity_event_deletion_cutoffObject



56
57
58
59
60
61
# File 'app/models/clusters/agent.rb', line 56

def activity_event_deletion_cutoff
  # Order is defined by the association
  activity_events
    .offset(ACTIVITY_EVENT_LIMIT - 1)
    .pick(:recorded_at)
end

#ci_access_authorized_for?(user) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
# File 'app/models/clusters/agent.rb', line 67

def ci_access_authorized_for?(user)
  return false unless user

  all_ci_access_authorized_projects_for(user).exists? ||
    all_ci_access_authorized_namespaces_for(user).exists?
end

#connected?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/clusters/agent.rb', line 52

def connected?
  agent_tokens.connected.exists?
end

#has_access_to?(requested_project) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/clusters/agent.rb', line 48

def has_access_to?(requested_project)
  requested_project == project
end

#to_ability_nameObject



63
64
65
# File 'app/models/clusters/agent.rb', line 63

def to_ability_name
  :cluster
end

#user_access_authorized_for?(user) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'app/models/clusters/agent.rb', line 74

def user_access_authorized_for?(user)
  return false unless user

  Clusters::Agents::Authorizations::UserAccess::Finder
    .new(user, agent: self, preload: false, limit: 1).execute.any?
end

#user_access_configObject

As of today, all config values of associated authorization rows have the same value. See ‘UserAccess::RefreshService` for more information.



83
84
85
86
87
88
# File 'app/models/clusters/agent.rb', line 83

def user_access_config
  self.class.from_union(
    user_access_project_authorizations.select('config').limit(1),
    user_access_group_authorizations.select('config').limit(1)
  ).compact.first&.config
end