Class: PagesDomain
Constant Summary
collapse
- VERIFICATION_KEY =
'gitlab-pages-verification-code'
- VERIFICATION_THRESHOLD =
3.days.freeze
- SSL_RENEWAL_THRESHOLD =
30.days.freeze
ApplicationRecord::MAX_PLUCK
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
78
79
80
|
# File 'app/models/pages_domain.rb', line 78
def self.find_by_domain_case_insensitive(domain)
find_by("LOWER(domain) = LOWER(?)", domain)
end
|
Instance Method Details
#certificate=(certificate) ⇒ Object
173
174
175
176
177
178
179
|
# File 'app/models/pages_domain.rb', line 173
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
155
156
157
|
# File 'app/models/pages_domain.rb', line 155
def certificate_text
@certificate_text ||= x509.try(:to_text)
end
|
#clear_auto_ssl_failure ⇒ Object
215
216
217
|
# File 'app/models/pages_domain.rb', line 215
def clear_auto_ssl_failure
self.auto_ssl_failed = false
end
|
#enabled? ⇒ Boolean
90
91
92
|
# File 'app/models/pages_domain.rb', line 90
def enabled?
!Gitlab::CurrentSettings.pages_domain_verification_enabled? || enabled_until.present?
end
|
#expiration ⇒ Object
145
146
147
|
# File 'app/models/pages_domain.rb', line 145
def expiration
x509&.not_after
end
|
#expired? ⇒ Boolean
138
139
140
141
142
143
|
# File 'app/models/pages_domain.rb', line 138
def expired?
return false unless x509
current = Time.current
current < x509.not_before || x509.not_after < current
end
|
#gitlab_provided_certificate=(certificate) ⇒ Object
199
200
201
202
|
# File 'app/models/pages_domain.rb', line 199
def gitlab_provided_certificate=(certificate)
self.certificate = certificate
self.certificate_source = 'gitlab_provided' if certificate_changed?
end
|
#gitlab_provided_key=(key) ⇒ Object
204
205
206
207
|
# File 'app/models/pages_domain.rb', line 204
def gitlab_provided_key=(key)
self.key = key
self.certificate_source = 'gitlab_provided' if attribute_changed?(:key)
end
|
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'app/models/pages_domain.rb', line 120
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
112
113
114
115
116
117
118
|
# File 'app/models/pages_domain.rb', line 112
def has_matching_key?
return false unless x509
return false unless pkey
x509.check_private_key(pkey)
end
|
#https? ⇒ Boolean
94
95
96
|
# File 'app/models/pages_domain.rb', line 94
def https?
certificate.present?
end
|
#keyed_verification_code ⇒ Object
167
168
169
170
171
|
# File 'app/models/pages_domain.rb', line 167
def keyed_verification_code
return unless verification_code.present?
"#{VERIFICATION_KEY}=#{verification_code}"
end
|
#pages_virtual_domain ⇒ Object
209
210
211
212
213
|
# File 'app/models/pages_domain.rb', line 209
def pages_virtual_domain
return unless pages_deployed?
Pages::VirtualDomain.new([project], domain: self)
end
|
#subject ⇒ Object
149
150
151
152
153
|
# File 'app/models/pages_domain.rb', line 149
def subject
return unless x509
x509.subject.to_s
end
|
#to_param ⇒ Object
98
99
100
|
# File 'app/models/pages_domain.rb', line 98
def to_param
domain
end
|
#untrusted_ca_certs_bundle ⇒ Object
#unverified? ⇒ Boolean
86
87
88
|
# File 'app/models/pages_domain.rb', line 86
def unverified?
!verified?
end
|
#url ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'app/models/pages_domain.rb', line 102
def url
return unless domain
if certificate.present?
"https://#{domain}"
else
"http://#{domain}"
end
end
|
#user_provided_certificate ⇒ Object
190
191
192
|
# File 'app/models/pages_domain.rb', line 190
def user_provided_certificate
certificate if certificate_user_provided?
end
|
#user_provided_certificate=(certificate) ⇒ Object
194
195
196
197
|
# File 'app/models/pages_domain.rb', line 194
def user_provided_certificate=(certificate)
self.certificate = certificate
self.certificate_source = 'user_provided' if certificate_changed?
end
|
#user_provided_key ⇒ Object
181
182
183
|
# File 'app/models/pages_domain.rb', line 181
def user_provided_key
key if certificate_user_provided?
end
|
#user_provided_key=(key) ⇒ Object
185
186
187
188
|
# File 'app/models/pages_domain.rb', line 185
def user_provided_key=(key)
self.key = key
self.certificate_source = 'user_provided' if attribute_changed?(:key)
end
|
#verification_domain ⇒ Object
Verification codes may be TXT records for domain or verification_domain, to support the use of CNAME records on domain.
161
162
163
164
165
|
# File 'app/models/pages_domain.rb', line 161
def verification_domain
return unless domain.present?
"_#{VERIFICATION_KEY}.#{domain}"
end
|
#verified? ⇒ Boolean
82
83
84
|
# File 'app/models/pages_domain.rb', line 82
def verified?
!!verified_at
end
|