diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/release/links.rb | 4 | ||||
-rw-r--r-- | lib/api/releases.rb | 10 | ||||
-rw-r--r-- | lib/banzai/filter/relative_link_filter.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/auth.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/ci/templates/Pages/SwaggerUI.gitlab-ci.yml | 29 | ||||
-rw-r--r-- | lib/gitlab/correlation_id.rb | 40 | ||||
-rw-r--r-- | lib/gitlab/database_importers/self_monitoring/project/create_service.rb | 40 | ||||
-rw-r--r-- | lib/gitlab/metrics/samplers/ruby_sampler.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/optimistic_locking.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/tracing.rb | 2 | ||||
-rw-r--r-- | lib/system_check/incoming_email/foreman_configured_check.rb | 25 | ||||
-rw-r--r-- | lib/system_check/incoming_email_check.rb | 2 |
14 files changed, 76 insertions, 103 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index cfcf6228225..ba58e125568 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1229,6 +1229,7 @@ module API expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? } expose :commit, using: Entities::Commit, if: lambda { |_, _| can_download_code? } expose :upcoming_release?, as: :upcoming_release + expose :milestone, using: Entities::Milestone, if: -> (release, _) { release.milestone.present? } expose :assets do expose :assets_count, as: :count do |release, _| diff --git a/lib/api/release/links.rb b/lib/api/release/links.rb index 5d1b40e3bff..def36dc8529 100644 --- a/lib/api/release/links.rb +++ b/lib/api/release/links.rb @@ -5,7 +5,7 @@ module API class Links < Grape::API include PaginationParams - RELEASE_ENDPOINT_REQUIREMETS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS + RELEASE_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS .merge(tag_name: API::NO_SLASH_URL_PART_REGEX) before { authorize! :read_release, user_project } @@ -17,7 +17,7 @@ module API params do requires :tag_name, type: String, desc: 'The name of the tag', as: :tag end - resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do resource :assets do desc 'Get a list of links of a release' do detail 'This feature was introduced in GitLab 11.7.' diff --git a/lib/api/releases.rb b/lib/api/releases.rb index 7a3d804c30c..5a31581c4da 100644 --- a/lib/api/releases.rb +++ b/lib/api/releases.rb @@ -4,7 +4,7 @@ module API class Releases < Grape::API include PaginationParams - RELEASE_ENDPOINT_REQUIREMETS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS + RELEASE_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS .merge(tag_name: API::NO_SLASH_URL_PART_REGEX) before { authorize_read_releases! } @@ -33,7 +33,7 @@ module API params do requires :tag_name, type: String, desc: 'The name of the tag', as: :tag end - get ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + get ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do authorize_download_code! present release, with: Entities::Release, current_user: current_user @@ -54,6 +54,7 @@ module API requires :url, type: String end end + optional :milestone, type: String, desc: 'The title of the related milestone' optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready. Defaults to the current time.' end post ':id/releases' do @@ -79,8 +80,9 @@ module API optional :name, type: String, desc: 'The name of the release' optional :description, type: String, desc: 'Release notes with markdown support' optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready.' + optional :milestone, type: String, desc: 'The title of the related milestone' end - put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do authorize_update_release! result = ::Releases::UpdateService @@ -101,7 +103,7 @@ module API params do requires :tag_name, type: String, desc: 'The name of the tag', as: :tag end - delete ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do + delete ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do authorize_destroy_release! result = ::Releases::DestroyService diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb index 846a7d46aad..2b734db5cfb 100644 --- a/lib/banzai/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -19,7 +19,6 @@ module Banzai def call return doc if context[:system_note] - return doc unless visible_to_user? @uri_types = {} clear_memoization(:linkable_files) @@ -50,7 +49,7 @@ module Banzai if html_attr.value.start_with?('/uploads/') process_link_to_upload_attr(html_attr) - elsif linkable_files? + elsif linkable_files? && repo_visible_to_user? process_link_to_repository_attr(html_attr) end end @@ -168,14 +167,8 @@ module Banzai Gitlab.config.gitlab.relative_url_root.presence || '/' end - def visible_to_user? - if project - Ability.allowed?(current_user, :download_code, project) - elsif group - Ability.allowed?(current_user, :read_group, group) - else # Objects detached from projects or groups, e.g. Personal Snippets. - true - end + def repo_visible_to_user? + project && Ability.allowed?(current_user, :download_code, project) end def ref diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb index 6769bd95c2b..bdc46abeb9f 100644 --- a/lib/gitlab/auth.rb +++ b/lib/gitlab/auth.rb @@ -265,7 +265,8 @@ module Gitlab :read_project, :build_download_code, :build_read_container_image, - :build_create_container_image + :build_create_container_image, + :build_destroy_container_image ] end diff --git a/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml index 3adc6a72874..3cdb7b5420c 100644 --- a/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml @@ -25,8 +25,9 @@ code_quality: expire_in: 1 week dependencies: [] only: - - branches - - tags + refs: + - branches + - tags except: variables: - $CODE_QUALITY_DISABLED diff --git a/lib/gitlab/ci/templates/Pages/SwaggerUI.gitlab-ci.yml b/lib/gitlab/ci/templates/Pages/SwaggerUI.gitlab-ci.yml new file mode 100644 index 00000000000..8fd08ea7995 --- /dev/null +++ b/lib/gitlab/ci/templates/Pages/SwaggerUI.gitlab-ci.yml @@ -0,0 +1,29 @@ +image: node:10-alpine + +# specify the location of the Open API Specification files within your project +# and the filename of the specification that you would like to display by default +variables: + DOCS_FOLDER: "api-docs" + SPEC_TO_DISPLAY: "my-project_specification_0.0.1.json" + +# These folders are cached between builds +cache: + paths: + - ./node_modules + +# publishes all files from the $DOCS_FOLDER together with the static version of SwaggerUI +# sets the specification file named in $SPEC_TO_DISPLAY to be displayed by default +pages: + stage: deploy + before_script: + - npm install swagger-ui-dist@3.22.1 + script: + - mkdir public + - cp -rp node_modules/swagger-ui-dist/* public + - cp -rp $DOCS_FOLDER/* public + - sed -i "s#https://petstore\.swagger\.io/v2/swagger\.json#$SPEC_TO_DISPLAY#g" public/index.html + artifacts: + paths: + - public + only: + - master diff --git a/lib/gitlab/correlation_id.rb b/lib/gitlab/correlation_id.rb deleted file mode 100644 index 0f9bde4390e..00000000000 --- a/lib/gitlab/correlation_id.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module CorrelationId - LOG_KEY = 'correlation_id'.freeze - - class << self - def use_id(correlation_id, &blk) - # always generate a id if null is passed - correlation_id ||= new_id - - ids.push(correlation_id || new_id) - - begin - yield(current_id) - ensure - ids.pop - end - end - - def current_id - ids.last - end - - def current_or_new_id - current_id || new_id - end - - private - - def ids - Thread.current[:correlation_id] ||= [] - end - - def new_id - SecureRandom.uuid - end - end - end -end diff --git a/lib/gitlab/database_importers/self_monitoring/project/create_service.rb b/lib/gitlab/database_importers/self_monitoring/project/create_service.rb index 3a170e8b5f8..5422a8631a0 100644 --- a/lib/gitlab/database_importers/self_monitoring/project/create_service.rb +++ b/lib/gitlab/database_importers/self_monitoring/project/create_service.rb @@ -45,20 +45,20 @@ module Gitlab def validate_application_settings return success if application_settings - log_error(_('No application_settings found')) + log_error('No application_settings found') error(_('No application_settings found')) end def validate_project_created return success unless project_created? - log_error(_('Project already created')) + log_error('Project already created') error(_('Project already created')) end def validate_admins unless instance_admins.any? - log_error(_('No active admin user found')) + log_error('No active admin user found') return error(_('No active admin user found')) end @@ -83,7 +83,7 @@ module Gitlab def create_project if project_created? - log_info(_('Instance administration project already exists')) + log_info('Instance administration project already exists') @project = application_settings.instance_administration_project return success(project: project) end @@ -93,7 +93,7 @@ module Gitlab if project.persisted? success(project: project) else - log_error(_("Could not create instance administration project. Errors: %{errors}") % { errors: project.errors.full_messages }) + log_error("Could not create instance administration project. Errors: %{errors}" % { errors: project.errors.full_messages }) error(_('Could not create project')) end end @@ -106,7 +106,7 @@ module Gitlab if result success else - log_error(_("Could not save instance administration project ID, errors: %{errors}") % { errors: application_settings.errors.full_messages }) + log_error("Could not save instance administration project ID, errors: %{errors}" % { errors: application_settings.errors.full_messages }) error(_('Could not save project ID')) end end @@ -116,7 +116,7 @@ module Gitlab errors = members.flat_map { |member| member.errors.full_messages } if errors.any? - log_error(_('Could not add admins as members to self-monitoring project. Errors: %{errors}') % { errors: errors }) + log_error('Could not add admins as members to self-monitoring project. Errors: %{errors}' % { errors: errors }) error(_('Could not add admins as members')) else success @@ -128,7 +128,7 @@ module Gitlab return success unless prometheus_listen_address.present? uri = parse_url(internal_prometheus_listen_address_uri) - return error(_('Prometheus listen_address is not a valid URI')) unless uri + return error(_('Prometheus listen_address in config/gitlab.yml is not a valid URI')) unless uri application_settings.add_to_outbound_local_requests_whitelist([uri.normalized_host]) result = application_settings.save @@ -140,7 +140,7 @@ module Gitlab Gitlab::CurrentSettings.expire_current_application_settings success else - log_error(_("Could not add prometheus URL to whitelist, errors: %{errors}") % { errors: application_settings.errors.full_messages }) + log_error("Could not add prometheus URL to whitelist, errors: %{errors}" % { errors: application_settings.errors.full_messages }) error(_('Could not add prometheus URL to whitelist')) end end @@ -152,7 +152,7 @@ module Gitlab service = project.find_or_initialize_service('prometheus') unless service.update(prometheus_service_attributes) - log_error(_('Could not save prometheus manual configuration for self-monitoring project. Errors: %{errors}') % { errors: service.errors.full_messages }) + log_error('Could not save prometheus manual configuration for self-monitoring project. Errors: %{errors}' % { errors: service.errors.full_messages }) return error(_('Could not save prometheus manual configuration')) end @@ -175,15 +175,15 @@ module Gitlab def prometheus_enabled? Gitlab.config.prometheus.enable if Gitlab.config.prometheus rescue Settingslogic::MissingSetting - log_error(_('prometheus.enable is not present in gitlab.yml')) + log_error('prometheus.enable is not present in config/gitlab.yml') false end def prometheus_listen_address - Gitlab.config.prometheus.listen_address if Gitlab.config.prometheus + Gitlab.config.prometheus.listen_address.to_s if Gitlab.config.prometheus rescue Settingslogic::MissingSetting - log_error(_('prometheus.listen_address is not present in gitlab.yml')) + log_error('Prometheus listen_address is not present in config/gitlab.yml') nil end @@ -228,9 +228,21 @@ module Gitlab end def internal_prometheus_listen_address_uri - if prometheus_listen_address.starts_with?('http') + if prometheus_listen_address.starts_with?('0.0.0.0:') + # 0.0.0.0:9090 + port = ':' + prometheus_listen_address.split(':').second + 'http://localhost' + port + + elsif prometheus_listen_address.starts_with?(':') + # :9090 + 'http://localhost' + prometheus_listen_address + + elsif prometheus_listen_address.starts_with?('http') + # https://localhost:9090 prometheus_listen_address + else + # localhost:9090 'http://' + prometheus_listen_address end end diff --git a/lib/gitlab/metrics/samplers/ruby_sampler.rb b/lib/gitlab/metrics/samplers/ruby_sampler.rb index 3bfa3da35e0..c38769f39a9 100644 --- a/lib/gitlab/metrics/samplers/ruby_sampler.rb +++ b/lib/gitlab/metrics/samplers/ruby_sampler.rb @@ -6,7 +6,7 @@ module Gitlab module Metrics module Samplers class RubySampler < BaseSampler - GC_REPORT_BUCKETS = [0.001, 0.002, 0.005, 0.01, 0.05, 0.1, 0.5].freeze + GC_REPORT_BUCKETS = [0.005, 0.01, 0.02, 0.04, 0.07, 0.1, 0.5].freeze def initialize(interval) GC::Profiler.clear diff --git a/lib/gitlab/optimistic_locking.rb b/lib/gitlab/optimistic_locking.rb index 0c0f46d3b77..d51d718c826 100644 --- a/lib/gitlab/optimistic_locking.rb +++ b/lib/gitlab/optimistic_locking.rb @@ -4,7 +4,8 @@ module Gitlab module OptimisticLocking module_function - def retry_lock(subject, retries = 100, &block) + def retry_lock(subject, retries = nil, &block) + retries ||= 100 # TODO(Observability): We should be recording details of the number of retries and the duration of the total execution here ActiveRecord::Base.transaction do yield(subject) diff --git a/lib/gitlab/tracing.rb b/lib/gitlab/tracing.rb index 29517591c51..7732d7c9d9c 100644 --- a/lib/gitlab/tracing.rb +++ b/lib/gitlab/tracing.rb @@ -30,7 +30,7 @@ module Gitlab # Avoid using `format` since it can throw TypeErrors # which we want to avoid on unsanitised env var input tracing_url_template.to_s - .gsub(/\{\{\s*correlation_id\s*\}\}/, Gitlab::CorrelationId.current_id.to_s) + .gsub(/\{\{\s*correlation_id\s*\}\}/, Labkit::Correlation::CorrelationId.current_id.to_s) .gsub(/\{\{\s*service\s*\}\}/, Gitlab.process_name) end end diff --git a/lib/system_check/incoming_email/foreman_configured_check.rb b/lib/system_check/incoming_email/foreman_configured_check.rb deleted file mode 100644 index 944913087da..00000000000 --- a/lib/system_check/incoming_email/foreman_configured_check.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -module SystemCheck - module IncomingEmail - class ForemanConfiguredCheck < SystemCheck::BaseCheck - set_name 'Foreman configured correctly?' - - def check? - path = Rails.root.join('Procfile') - - File.exist?(path) && File.read(path) =~ /^mail_room:/ - end - - def show_error - try_fixing_it( - 'Enable mail_room in your Procfile.' - ) - for_more_information( - 'doc/administration/reply_by_email.md' - ) - fix_and_rerun - end - end - end -end diff --git a/lib/system_check/incoming_email_check.rb b/lib/system_check/incoming_email_check.rb index 155b6547595..e0e1147711c 100644 --- a/lib/system_check/incoming_email_check.rb +++ b/lib/system_check/incoming_email_check.rb @@ -14,8 +14,6 @@ module SystemCheck if Rails.env.production? checks << SystemCheck::IncomingEmail::InitdConfiguredCheck checks << SystemCheck::IncomingEmail::MailRoomRunningCheck - else - checks << SystemCheck::IncomingEmail::ForemanConfiguredCheck end SystemCheck.run('Reply by email', checks) |