diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/pages_domains.rb | 15 | ||||
-rw-r--r-- | lib/banzai/filter/relative_link_filter.rb | 2 | ||||
-rw-r--r-- | lib/gitaly/server.rb | 18 | ||||
-rw-r--r-- | lib/gitlab.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/importer.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/ci/ansi2html.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/lexer.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/expression/parser.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/json_cache.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/kubernetes.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/usage_data.rb | 3 | ||||
-rw-r--r-- | lib/system_check/ldap_check.rb | 9 |
14 files changed, 88 insertions, 26 deletions
diff --git a/lib/api/pages_domains.rb b/lib/api/pages_domains.rb index 78442f465bd..4227a106a95 100644 --- a/lib/api/pages_domains.rb +++ b/lib/api/pages_domains.rb @@ -90,14 +90,15 @@ module API end params do requires :domain, type: String, desc: 'The domain' - optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate' - optional :key, allow_blank: false, types: [File, String], desc: 'The key' - all_or_none_of :certificate, :key + optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate', as: :user_provided_certificate + optional :key, allow_blank: false, types: [File, String], desc: 'The key', as: :user_provided_key + all_or_none_of :user_provided_certificate, :user_provided_key end post ":id/pages/domains" do authorize! :update_pages, user_project pages_domain_params = declared(params, include_parent_namespaces: false) + pages_domain = user_project.pages_domains.create(pages_domain_params) if pages_domain.persisted? @@ -110,8 +111,8 @@ module API desc 'Updates a pages domain' params do requires :domain, type: String, desc: 'The domain' - optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate' - optional :key, allow_blank: false, types: [File, String], desc: 'The key' + optional :certificate, allow_blank: false, types: [File, String], desc: 'The certificate', as: :user_provided_certificate + optional :key, allow_blank: false, types: [File, String], desc: 'The key', as: :user_provided_key end put ":id/pages/domains/:domain", requirements: PAGES_DOMAINS_ENDPOINT_REQUIREMENTS do authorize! :update_pages, user_project @@ -119,8 +120,8 @@ module API pages_domain_params = declared(params, include_parent_namespaces: false) # Remove empty private key if certificate is not empty. - if pages_domain_params[:certificate] && !pages_domain_params[:key] - pages_domain_params.delete(:key) + if pages_domain_params[:user_provided_certificate] && !pages_domain_params[:user_provided_key] + pages_domain_params.delete(:user_provided_key) end if pages_domain.update(pages_domain_params) diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb index 199b3533cf4..80c84c0f622 100644 --- a/lib/banzai/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -17,6 +17,8 @@ module Banzai include Gitlab::Utils::StrongMemoize def call + return doc if context[:system_note] + @uri_types = {} clear_memoization(:linkable_files) diff --git a/lib/gitaly/server.rb b/lib/gitaly/server.rb index 7b238623418..907c6e1b605 100644 --- a/lib/gitaly/server.rb +++ b/lib/gitaly/server.rb @@ -2,8 +2,18 @@ module Gitaly class Server - def self.all - Gitlab.config.repositories.storages.keys.map { |s| Gitaly::Server.new(s) } + class << self + def all + Gitlab.config.repositories.storages.keys.map { |s| Gitaly::Server.new(s) } + end + + def count + all.size + end + + def filesystems + all.map(&:filesystem_type).compact.uniq + end end attr_reader :storage @@ -36,6 +46,10 @@ module Gitaly storage_status&.writeable end + def filesystem_type + storage_status&.fs_type + end + def address Gitlab::GitalyClient.address(@storage) rescue RuntimeError => e diff --git a/lib/gitlab.rb b/lib/gitlab.rb index ccaf06c5d6a..fd4bbd69468 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_dependency 'gitlab/popen' +require_dependency File.expand_path('gitlab/popen', __dir__) module Gitlab def self.root @@ -60,11 +60,15 @@ module Gitlab end def self.ee? - if ENV['IS_GITLAB_EE'].present? - Gitlab::Utils.to_boolean(ENV['IS_GITLAB_EE']) - else - Object.const_defined?(:License) - end + @is_ee ||= + if ENV['IS_GITLAB_EE'].present? + Gitlab::Utils.to_boolean(ENV['IS_GITLAB_EE']) + else + # We may use this method when the Rails environment is not loaded. This + # means that checking the presence of the License class could result in + # this method returning `false`, even for an EE installation. + root.join('ee/app/models/license.rb').exist? + end end def self.http_proxy_env? diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index c9f0ed66a54..8047ef4fa15 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -11,6 +11,7 @@ module Gitlab { title: 'task', color: '#7F8C8D' }].freeze attr_reader :project, :client, :errors, :users + attr_accessor :logger def initialize(project) @project = project @@ -19,6 +20,7 @@ module Gitlab @labels = {} @errors = [] @users = {} + @logger = Gitlab::Import::Logger.build end def execute @@ -41,6 +43,18 @@ module Gitlab }.to_json) end + def store_pull_request_error(pull_request, ex) + backtrace = Gitlab::Profiler.clean_backtrace(ex.backtrace) + error = { type: :pull_request, iid: pull_request.iid, errors: ex.message, trace: backtrace, raw_response: pull_request.raw } + + log_error(error) + # Omit the details from the database to avoid blowing up usage in the error column + error.delete(:trace) + error.delete(:raw_response) + + errors << error + end + def gitlab_user_id(project, username) find_user_id(username) || project.creator_id end @@ -176,7 +190,7 @@ module Gitlab import_pull_request_comments(pull_request, merge_request) if merge_request.persisted? rescue StandardError => e - errors << { type: :pull_request, iid: pull_request.iid, errors: e.message, trace: e.backtrace.join("\n"), raw_response: pull_request.raw } + store_pull_request_error(pull_request, e) end end @@ -254,6 +268,18 @@ module Gitlab updated_at: comment.updated_at } end + + def log_error(details) + logger.error(log_base_data.merge(details)) + end + + def log_base_data + { + class: self.class.name, + project_id: project.id, + project_path: project.full_path + } + end end end end diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb index fc3223e7442..55411b5a8c4 100644 --- a/lib/gitlab/ci/ansi2html.rb +++ b/lib/gitlab/ci/ansi2html.rb @@ -200,7 +200,9 @@ module Gitlab css_classes = %w[section line] + sections.map { |section| "s_#{section}" } end - write_in_tag %{<br/>} + ensure_open_new_tag + write_raw %{<br/>} + close_open_tags write_raw %{<span class="#{css_classes.join(' ')}"></span>} if css_classes.any? @lineno_in_section += 1 open_new_tag diff --git a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb index 531c9ce4256..e6e0aaab60b 100644 --- a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb +++ b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb @@ -8,7 +8,6 @@ module Gitlab def unmet? deployment_cluster.present? && deployment_cluster.managed? && - !deployment_cluster.project_type? && (kubernetes_namespace.new_record? || kubernetes_namespace.service_account_token.blank?) end diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb b/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb index eb32dffc454..e4cf360a1c1 100644 --- a/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb +++ b/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb @@ -34,7 +34,7 @@ module Gitlab end def self.eager_matching_with_escape_characters? - Feature.enabled?(:ci_variables_complex_expressions) + Feature.enabled?(:ci_variables_complex_expressions, default_enabled: true) end end end diff --git a/lib/gitlab/ci/pipeline/expression/lexer.rb b/lib/gitlab/ci/pipeline/expression/lexer.rb index 23aa1ca4a36..22c210ae26b 100644 --- a/lib/gitlab/ci/pipeline/expression/lexer.rb +++ b/lib/gitlab/ci/pipeline/expression/lexer.rb @@ -73,7 +73,7 @@ module Gitlab end def available_lexemes - Feature.enabled?(:ci_variables_complex_expressions) ? NEW_LEXEMES : LEXEMES + Feature.enabled?(:ci_variables_complex_expressions, default_enabled: true) ? NEW_LEXEMES : LEXEMES end end end diff --git a/lib/gitlab/ci/pipeline/expression/parser.rb b/lib/gitlab/ci/pipeline/expression/parser.rb index 0679ed329e5..589bf32a4d7 100644 --- a/lib/gitlab/ci/pipeline/expression/parser.rb +++ b/lib/gitlab/ci/pipeline/expression/parser.rb @@ -13,7 +13,7 @@ module Gitlab end def tree - if Feature.enabled?(:ci_variables_complex_expressions) + if Feature.enabled?(:ci_variables_complex_expressions, default_enabled: true) rpn_parse_tree else reverse_descent_parse_tree diff --git a/lib/gitlab/json_cache.rb b/lib/gitlab/json_cache.rb index 9a0b2b35112..d01183d7845 100644 --- a/lib/gitlab/json_cache.rb +++ b/lib/gitlab/json_cache.rb @@ -22,10 +22,10 @@ module Gitlab expanded_cache_key = [namespace, key].compact if cache_key_with_version - expanded_cache_key << Rails.version + expanded_cache_key << [Gitlab::VERSION, Rails.version] end - expanded_cache_key.join(':') + expanded_cache_key.flatten.join(':').freeze end def expire(key) diff --git a/lib/gitlab/kubernetes.rb b/lib/gitlab/kubernetes.rb index 1103a4eed1d..22bd00751bc 100644 --- a/lib/gitlab/kubernetes.rb +++ b/lib/gitlab/kubernetes.rb @@ -43,6 +43,14 @@ module Gitlab }) end + def filter_by_legacy_label(items, app, env) + legacy_items = filter_by_label(items, { app: env }) + + non_legacy_items = filter_by_project_environment(legacy_items, app, env) + + legacy_items - non_legacy_items + end + # Converts a pod (as returned by the kubernetes API) into a terminal def terminals_for_pod(api_url, namespace, pod) metadata = pod.fetch("metadata", {}) diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 9aa2e972adf..0180fe7fa71 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -136,8 +136,9 @@ module Gitlab def components_usage_data { - gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION }, git: { version: Gitlab::Git.version }, + gitaly: { version: Gitaly::Server.all.first.server_version, servers: Gitaly::Server.count, filesystems: Gitaly::Server.filesystems }, + gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION }, database: { adapter: Gitlab::Database.adapter_name, version: Gitlab::Database.version } } end diff --git a/lib/system_check/ldap_check.rb b/lib/system_check/ldap_check.rb index 619fb3cccb8..938026424ed 100644 --- a/lib/system_check/ldap_check.rb +++ b/lib/system_check/ldap_check.rb @@ -33,8 +33,13 @@ module SystemCheck $stdout.puts "LDAP users with access to your GitLab server (only showing the first #{limit} results)" users = adapter.users(adapter.config.uid, '*', limit) - users.each do |user| - $stdout.puts "\tDN: #{user.dn}\t #{adapter.config.uid}: #{user.uid}" + + if should_sanitize? + $stdout.puts "\tUser output sanitized. Found #{users.length} users of #{limit} limit." + else + users.each do |user| + $stdout.puts "\tDN: #{user.dn}\t #{adapter.config.uid}: #{user.uid}" + end end end rescue Net::LDAP::ConnectionRefusedError, Errno::ECONNREFUSED => e |