PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/api/settings.rb

https://bitbucket.org/terrchen/gitlab-ce
Ruby | 174 lines | 161 code | 10 blank | 3 comment | 7 complexity | 0a97fcda59a51c208641067e4aa3df2a MD5 | raw file
Possible License(s): Apache-2.0, CC0-1.0
  1. module API
  2. class Settings < Grape::API
  3. before { authenticated_as_admin! }
  4. helpers do
  5. def current_settings
  6. @current_setting ||=
  7. (ApplicationSetting.current_without_cache || ApplicationSetting.create_from_defaults)
  8. end
  9. end
  10. desc 'Get the current application settings' do
  11. success Entities::ApplicationSetting
  12. end
  13. get "application/settings" do
  14. present current_settings, with: Entities::ApplicationSetting
  15. end
  16. desc 'Modify application settings' do
  17. success Entities::ApplicationSetting
  18. end
  19. params do
  20. optional :default_branch_protection, type: Integer, values: [0, 1, 2], desc: 'Determine if developers can push to master'
  21. optional :default_project_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default project visibility'
  22. optional :default_snippet_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default snippet visibility'
  23. optional :default_group_visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The default group visibility'
  24. optional :restricted_visibility_levels, type: Array[String], 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.'
  25. optional :import_sources, type: Array[String], values: %w[github bitbucket gitlab google_code fogbugz git gitlab_project],
  26. desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com'
  27. optional :disabled_oauth_sign_in_sources, type: Array[String], desc: 'Disable certain OAuth sign-in sources'
  28. optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.'
  29. optional :project_export_enabled, type: Boolean, desc: 'Enable project export'
  30. optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled'
  31. optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects'
  32. optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB'
  33. optional :session_expire_delay, type: Integer, desc: 'Session duration in minutes. GitLab restart is required to apply changes.'
  34. optional :user_oauth_applications, type: Boolean, desc: 'Allow users to register any application to use GitLab as an OAuth provider'
  35. optional :user_default_external, type: Boolean, desc: 'Newly registered users will by default be external'
  36. optional :signup_enabled, type: Boolean, desc: 'Flag indicating if sign up is enabled'
  37. optional :send_user_confirmation_email, type: Boolean, desc: 'Send confirmation email on sign-up'
  38. optional :domain_whitelist, type: String, 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'
  39. optional :domain_blacklist_enabled, type: Boolean, desc: 'Enable domain blacklist for sign ups'
  40. given domain_blacklist_enabled: ->(val) { val } do
  41. requires :domain_blacklist, type: String, 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'
  42. end
  43. optional :after_sign_up_text, type: String, desc: 'Text shown after sign up'
  44. optional :password_authentication_enabled_for_web, type: Boolean, desc: 'Flag indicating if password authentication is enabled for the web interface'
  45. 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
  46. 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
  47. mutually_exclusive :password_authentication_enabled_for_web, :password_authentication_enabled, :signin_enabled
  48. optional :password_authentication_enabled_for_git, type: Boolean, desc: 'Flag indicating if password authentication is enabled for Git over HTTP(S)'
  49. optional :performance_bar_allowed_group_path, type: String, desc: 'Path of the group that is allowed to toggle the performance bar.'
  50. optional :performance_bar_allowed_group_id, type: String, desc: 'Depreated: 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
  51. 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
  52. optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users to setup Two-factor authentication'
  53. given require_two_factor_authentication: ->(val) { val } do
  54. 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'
  55. end
  56. optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page'
  57. optional :after_sign_out_path, type: String, desc: 'We will redirect users to this page after they sign out'
  58. optional :sign_in_text, type: String, desc: 'The sign in text of the GitLab application'
  59. optional :help_page_hide_commercial_content, type: Boolean, desc: 'Hide marketing-related entries from help'
  60. optional :help_page_text, type: String, desc: 'Custom text displayed on the help page'
  61. optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page'
  62. optional :shared_runners_enabled, type: Boolean, desc: 'Enable shared runners for new projects'
  63. given shared_runners_enabled: ->(val) { val } do
  64. requires :shared_runners_text, type: String, desc: 'Shared runners text '
  65. end
  66. optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts"
  67. optional :default_artifacts_expire_in, type: String, desc: "Set the default expiration time for each job's artifacts"
  68. optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
  69. optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
  70. optional :prometheus_metrics_enabled, type: Boolean, desc: 'Enable Prometheus metrics'
  71. optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'
  72. given metrics_enabled: ->(val) { val } do
  73. requires :metrics_host, type: String, desc: 'The InfluxDB host'
  74. requires :metrics_port, type: Integer, desc: 'The UDP port to use for connecting to InfluxDB'
  75. requires :metrics_pool_size, type: Integer, desc: 'The amount of InfluxDB connections to open'
  76. requires :metrics_timeout, type: Integer, desc: 'The amount of seconds after which an InfluxDB connection will time out'
  77. requires :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.'
  78. requires :metrics_sample_interval, type: Integer, desc: 'The sampling interval in seconds'
  79. requires :metrics_packet_size, type: Integer, desc: 'The amount of points to store in a single UDP packet'
  80. end
  81. optional :sidekiq_throttling_enabled, type: Boolean, desc: 'Enable Sidekiq Job Throttling'
  82. given sidekiq_throttling_enabled: ->(val) { val } do
  83. requires :sidekiq_throttling_queus, type: Array[String], desc: 'Choose which queues you wish to throttle'
  84. requires :sidekiq_throttling_factor, type: Float, desc: 'The factor by which the queues should be throttled. A value between 0.0 and 1.0, exclusive.'
  85. end
  86. optional :recaptcha_enabled, type: Boolean, desc: 'Helps prevent bots from creating accounts'
  87. given recaptcha_enabled: ->(val) { val } do
  88. requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha'
  89. requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
  90. end
  91. optional :akismet_enabled, type: Boolean, desc: 'Helps prevent bots from creating issues'
  92. given akismet_enabled: ->(val) { val } do
  93. requires :akismet_api_key, type: String, desc: 'Generate API key at http://www.akismet.com'
  94. end
  95. 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.'
  96. optional :sentry_enabled, type: Boolean, desc: 'Sentry is an error reporting and logging tool which is currently not shipped with GitLab, get it here: https://getsentry.com'
  97. given sentry_enabled: ->(val) { val } do
  98. requires :sentry_dsn, type: String, desc: 'Sentry Data Source Name'
  99. end
  100. optional :clientside_sentry_enabled, type: Boolean, desc: 'Sentry can also be used for reporting and logging clientside exceptions. https://sentry.io/for/javascript/'
  101. given clientside_sentry_enabled: ->(val) { val } do
  102. requires :clientside_sentry_dsn, type: String, desc: 'Clientside Sentry Data Source Name'
  103. end
  104. optional :repository_storages, type: Array[String], desc: 'Storage paths for new projects'
  105. 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."
  106. optional :koding_enabled, type: Boolean, desc: 'Enable Koding'
  107. given koding_enabled: ->(val) { val } do
  108. requires :koding_url, type: String, desc: 'The Koding team URL'
  109. end
  110. optional :plantuml_enabled, type: Boolean, desc: 'Enable PlantUML'
  111. given plantuml_enabled: ->(val) { val } do
  112. requires :plantuml_url, type: String, desc: 'The PlantUML server URL'
  113. end
  114. optional :version_check_enabled, type: Boolean, desc: 'Let GitLab inform you when an update is available.'
  115. 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.'
  116. 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.'
  117. optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)'
  118. given housekeeping_enabled: ->(val) { val } do
  119. requires :housekeeping_bitmaps_enabled, type: Boolean, desc: "Creating pack file bitmaps makes housekeeping take a little longer but bitmaps should accelerate 'git clone' performance."
  120. requires :housekeeping_incremental_repack_period, type: Integer, desc: "Number of Git pushes after which an incremental 'git repack' is run."
  121. requires :housekeeping_full_repack_period, type: Integer, desc: "Number of Git pushes after which a full 'git repack' is run."
  122. requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run."
  123. end
  124. optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
  125. optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.'
  126. optional :gitaly_timeout_default, type: Integer, desc: 'Default Gitaly timeout, in seconds. Set to 0 to disable timeouts.'
  127. optional :gitaly_timeout_medium, type: Integer, desc: 'Medium Gitaly timeout, in seconds. Set to 0 to disable timeouts.'
  128. optional :gitaly_timeout_fast, type: Integer, desc: 'Gitaly fast operation timeout, in seconds. Set to 0 to disable timeouts.'
  129. optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
  130. ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type|
  131. optional :"#{type}_key_restriction",
  132. type: Integer,
  133. values: KeyRestrictionValidator.supported_key_restrictions(type),
  134. desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys."
  135. end
  136. optional_attributes = ::ApplicationSettingsHelper.visible_attributes << :performance_bar_allowed_group_id
  137. optional(*optional_attributes)
  138. at_least_one_of(*optional_attributes)
  139. end
  140. put "application/settings" do
  141. attrs = declared_params(include_missing: false)
  142. # support legacy names, can be removed in v6
  143. if attrs.has_key?(:performance_bar_allowed_group_id)
  144. attrs[:performance_bar_allowed_group_path] = attrs.delete(:performance_bar_allowed_group_id)
  145. end
  146. # support legacy names, can be removed in v6
  147. if attrs.has_key?(:performance_bar_enabled)
  148. performance_bar_enabled = attrs.delete(:performance_bar_allowed_group_id)
  149. attrs[:performance_bar_allowed_group_path] = nil unless performance_bar_enabled
  150. end
  151. # support legacy names, can be removed in v5
  152. if attrs.has_key?(:signin_enabled)
  153. attrs[:password_authentication_enabled_for_web] = attrs.delete(:signin_enabled)
  154. elsif attrs.has_key?(:password_authentication_enabled)
  155. attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled)
  156. end
  157. if ApplicationSettings::UpdateService.new(current_settings, current_user, attrs).execute
  158. present current_settings, with: Entities::ApplicationSetting
  159. else
  160. render_validation_error!(current_settings)
  161. end
  162. end
  163. end
  164. end