PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/api/settings.rb

https://gitlab.com/rtripault/gitlab-ce
Ruby | 135 lines | 132 code | 3 blank | 0 comment | 7 complexity | a83307e6206eaad85484b7cd5258561e MD5 | raw file
  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 || 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: Integer, values: Gitlab::VisibilityLevel.values, desc: 'The default project visibility'
  22. optional :default_snippet_visibility, type: Integer, values: Gitlab::VisibilityLevel.values, desc: 'The default snippet visibility'
  23. optional :default_group_visibility, type: Integer, values: Gitlab::VisibilityLevel.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 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 :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled'
  30. optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects'
  31. optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB'
  32. optional :session_expire_delay, type: Integer, desc: 'Session duration in minutes. GitLab restart is required to apply changes.'
  33. optional :user_oauth_applications, type: Boolean, desc: 'Allow users to register any application to use GitLab as an OAuth provider'
  34. optional :user_default_external, type: Boolean, desc: 'Newly registered users will by default be external'
  35. optional :signup_enabled, type: Boolean, desc: 'Flag indicating if sign up is enabled'
  36. optional :send_user_confirmation_email, type: Boolean, desc: 'Send confirmation email on sign-up'
  37. 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'
  38. optional :domain_blacklist_enabled, type: Boolean, desc: 'Enable domain blacklist for sign ups'
  39. given domain_blacklist_enabled: ->(val) { val } do
  40. 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'
  41. end
  42. optional :after_sign_up_text, type: String, desc: 'Text shown after sign up'
  43. optional :signin_enabled, type: Boolean, desc: 'Flag indicating if sign in is enabled'
  44. optional :require_two_factor_authentication, type: Boolean, desc: 'Require all users to setup Two-factor authentication'
  45. given require_two_factor_authentication: ->(val) { val } do
  46. 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'
  47. end
  48. optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page'
  49. optional :after_sign_out_path, type: String, desc: 'We will redirect users to this page after they sign out'
  50. optional :sign_in_text, type: String, desc: 'The sign in text of the GitLab application'
  51. optional :help_page_text, type: String, desc: 'Custom text displayed on the help page'
  52. optional :shared_runners_enabled, type: Boolean, desc: 'Enable shared runners for new projects'
  53. given shared_runners_enabled: ->(val) { val } do
  54. requires :shared_runners_text, type: String, desc: 'Shared runners text '
  55. end
  56. optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size each build's artifacts can have"
  57. optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
  58. optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
  59. optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'
  60. given metrics_enabled: ->(val) { val } do
  61. requires :metrics_host, type: String, desc: 'The InfluxDB host'
  62. requires :metrics_port, type: Integer, desc: 'The UDP port to use for connecting to InfluxDB'
  63. requires :metrics_pool_size, type: Integer, desc: 'The amount of InfluxDB connections to open'
  64. requires :metrics_timeout, type: Integer, desc: 'The amount of seconds after which an InfluxDB connection will time out'
  65. 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.'
  66. requires :metrics_sample_interval, type: Integer, desc: 'The sampling interval in seconds'
  67. requires :metrics_packet_size, type: Integer, desc: 'The amount of points to store in a single UDP packet'
  68. end
  69. optional :sidekiq_throttling_enabled, type: Boolean, desc: 'Enable Sidekiq Job Throttling'
  70. given sidekiq_throttling_enabled: ->(val) { val } do
  71. requires :sidekiq_throttling_queus, type: Array[String], desc: 'Choose which queues you wish to throttle'
  72. 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.'
  73. end
  74. optional :recaptcha_enabled, type: Boolean, desc: 'Helps prevent bots from creating accounts'
  75. given recaptcha_enabled: ->(val) { val } do
  76. requires :recaptcha_site_key, type: String, desc: 'Generate site key at http://www.google.com/recaptcha'
  77. requires :recaptcha_private_key, type: String, desc: 'Generate private key at http://www.google.com/recaptcha'
  78. end
  79. optional :akismet_enabled, type: Boolean, desc: 'Helps prevent bots from creating issues'
  80. given akismet_enabled: ->(val) { val } do
  81. requires :akismet_api_key, type: String, desc: 'Generate API key at http://www.akismet.com'
  82. end
  83. 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.'
  84. 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'
  85. given sentry_enabled: ->(val) { val } do
  86. requires :sentry_dsn, type: String, desc: 'Sentry Data Source Name'
  87. end
  88. optional :repository_storage, type: String, desc: 'Storage paths for new projects'
  89. 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."
  90. optional :koding_enabled, type: Boolean, desc: 'Enable Koding'
  91. given koding_enabled: ->(val) { val } do
  92. requires :koding_url, type: String, desc: 'The Koding team URL'
  93. end
  94. optional :plantuml_enabled, type: Boolean, desc: 'Enable PlantUML'
  95. given plantuml_enabled: ->(val) { val } do
  96. requires :plantuml_url, type: String, desc: 'The PlantUML server URL'
  97. end
  98. optional :version_check_enabled, type: Boolean, desc: 'Let GitLab inform you when an update is available.'
  99. 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.'
  100. 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.'
  101. optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)'
  102. given housekeeping_enabled: ->(val) { val } do
  103. requires :housekeeping_bitmaps_enabled, type: Boolean, desc: "Creating pack file bitmaps makes housekeeping take a little longer but bitmaps should accelerate 'git clone' performance."
  104. requires :housekeeping_incremental_repack_period, type: Integer, desc: "Number of Git pushes after which an incremental 'git repack' is run."
  105. requires :housekeeping_full_repack_period, type: Integer, desc: "Number of Git pushes after which a full 'git repack' is run."
  106. requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run."
  107. end
  108. optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
  109. at_least_one_of :default_branch_protection, :default_project_visibility, :default_snippet_visibility,
  110. :default_group_visibility, :restricted_visibility_levels, :import_sources,
  111. :enabled_git_access_protocol, :gravatar_enabled, :default_projects_limit,
  112. :max_attachment_size, :session_expire_delay, :disabled_oauth_sign_in_sources,
  113. :user_oauth_applications, :user_default_external, :signup_enabled,
  114. :send_user_confirmation_email, :domain_whitelist, :domain_blacklist_enabled,
  115. :after_sign_up_text, :signin_enabled, :require_two_factor_authentication,
  116. :home_page_url, :after_sign_out_path, :sign_in_text, :help_page_text,
  117. :shared_runners_enabled, :max_artifacts_size, :max_pages_size, :container_registry_token_expire_delay,
  118. :metrics_enabled, :sidekiq_throttling_enabled, :recaptcha_enabled,
  119. :akismet_enabled, :admin_notification_email, :sentry_enabled,
  120. :repository_storage, :repository_checks_enabled, :koding_enabled, :plantuml_enabled,
  121. :version_check_enabled, :email_author_in_body, :html_emails_enabled,
  122. :housekeeping_enabled, :terminal_max_session_time
  123. end
  124. put "application/settings" do
  125. if current_settings.update_attributes(declared_params(include_missing: false))
  126. present current_settings, with: Entities::ApplicationSetting
  127. else
  128. render_validation_error!(current_settings)
  129. end
  130. end
  131. end
  132. end