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

209 lines
17 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
2020-07-28 23:09:34 +05:30
class Settings < Grape::API::Instance
2015-09-11 14:41:01 +05:30
before { authenticated_as_admin! }
2019-09-04 21:01:54 +05:30
helpers Helpers::SettingsHelpers
2015-09-11 14:41:01 +05:30
helpers do
def current_settings
@current_setting ||=
2018-11-08 19:23:39 +05:30
(ApplicationSetting.current_without_cache || ApplicationSetting.create_from_defaults)
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
2018-11-18 11:00:15 +05:30
optional :admin_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.'
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'
optional :asset_proxy_whitelist, 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 whitelisted.'
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"
2019-12-26 22:10:19 +05:30
optional :default_ci_config_path, type: String, desc: 'The instance default CI configuration 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'
optional :default_branch_protection, type: Integer, values: ::Gitlab::Access.protection_values, desc: 'Determine if developers can push to master'
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'
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'
2017-08-17 22:00:37 +05:30
optional :domain_blacklist_enabled, type: Boolean, desc: 'Enable domain blacklist for sign ups'
2019-12-04 20:38:33 +05:30
optional :domain_blacklist, 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_whitelist, 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.'
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'
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_bitmaps_enabled, type: Boolean, desc: "Creating pack file bitmaps makes housekeeping take a little longer but bitmaps should accelerate 'git clone' performance."
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'
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'
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'
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
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."
2020-08-09 18:53:13 +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'
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.'
2018-11-18 11:00:15 +05:30
optional :instance_statistics_visibility_private, type: Boolean, desc: 'When set to `true` Instance statistics will only be available to admins'
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
optional :snowplow_enabled, type: Grape::API::Boolean, desc: 'Enable Snowplow tracking'
2019-12-26 22:10:19 +05:30
optional :snowplow_iglu_registry_url, type: String, desc: 'The Snowplow base Iglu Schema Registry URL to use for custom context and self describing events'
2019-10-12 21:52:04 +05:30
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."
2018-03-17 18:26:18 +05:30
ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type|
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
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
API::Settings.prepend_if_ee('EE::API::Settings')