... @@ -6,6 +6,9 @@ class ApplicationSetting < ApplicationRecord
... @@ -6,6 +6,9 @@ class ApplicationSetting < ApplicationRecord
include TokenAuthenticatable
include TokenAuthenticatable
include ChronicDurationAttribute
include ChronicDurationAttribute
GRAFANA_URL_ERROR_MESSAGE = 'Please check your Grafana URL setting in ' \
'Admin Area > Settings > Metrics and profiling > Metrics - Grafana'
add_authentication_token_field :runners_registration_token , encrypted: -> { Feature . enabled? ( :application_settings_tokens_optional_encryption , default_enabled: true ) ? :optional : :required }
add_authentication_token_field :runners_registration_token , encrypted: -> { Feature . enabled? ( :application_settings_tokens_optional_encryption , default_enabled: true ) ? :optional : :required }
add_authentication_token_field :health_check_access_token
add_authentication_token_field :health_check_access_token
add_authentication_token_field :static_objects_external_storage_auth_token
add_authentication_token_field :static_objects_external_storage_auth_token
... @@ -38,6 +41,14 @@ class ApplicationSetting < ApplicationRecord
... @@ -38,6 +41,14 @@ class ApplicationSetting < ApplicationRecord
chronic_duration_attr_writer :archive_builds_in_human_readable , :archive_builds_in_seconds
chronic_duration_attr_writer :archive_builds_in_human_readable , :archive_builds_in_seconds
validates :grafana_url ,
system_hook_url: {
blocked_message: "is blocked: %{exception_message}. " + GRAFANA_URL_ERROR_MESSAGE
},
if: :grafana_url_absolute?
validate :validate_grafana_url
validates :uuid , presence: true
validates :uuid , presence: true
validates :outbound_local_requests_whitelist ,
validates :outbound_local_requests_whitelist ,
... @@ -357,6 +368,19 @@ class ApplicationSetting < ApplicationRecord
... @@ -357,6 +368,19 @@ class ApplicationSetting < ApplicationRecord
end
end
after_commit :expire_performance_bar_allowed_user_ids_cache , if: -> { previous_changes . key? ( 'performance_bar_allowed_group_id' ) }
after_commit :expire_performance_bar_allowed_user_ids_cache , if: -> { previous_changes . key? ( 'performance_bar_allowed_group_id' ) }
def validate_grafana_url
unless parsed_grafana_url
self . errors . add (
:grafana_url ,
"must be a valid relative or absolute URL. #{ GRAFANA_URL_ERROR_MESSAGE } "
)
end
end
def grafana_url_absolute?
parsed_grafana_url & . absolute?
end
def sourcegraph_url_is_com?
def sourcegraph_url_is_com?
!! ( sourcegraph_url =~ /\Ahttps:\/\/(www\.)?sourcegraph\.com/ )
!! ( sourcegraph_url =~ /\Ahttps:\/\/(www\.)?sourcegraph\.com/ )
end
end
... @@ -381,6 +405,12 @@ class ApplicationSetting < ApplicationRecord
... @@ -381,6 +405,12 @@ class ApplicationSetting < ApplicationRecord
def recaptcha_or_login_protection_enabled
def recaptcha_or_login_protection_enabled
recaptcha_enabled || login_recaptcha_protection_enabled
recaptcha_enabled || login_recaptcha_protection_enabled
end
end
private
def parsed_grafana_url
@parsed_grafana_url ||= Gitlab :: Utils . parse_url ( grafana_url )
end
end
end
ApplicationSetting . prepend_if_ee ( 'EE::ApplicationSetting' )
ApplicationSetting . prepend_if_ee ( 'EE::ApplicationSetting' )