Class: PagesDomain
Constant Summary
collapse
- VERIFICATION_KEY =
'gitlab-pages-verification-code'
- VERIFICATION_THRESHOLD =
3.days.freeze
- SSL_RENEWAL_THRESHOLD =
30.days.freeze
- MAX_CERTIFICATE_KEY_LENGTH =
8192
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
#run_after_commit, #run_after_commit_or_now
#present
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
.find_by_domain_case_insensitive(domain) ⇒ Object
79
80
81
|
# File 'app/models/pages_domain.rb', line 79
def self.find_by_domain_case_insensitive(domain)
find_by("LOWER(domain) = LOWER(?)", domain)
end
|
.ids_for_project(project_id) ⇒ Object
83
84
85
|
# File 'app/models/pages_domain.rb', line 83
def self.ids_for_project(project_id)
where(project_id: project_id).ids
end
|
Instance Method Details
#certificate=(certificate) ⇒ Object
182
183
184
185
186
187
188
|
# File 'app/models/pages_domain.rb', line 182
def certificate=(certificate)
super(certificate)
self.certificate_valid_not_before = x509&.not_before
self.certificate_valid_not_after = x509&.not_after
end
|
#certificate_text ⇒ Object
160
161
162
|
# File 'app/models/pages_domain.rb', line 160
def certificate_text
@certificate_text ||= x509.try(:to_text)
end
|
#clear_auto_ssl_failure ⇒ Object
218
219
220
|
# File 'app/models/pages_domain.rb', line 218
def clear_auto_ssl_failure
self.auto_ssl_failed = false
end
|
#enabled? ⇒ Boolean
95
96
97
|
# File 'app/models/pages_domain.rb', line 95
def enabled?
!Gitlab::CurrentSettings.pages_domain_verification_enabled? || enabled_until.present?
end
|
#expiration ⇒ Object
150
151
152
|
# File 'app/models/pages_domain.rb', line 150
def expiration
x509&.not_after
end
|
#expired? ⇒ Boolean
143
144
145
146
147
148
|
# File 'app/models/pages_domain.rb', line 143
def expired?
return false unless x509
current = Time.current
current < x509.not_before || x509.not_after < current
end
|
#gitlab_provided_certificate=(certificate) ⇒ Object
208
209
210
211
|
# File 'app/models/pages_domain.rb', line 208
def gitlab_provided_certificate=(certificate)
self.certificate = certificate
self.certificate_source = 'gitlab_provided' if certificate_changed?
end
|
#gitlab_provided_key=(key) ⇒ Object
213
214
215
216
|
# File 'app/models/pages_domain.rb', line 213
def gitlab_provided_key=(key)
self.key = key
self.certificate_source = 'gitlab_provided' if attribute_changed?(:key)
end
|
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'app/models/pages_domain.rb', line 125
def has_intermediates?
return false unless x509
return true if x509.verify(x509.public_key)
store = OpenSSL::X509::Store.new
store.set_default_paths
store.verify(x509, untrusted_ca_certs_bundle)
rescue OpenSSL::X509::StoreError
false
end
|
#has_matching_key? ⇒ Boolean
117
118
119
120
121
122
123
|
# File 'app/models/pages_domain.rb', line 117
def has_matching_key?
return false unless x509
return false unless pkey
x509.check_private_key(pkey)
end
|
#https? ⇒ Boolean
99
100
101
|
# File 'app/models/pages_domain.rb', line 99
def https?
certificate.present?
end
|
#keyed_verification_code ⇒ Object
172
173
174
175
176
|
# File 'app/models/pages_domain.rb', line 172
def keyed_verification_code
return unless verification_code.present?
"#{VERIFICATION_KEY}=#{verification_code}"
end
|
#pages_deployed? ⇒ Boolean
232
233
234
235
236
|
# File 'app/models/pages_domain.rb', line 232
def pages_deployed?
return false unless project
project.pages_metadatum&.deployed?
end
|
#subject ⇒ Object
154
155
156
157
158
|
# File 'app/models/pages_domain.rb', line 154
def subject
return unless x509
x509.subject.to_s
end
|
#to_param ⇒ Object
103
104
105
|
# File 'app/models/pages_domain.rb', line 103
def to_param
domain
end
|
#untrusted_ca_certs_bundle ⇒ Object
#unverified? ⇒ Boolean
91
92
93
|
# File 'app/models/pages_domain.rb', line 91
def unverified?
!verified?
end
|
#url ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'app/models/pages_domain.rb', line 107
def url
return unless domain
if certificate.present?
"https://#{domain}"
else
"http://#{domain}"
end
end
|
#user_provided_certificate ⇒ Object
199
200
201
|
# File 'app/models/pages_domain.rb', line 199
def user_provided_certificate
certificate if certificate_user_provided?
end
|
#user_provided_certificate=(certificate) ⇒ Object
203
204
205
206
|
# File 'app/models/pages_domain.rb', line 203
def user_provided_certificate=(certificate)
self.certificate = certificate
self.certificate_source = 'user_provided' if certificate_changed?
end
|
#user_provided_key ⇒ Object
190
191
192
|
# File 'app/models/pages_domain.rb', line 190
def user_provided_key
key if certificate_user_provided?
end
|
#user_provided_key=(key) ⇒ Object
194
195
196
197
|
# File 'app/models/pages_domain.rb', line 194
def user_provided_key=(key)
self.key = key
self.certificate_source = 'user_provided' if attribute_changed?(:key)
end
|
#validate_custom_domain_count_per_project ⇒ Object
222
223
224
225
226
227
228
229
230
|
# File 'app/models/pages_domain.rb', line 222
def validate_custom_domain_count_per_project
return unless project
unless project.can_create_custom_domains?
self.errors.add(
:base,
_("This project reached the limit of custom domains. (Max %d)") % Gitlab::CurrentSettings.max_pages_custom_domains_per_project)
end
end
|
#verification_domain ⇒ Object
Verification codes may be TXT records for domain or verification_domain, to support the use of CNAME records on domain.
166
167
168
169
170
|
# File 'app/models/pages_domain.rb', line 166
def verification_domain
return unless domain.present?
"_#{VERIFICATION_KEY}.#{domain}"
end
|
#verification_record ⇒ Object
178
179
180
|
# File 'app/models/pages_domain.rb', line 178
def verification_record
"#{verification_domain} TXT #{keyed_verification_code}"
end
|
#verified? ⇒ Boolean
87
88
89
|
# File 'app/models/pages_domain.rb', line 87
def verified?
!!verified_at
end
|