Class: DeployToken
Constant Summary
collapse
- AVAILABLE_SCOPES =
%i(read_repository read_registry write_registry
read_package_registry write_package_registry).freeze
- GITLAB_DEPLOY_TOKEN_NAME =
'gitlab-deploy-token'
- REQUIRED_DEPENDENCY_PROXY_SCOPES =
%i[read_registry write_registry].freeze
Constants included
from Expirable
Expirable::DAYS_TO_EXPIRE
ApplicationRecord::MAX_PLUCK
Class Method Summary
collapse
Instance Method Summary
collapse
#clear_memoization, #strong_memoize, #strong_memoized?
#access_locked?, #admin?, #alert_bot?, #automation_bot?, #blocked?, #can?, #can_create_group, #can_read_all_resources?, #confirmation_required_on_sign_in?, #external?, #from_ci_job_token?, #internal?, #password_expired_if_applicable?, #preferred_language, #required_terms_not_accepted?, #requires_ldap_check?, #security_bot?, #support_bot?, #try_obtain_ldap_lease
Methods included from Expirable
#expires?, #expires_soon?
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!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.gitlab_deploy_token ⇒ Object
51
52
53
|
# File 'app/models/deploy_token.rb', line 51
def self.gitlab_deploy_token
active.find_by(name: GITLAB_DEPLOY_TOKEN_NAME)
end
|
Instance Method Details
#accessible_projects ⇒ Object
111
112
113
114
115
116
117
|
# File 'app/models/deploy_token.rb', line 111
def accessible_projects
if project_type?
projects
elsif group_type?
group.all_projects
end
end
|
#active? ⇒ Boolean
65
66
67
|
# File 'app/models/deploy_token.rb', line 65
def active?
!revoked && !expired?
end
|
#deactivated? ⇒ Boolean
69
70
71
|
# File 'app/models/deploy_token.rb', line 69
def deactivated?
!active?
end
|
#expires_at ⇒ Object
133
134
135
136
|
# File 'app/models/deploy_token.rb', line 133
def expires_at
expires_at = read_attribute(:expires_at)
expires_at != Forever.date ? expires_at : nil
end
|
#expires_at=(value) ⇒ Object
138
139
140
|
# File 'app/models/deploy_token.rb', line 138
def expires_at=(value)
write_attribute(:expires_at, value.presence || Forever.date)
end
|
#group ⇒ Object
105
106
107
108
109
|
# File 'app/models/deploy_token.rb', line 105
def group
strong_memoize(:group) do
groups.first
end
end
|
#has_access_to?(requested_project) ⇒ Boolean
81
82
83
84
85
86
|
# File 'app/models/deploy_token.rb', line 81
def has_access_to?(requested_project)
return false unless active?
return false unless holder
holder.has_access_to?(requested_project)
end
|
#has_access_to_group?(requested_group) ⇒ Boolean
88
89
90
91
92
93
94
|
# File 'app/models/deploy_token.rb', line 88
def has_access_to_group?(requested_group)
return false unless active?
return false unless group_type?
return false unless holder
holder.has_access_to_group?(requested_group)
end
|
#holder ⇒ Object
119
120
121
122
123
124
125
126
127
|
# File 'app/models/deploy_token.rb', line 119
def holder
strong_memoize(:holder) do
if project_type?
project_deploy_tokens.first
elsif group_type?
group_deploy_tokens.first
end
end
end
|
#impersonated? ⇒ Boolean
129
130
131
|
# File 'app/models/deploy_token.rb', line 129
def impersonated?
false
end
|
#project ⇒ Object
This is temporal. Currently we limit DeployToken to a single project or group, later we're going to extend that to be for multiple projects and namespaces.
99
100
101
102
103
|
# File 'app/models/deploy_token.rb', line 99
def project
strong_memoize(:project) do
projects.first
end
end
|
#revoke! ⇒ Object
61
62
63
|
# File 'app/models/deploy_token.rb', line 61
def revoke!
update!(revoked: true)
end
|
#scopes ⇒ Object
73
74
75
|
# File 'app/models/deploy_token.rb', line 73
def scopes
AVAILABLE_SCOPES.select { |token_scope| read_attribute(token_scope) }
end
|
#username ⇒ Object
77
78
79
|
# File 'app/models/deploy_token.rb', line 77
def username
super || default_username
end
|
#valid_for_dependency_proxy? ⇒ Boolean
55
56
57
58
59
|
# File 'app/models/deploy_token.rb', line 55
def valid_for_dependency_proxy?
group_type? &&
active? &&
REQUIRED_DEPENDENCY_PROXY_SCOPES.all? { |scope| scope.in?(scopes) }
end
|