debian-mirror-gitlab/lib/api/settings.rb

260 lines
22 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
module API
2021-01-03 14:25:43 +05:30
class Settings < ::API::Base
2015-09-11 14:41:01 +05:30
before { authenticated_as_admin! }
2022-06-21 17:19:12 +05:30
feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
2021-01-29 00:20:46 +05:30
2019-09-04 21:01:54 +05:30
helpers Helpers::SettingsHelpers
2015-09-11 14:41:01 +05:30
helpers do
def current_settings
2021-03-11 19:13:27 +05:30
@current_setting ||= ApplicationSetting.find_or_create_without_cache
2015-09-11 14:41:01 +05:30
end
2019-07-07 11:18:12 +05:30
def filter_attributes_using_license(attrs)
# This method will be redefined in EE.
attrs
end
2015-09-11 14:41:01 +05:30
end
2017-08-17 22:00:37 +05:30
desc 'Get the current application settings' do
success Entities::ApplicationSetting
end
2015-09-11 14:41:01 +05:30
get "application/settings" do
present current_settings, with: Entities::ApplicationSetting
end
2017-08-17 22:00:37 +05:30
desc 'Modify application settings' do
success Entities::ApplicationSetting
end
params do
2021-04-29 21:17:54 +05:30
optional :admin_mode, type: Boolean, desc: 'Require admin users to re-authenticate for administrative (i.e. potentially dangerous) operations'
2021-01-03 14:25:43 +05:30
optional :admin_notification_email, type: String, desc: 'Deprecated: Use :abuse_notification_email instead. Abuse reports will be sent to this address if it is set. Abuse reports are always available in the admin area.'
optional :abuse_notification_email, type: String, desc: 'Abuse reports will be sent to this address if it is set. Abuse reports are always available in the admin area.'
2018-11-18 11:00:15 +05:30
optional :after_sign_up_text, type: String, desc: 'Text shown after sign up'
optional :after_sign_out_path, type: String, desc: 'We will redirect users to this page after they sign out'
optional :akismet_enabled, type: Boolean, desc: 'Helps prevent bots from creating issues'
given akismet_enabled: ->(val) { val } do
requires :akismet_api_key, type: String, desc: 'Generate API key at http://www.akismet.com'
end
2019-09-04 21:01:54 +05:30
optional :asset_proxy_enabled, type: Boolean, desc: 'Enable proxying of assets'
optional :asset_proxy_url, type: String, desc: 'URL of the asset proxy server'
optional :asset_proxy_secret_key, type: String, desc: 'Shared secret with the asset proxy server'
2021-03-11 19:13:27 +05:30
optional :asset_proxy_whitelist, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Deprecated: Use :asset_proxy_allowlist instead. Assets that match these domain(s) will NOT be proxied. Wildcards allowed. Your GitLab installation URL is automatically whitelisted.'
optional :asset_proxy_allowlist, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Assets that match these domain(s) will NOT be proxied. Wildcards allowed. Your GitLab installation URL is automatically allowed.'
2018-11-18 11:00:15 +05:30
optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
optional :default_artifacts_expire_in, type: String, desc: "Set the default expiration time for each job's artifacts"
2021-09-04 01:27:46 +05:30
optional :default_ci_config_path, type: String, desc: 'The instance default CI/CD configuration file and path for new projects'
2019-07-07 11:18:12 +05:30
optional :default_project_creation, type: Integer, values: ::Gitlab::Access.project_creation_values, desc: 'Determine if developers can create projects in the group'
2021-10-27 15:23:28 +05:30
optional :default_branch_protection, type: Integer, values: ::Gitlab::Access.protection_values, desc: 'Determine if developers can push to default branch'
2018-11-18 11:00:15 +05:30
optional :default_group_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default group visibility'
2017-08-17 22:00:37 +05:30
optional :default_project_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default project visibility'
2018-11-18 11:00:15 +05:30
optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects'
2017-08-17 22:00:37 +05:30
optional :default_snippet_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default snippet visibility'
2021-02-22 17:27:13 +05:30
optional :disable_feed_token, type: Boolean, desc: 'Disable display of RSS/Atom and Calendar `feed_tokens`'
2020-07-28 23:09:34 +05:30
optional :disabled_oauth_sign_in_sources, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Disable certain OAuth sign-in sources'
2021-01-29 00:20:46 +05:30
optional :domain_denylist_enabled, type: Boolean, desc: 'Enable domain denylist for sign ups'
optional :domain_denylist, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Users with e-mail addresses that match these domain(s) will NOT be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com'
optional :domain_allowlist, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'ONLY users with e-mail addresses that match these domain(s) will be able to sign-up. Wildcards allowed. Use separate lines for multiple entries. Ex: domain.com, *.domain.com'
2019-12-26 22:10:19 +05:30
optional :eks_integration_enabled, type: Boolean, desc: 'Enable integration with Amazon EKS'
given eks_integration_enabled: -> (val) { val } do
requires :eks_account_id, type: String, desc: 'Amazon account ID for EKS integration'
requires :eks_access_key_id, type: String, desc: 'Access key ID for the EKS integration IAM user'
requires :eks_secret_access_key, type: String, desc: 'Secret access key for the EKS integration IAM user'
end
2018-11-18 11:00:15 +05:30
optional :email_author_in_body, type: Boolean, desc: 'Some email servers do not support overriding the email sender name. Enable this option to include the name of the author of the issue, merge request or comment in the email body instead.'
optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.'
2020-11-24 15:15:51 +05:30
optional :gitpod_enabled, type: Boolean, desc: 'Enable Gitpod'
given gitpod_enabled: ->(val) { val } do
requires :gitpod_url, type: String, desc: 'The configured Gitpod instance URL'
end
2018-11-18 11:00:15 +05:30
optional :gitaly_timeout_default, type: Integer, desc: 'Default Gitaly timeout, in seconds. Set to 0 to disable timeouts.'
optional :gitaly_timeout_fast, type: Integer, desc: 'Gitaly fast operation timeout, in seconds. Set to 0 to disable timeouts.'
optional :gitaly_timeout_medium, type: Integer, desc: 'Medium Gitaly timeout, in seconds. Set to 0 to disable timeouts.'
2019-09-30 21:07:59 +05:30
optional :grafana_enabled, type: Boolean, desc: 'Enable Grafana'
optional :grafana_url, type: String, desc: 'Grafana URL'
2018-11-18 11:00:15 +05:30
optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled'
2017-09-10 17:25:29 +05:30
optional :help_page_hide_commercial_content, type: Boolean, desc: 'Hide marketing-related entries from help'
2019-09-30 21:07:59 +05:30
optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page and help dropdown'
2021-01-03 14:25:43 +05:30
optional :help_page_documentation_base_url, type: String, desc: 'Alternate documentation pages URL'
2018-11-18 11:00:15 +05:30
optional :help_page_text, type: String, desc: 'Custom text displayed on the help page'
optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page'
optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)'
given housekeeping_enabled: ->(val) { val } do
requires :housekeeping_full_repack_period, type: Integer, desc: "Number of Git pushes after which a full 'git repack' is run."
requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run."
requires :housekeeping_incremental_repack_period, type: Integer, desc: "Number of Git pushes after which an incremental 'git repack' is run."
end
optional :html_emails_enabled, type: Boolean, desc: 'By default GitLab sends emails in HTML and plain text formats so mail clients can choose what format to use. Disable this option if you only want to send emails in plain text format.'
2020-07-28 23:09:34 +05:30
optional :import_sources, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce,
values: %w[github bitbucket bitbucket_server gitlab google_code fogbugz git gitlab_project gitea manifest phabricator],
2018-11-18 11:00:15 +05:30
desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com'
2021-04-17 20:07:23 +05:30
optional :in_product_marketing_emails_enabled, type: Boolean, desc: 'By default, in-product marketing emails are enabled. To disable these emails, disable this option.'
2021-03-08 18:12:59 +05:30
optional :invisible_captcha_enabled, type: Boolean, desc: 'Enable Invisible Captcha spam detection during signup.'
2017-08-17 22:00:37 +05:30
optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts"
2018-11-18 11:00:15 +05:30
optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB'
2022-07-16 23:28:13 +05:30
optional :max_export_size, type: Integer, desc: 'Maximum export size in MB'
2020-06-23 00:09:42 +05:30
optional :max_import_size, type: Integer, desc: 'Maximum import size in MB'
2017-08-17 22:00:37 +05:30
optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
2022-10-11 01:57:18 +05:30
optional :max_pages_custom_domains_per_project, type: Integer, desc: 'Maximum number of GitLab Pages custom domains per project'
2020-05-24 23:13:21 +05:30
optional :metrics_method_call_threshold, type: Integer, desc: 'A method call is only tracked when it takes longer to complete than the given amount of milliseconds.'
2018-11-18 11:00:15 +05:30
optional :password_authentication_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' # support legacy names, can be removed in v5
optional :password_authentication_enabled_for_web, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface'
mutually_exclusive :password_authentication_enabled_for_web, :password_authentication_enabled, :signin_enabled
optional :password_authentication_enabled_for_git, type: Boolean, desc: 'Flag indicating if password authentication is enabled for Git over HTTP(S)'
optional :performance_bar_allowed_group_id, type: String, desc: 'Deprecated: Use :performance_bar_allowed_group_path instead. Path of the group that is allowed to toggle the performance bar.' # support legacy names, can be removed in v6
optional :performance_bar_allowed_group_path, type: String, desc: 'Path of the group that is allowed to toggle the performance bar.'
optional :performance_bar_enabled, type: String, desc: 'Deprecated: Pass `performance_bar_allowed_group_path: nil` instead. Allow enabling the performance.' # support legacy names, can be removed in v6
2021-02-22 17:27:13 +05:30
optional :personal_access_token_prefix, type: String, desc: 'Prefix to prepend to all personal access tokens'
optional :kroki_enabled, type: Boolean, desc: 'Enable Kroki'
given kroki_enabled: ->(val) { val } do
requires :kroki_url, type: String, desc: 'The Kroki server URL'
end
2018-11-18 11:00:15 +05:30
optional :plantuml_enabled, type: Boolean, desc: 'Enable PlantUML'
given plantuml_enabled: ->(val) { val } do
requires :plantuml_url, type: String, desc: 'The PlantUML server URL'
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.'
optional :project_export_enabled, type: Boolean, desc: 'Enable project export'
optional :prometheus_metrics_enabled, type: Boolean, desc: 'Enable Prometheus metrics'
2019-12-21 20:55:43 +05:30
optional :push_event_hooks_limit, type: Integer, desc: "Number of changes (branches or tags) in a single push to determine whether webhooks and services will be fired or not. Webhooks and services won't be submitted if it surpasses that value."
optional :push_event_activities_limit, type: Integer, desc: 'Number of changes (branches or tags) in a single push to determine whether individual push events or bulk push event will be created. Bulk push event will be created if it surpasses that value.'
2017-08-17 22:00:37 +05:30
optional :recaptcha_enabled, type: Boolean, desc: 'Helps prevent bots from creating accounts'
given recaptcha_enabled: ->(val) { val } do
requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha'
requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
end
2019-09-04 21:01:54 +05:30
optional :login_recaptcha_protection_enabled, type: Boolean, desc: 'Helps prevent brute-force attacks'
given login_recaptcha_protection_enabled: ->(val) { val } do
requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha'
requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
end
2018-11-18 11:00:15 +05:30
optional :repository_checks_enabled, type: Boolean, desc: "GitLab will periodically run 'git fsck' in all project and wiki repositories to look for silent disk corruption issues."
2022-11-25 23:54:43 +05:30
optional :repository_storages_weighted, type: Hash, coerce_with: Validations::Types::HashOfIntegerValues.coerce, desc: 'Storage paths for new projects with a weighted value ranging from 0 to 100', documentation: { type: 'Object', additional_properties: Integer }
2018-12-05 23:21:45 +05:30
optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users to set up Two-factor authentication'
2018-11-18 11:00:15 +05:30
given require_two_factor_authentication: ->(val) { val } do
requires :two_factor_grace_period, type: Integer, desc: 'Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication'
2017-08-17 22:00:37 +05:30
end
2020-07-28 23:09:34 +05:30
optional :restricted_visibility_levels, type: Array[String], coerce_with: Validations::Types::CommaSeparatedToArray.coerce, desc: 'Selected levels cannot be used by non-admin users for groups, projects or snippets. If the public level is restricted, user profiles are only visible to logged in users.'
2018-11-18 11:00:15 +05:30
optional :send_user_confirmation_email, type: Boolean, desc: 'Send confirmation email on sign-up'
optional :session_expire_delay, type: Integer, desc: 'Session duration in minutes. GitLab restart is required to apply changes.'
optional :shared_runners_enabled, type: Boolean, desc: 'Enable shared runners for new projects'
given shared_runners_enabled: ->(val) { val } do
requires :shared_runners_text, type: String, desc: 'Shared runners text '
2017-08-17 22:00:37 +05:30
end
2018-11-18 11:00:15 +05:30
optional :sign_in_text, type: String, desc: 'The sign in text of the GitLab application'
optional :signin_enabled, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface' # support legacy names, can be removed in v5
optional :signup_enabled, type: Boolean, desc: 'Flag indicating if sign up is enabled'
2019-12-26 22:10:19 +05:30
optional :sourcegraph_enabled, type: Boolean, desc: 'Enable Sourcegraph'
optional :sourcegraph_public_only, type: Boolean, desc: 'Only allow public projects to communicate with Sourcegraph'
given sourcegraph_enabled: ->(val) { val } do
requires :sourcegraph_url, type: String, desc: 'The configured Sourcegraph instance URL'
end
2020-06-23 00:09:42 +05:30
optional :spam_check_endpoint_enabled, type: Boolean, desc: 'Enable Spam Check via external API endpoint'
given spam_check_endpoint_enabled: ->(val) { val } do
requires :spam_check_endpoint_url, type: String, desc: 'The URL of the external Spam Check service endpoint'
end
2017-08-17 22:00:37 +05:30
optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
2018-11-08 19:23:39 +05:30
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
2019-09-04 21:01:54 +05:30
optional :local_markdown_version, type: Integer, desc: 'Local markdown version, increase this value when any cached markdown should be invalidated'
2019-10-12 21:52:04 +05:30
optional :allow_local_requests_from_hooks_and_services, type: Boolean, desc: 'Deprecated: Use :allow_local_requests_from_web_hooks_and_services instead. Allow requests to the local network from hooks and services.' # support legacy names, can be removed in v5
2021-09-30 23:02:18 +05:30
optional :mailgun_events_enabled, type: Grape::API::Boolean, desc: 'Enable Mailgun event receiver'
given mailgun_events_enabled: ->(val) { val } do
requires :mailgun_signing_key, type: String, desc: 'The Mailgun HTTP webhook signing key for receiving events from webhook'
end
2019-10-12 21:52:04 +05:30
optional :snowplow_enabled, type: Grape::API::Boolean, desc: 'Enable Snowplow tracking'
given snowplow_enabled: ->(val) { val } do
requires :snowplow_collector_hostname, type: String, desc: 'The Snowplow collector hostname'
optional :snowplow_cookie_domain, type: String, desc: 'The Snowplow cookie domain'
2019-12-26 22:10:19 +05:30
optional :snowplow_app_id, type: String, desc: 'The Snowplow site name / application id'
2019-10-12 21:52:04 +05:30
end
2020-05-24 23:13:21 +05:30
optional :issues_create_limit, type: Integer, desc: "Maximum number of issue creation requests allowed per minute per user. Set to 0 for unlimited requests per minute."
optional :raw_blob_request_limit, type: Integer, desc: "Maximum number of requests per minute for each raw path. Set to 0 for unlimited requests per minute."
2020-11-24 15:15:51 +05:30
optional :wiki_page_max_content_bytes, type: Integer, desc: "Maximum wiki page content size in bytes"
2021-01-29 00:20:46 +05:30
optional :require_admin_approval_after_user_signup, type: Boolean, desc: 'Require explicit admin approval for new signups'
2021-06-08 01:23:25 +05:30
optional :whats_new_variant, type: String, values: ApplicationSetting.whats_new_variants.keys, desc: "What's new variant, possible values: `all_tiers`, `current_tier`, and `disabled`."
optional :floc_enabled, type: Grape::API::Boolean, desc: 'Enable FloC (Federated Learning of Cohorts)'
2021-11-11 11:23:49 +05:30
optional :user_deactivation_emails_enabled, type: Boolean, desc: 'Send emails to users upon account deactivation'
2021-11-18 22:05:49 +05:30
optional :suggest_pipeline_enabled, type: Boolean, desc: 'Enable pipeline suggestion banner'
2022-04-04 11:22:00 +05:30
optional :users_get_by_id_limit, type: Integer, desc: "Maximum number of calls to the /users/:id API per 10 minutes per user. Set to 0 for unlimited requests."
optional :runner_token_expiration_interval, type: Integer, desc: 'Token expiration interval for shared runners, in seconds'
optional :group_runner_token_expiration_interval, type: Integer, desc: 'Token expiration interval for group runners, in seconds'
optional :project_runner_token_expiration_interval, type: Integer, desc: 'Token expiration interval for project runners, in seconds'
2022-07-16 23:28:13 +05:30
optional :pipeline_limit_per_project_user_sha, type: Integer, desc: "Maximum number of pipeline creation requests allowed per minute per user and commit. Set to 0 for unlimited requests per minute."
2018-03-17 18:26:18 +05:30
2022-06-21 17:19:12 +05:30
Gitlab::SSHPublicKey.supported_types.each do |type|
2018-03-17 18:26:18 +05:30
optional :"#{type}_key_restriction",
type: Integer,
values: KeyRestrictionValidator.supported_key_restrictions(type),
desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys."
end
2017-08-17 22:00:37 +05:30
2019-09-04 21:01:54 +05:30
use :optional_params_ee
2018-11-08 19:23:39 +05:30
2019-09-04 21:01:54 +05:30
optional(*Helpers::SettingsHelpers.optional_attributes)
at_least_one_of(*Helpers::SettingsHelpers.optional_attributes)
2017-08-17 22:00:37 +05:30
end
2015-09-11 14:41:01 +05:30
put "application/settings" do
2017-08-17 22:00:37 +05:30
attrs = declared_params(include_missing: false)
2015-09-11 14:41:01 +05:30
2018-11-08 19:23:39 +05:30
# support legacy names, can be removed in v6
if attrs.has_key?(:performance_bar_allowed_group_id)
attrs[:performance_bar_allowed_group_path] = attrs.delete(:performance_bar_allowed_group_id)
end
# support legacy names, can be removed in v6
if attrs.has_key?(:performance_bar_enabled)
performance_bar_enabled = attrs.delete(:performance_bar_allowed_group_id)
attrs[:performance_bar_allowed_group_path] = nil unless performance_bar_enabled
end
2018-03-17 18:26:18 +05:30
# support legacy names, can be removed in v5
2017-09-10 17:25:29 +05:30
if attrs.has_key?(:signin_enabled)
2018-03-17 18:26:18 +05:30
attrs[:password_authentication_enabled_for_web] = attrs.delete(:signin_enabled)
elsif attrs.has_key?(:password_authentication_enabled)
attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled)
2017-09-10 17:25:29 +05:30
end
2019-10-12 21:52:04 +05:30
# support legacy names, can be removed in v5
if attrs.has_key?(:allow_local_requests_from_hooks_and_services)
attrs[:allow_local_requests_from_web_hooks_and_services] = attrs.delete(:allow_local_requests_from_hooks_and_services)
end
2021-01-03 14:25:43 +05:30
# support legacy names, can be removed in v5
if attrs.has_key?(:admin_notification_email)
attrs[:abuse_notification_email] = attrs.delete(:admin_notification_email)
end
2021-03-11 19:13:27 +05:30
# support legacy names, can be removed in v5
if attrs.has_key?(:asset_proxy_whitelist)
attrs[:asset_proxy_allowlist] = attrs.delete(:asset_proxy_whitelist)
end
2021-11-11 11:23:49 +05:30
# Also accept these attributes under their new names.
#
# TODO: Once we rename the columns, we have to swap this around and keep supporting the old names until v5.
# https://gitlab.com/gitlab-org/gitlab/-/issues/340031
%w[enabled period_in_seconds requests_per_period].each do |suffix|
old_name = :"throttle_unauthenticated_#{suffix}"
new_name = :"throttle_unauthenticated_web_#{suffix}"
attrs[old_name] = attrs.delete(new_name) if attrs.has_key?(new_name)
end
2020-05-24 23:13:21 +05:30
# since 13.0 it's not possible to disable hashed storage - support can be removed in 14.0
attrs.delete(:hashed_storage_enabled) if attrs.has_key?(:hashed_storage_enabled)
2019-07-07 11:18:12 +05:30
attrs = filter_attributes_using_license(attrs)
2018-03-27 19:54:05 +05:30
if ApplicationSettings::UpdateService.new(current_settings, current_user, attrs).execute
2015-09-11 14:41:01 +05:30
present current_settings, with: Entities::ApplicationSetting
else
render_validation_error!(current_settings)
end
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
API::Settings.prepend_mod_with('API::Settings')