diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 12:09:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 12:09:17 +0000 |
commit | cd52759ee33051b8ad7b88b02ba7954e4fad7018 (patch) | |
tree | f1096c68e457aef7f5201acd16e4a751ff538026 /lib | |
parent | 18f7828977b74bf6e5153594a098ef90e773b3b7 (diff) | |
download | gitlab-ce-cd52759ee33051b8ad7b88b02ba7954e4fad7018.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/deploy_tokens.rb | 18 | ||||
-rw-r--r-- | lib/api/entities/release.rb | 2 | ||||
-rw-r--r-- | lib/api/entities/user_details_with_admin.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/authorized_keys.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/background_migration/update_authorized_keys_file_since.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/background_migration/user_mentions/models/merge_request.rb | 45 | ||||
-rw-r--r-- | lib/gitlab/background_migration/user_mentions/models/merge_request_user_mention.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/shell.rb | 112 | ||||
-rw-r--r-- | lib/tasks/gitlab/shell.rake | 10 |
10 files changed, 92 insertions, 132 deletions
diff --git a/lib/api/deploy_tokens.rb b/lib/api/deploy_tokens.rb index cb1ee7df496..2b1c485785b 100644 --- a/lib/api/deploy_tokens.rb +++ b/lib/api/deploy_tokens.rb @@ -71,6 +71,24 @@ module API present deploy_token, with: Entities::DeployTokenWithToken end + + desc 'Delete a project deploy token' do + detail 'This feature was introduced in GitLab 12.9' + end + params do + requires :token_id, type: Integer, desc: 'The deploy token ID' + end + delete ':id/deploy_tokens/:token_id' do + authorize!(:destroy_deploy_token, user_project) + + deploy_token = user_project.project_deploy_tokens + .find_by_deploy_token_id(params[:token_id]) + + not_found!('Deploy Token') unless deploy_token + + deploy_token.destroy + no_content! + end end params do diff --git a/lib/api/entities/release.rb b/lib/api/entities/release.rb index 292b2e0102b..c70982a9ece 100644 --- a/lib/api/entities/release.rb +++ b/lib/api/entities/release.rb @@ -11,7 +11,7 @@ module API expose :tag, as: :tag_name, if: ->(_, _) { can_download_code? } expose :description expose :description_html do |entity| - MarkupHelper.markdown_field(entity, :description) + MarkupHelper.markdown_field(entity, :description, current_user: options[:current_user]) end expose :created_at expose :released_at diff --git a/lib/api/entities/user_details_with_admin.rb b/lib/api/entities/user_details_with_admin.rb index 9ea5c583437..22a842983e2 100644 --- a/lib/api/entities/user_details_with_admin.rb +++ b/lib/api/entities/user_details_with_admin.rb @@ -9,3 +9,5 @@ module API end end end + +API::Entities::UserDetailsWithAdmin.prepend_if_ee('EE::API::Entities::UserDetailsWithAdmin') diff --git a/lib/gitlab/authorized_keys.rb b/lib/gitlab/authorized_keys.rb index 820a78b653c..50cd15b7a10 100644 --- a/lib/gitlab/authorized_keys.rb +++ b/lib/gitlab/authorized_keys.rb @@ -70,7 +70,7 @@ module Gitlab # # @param [String] id identifier of the key to be removed prefixed by `key-` # @return [Boolean] - def rm_key(id) + def remove_key(id) lock do logger.info("Removing key (#{id})") open_authorized_keys_file('r+') do |f| diff --git a/lib/gitlab/background_migration/update_authorized_keys_file_since.rb b/lib/gitlab/background_migration/update_authorized_keys_file_since.rb deleted file mode 100644 index dd80d4bab1a..00000000000 --- a/lib/gitlab/background_migration/update_authorized_keys_file_since.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module BackgroundMigration - # rubocop: disable Style/Documentation - class UpdateAuthorizedKeysFileSince - def perform(cutoff_datetime) - end - end - end -end - -Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince.prepend_if_ee('EE::Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince') diff --git a/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb b/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb index 22b984887b1..cf0f582a2d4 100644 --- a/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb +++ b/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb @@ -8,7 +8,7 @@ module Gitlab # Resources that have mentions to be migrated: # issue, merge_request, epic, commit, snippet, design - BULK_INSERT_SIZE = 5000 + BULK_INSERT_SIZE = 1_000 ISOLATION_MODULE = 'Gitlab::BackgroundMigration::UserMentions::Models' def perform(resource_model, join, conditions, with_notes, start_id, end_id) diff --git a/lib/gitlab/background_migration/user_mentions/models/merge_request.rb b/lib/gitlab/background_migration/user_mentions/models/merge_request.rb new file mode 100644 index 00000000000..655c1db71ae --- /dev/null +++ b/lib/gitlab/background_migration/user_mentions/models/merge_request.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + module UserMentions + module Models + class MergeRequest < ActiveRecord::Base + include Concerns::IsolatedMentionable + include CacheMarkdownField + include Concerns::MentionableMigrationMethods + + attr_mentionable :title, pipeline: :single_line + attr_mentionable :description + cache_markdown_field :title, pipeline: :single_line + cache_markdown_field :description, issuable_state_filter_enabled: true + + self.table_name = 'merge_requests' + + belongs_to :author, class_name: "User" + belongs_to :target_project, class_name: "Project" + belongs_to :source_project, class_name: "Project" + + alias_attribute :project, :target_project + + def self.user_mention_model + Gitlab::BackgroundMigration::UserMentions::Models::MergeRequestUserMention + end + + def user_mention_model + self.class.user_mention_model + end + + def user_mention_resource_id + id + end + + def user_mention_note_id + 'NULL' + end + end + end + end + end +end diff --git a/lib/gitlab/background_migration/user_mentions/models/merge_request_user_mention.rb b/lib/gitlab/background_migration/user_mentions/models/merge_request_user_mention.rb new file mode 100644 index 00000000000..e9b85e9cb8c --- /dev/null +++ b/lib/gitlab/background_migration/user_mentions/models/merge_request_user_mention.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + module UserMentions + module Models + class MergeRequestUserMention < ActiveRecord::Base + self.table_name = 'merge_request_user_mentions' + + def self.resource_foreign_key + :merge_request_id + end + end + end + end + end +end diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index 726ecd81824..e7158148b59 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -192,84 +192,6 @@ module Gitlab false end - # Add new key to authorized_keys - # - # @example Add new key - # add_key("key-42", "sha-rsa ...") - # - # @param [String] key_id identifier of the key - # @param [String] key_content key content (public certificate) - # @return [Boolean] whether key could be added - def add_key(key_id, key_content) - return unless self.authorized_keys_enabled? - - gitlab_authorized_keys.add_key(key_id, key_content) - end - - # Batch-add keys to authorized_keys - # - # @example - # batch_add_keys(Key.all) - # - # @param [Array<Key>] keys - # @return [Boolean] whether keys could be added - def batch_add_keys(keys) - return unless self.authorized_keys_enabled? - - gitlab_authorized_keys.batch_add_keys(keys) - end - - # Remove SSH key from authorized_keys - # - # @example Remove a key - # remove_key("key-342") - # - # @param [String] key_id - # @return [Boolean] whether key could be removed or not - def remove_key(key_id, _ = nil) - return unless self.authorized_keys_enabled? - - gitlab_authorized_keys.rm_key(key_id) - end - - # Remove all SSH keys from gitlab shell - # - # @example Remove all keys - # remove_all_keys - # - # @return [Boolean] whether keys could be removed or not - def remove_all_keys - return unless self.authorized_keys_enabled? - - gitlab_authorized_keys.clear - end - - # Remove SSH keys from gitlab shell that are not in the DB - # - # @example Remove keys not on the database - # remove_keys_not_found_in_db - # - # rubocop: disable CodeReuse/ActiveRecord - def remove_keys_not_found_in_db - return unless self.authorized_keys_enabled? - - Rails.logger.info("Removing keys not found in DB") # rubocop:disable Gitlab/RailsLogger - - batch_read_key_ids do |ids_in_file| - ids_in_file.uniq! - keys_in_db = Key.where(id: ids_in_file) - - next unless ids_in_file.size > keys_in_db.count # optimization - - ids_to_remove = ids_in_file - keys_in_db.pluck(:id) - ids_to_remove.each do |id| - Rails.logger.info("Removing key-#{id} not found in DB") # rubocop:disable Gitlab/RailsLogger - remove_key("key-#{id}") - end - end - end - # rubocop: enable CodeReuse/ActiveRecord - # Add empty directory for storing repositories # # @example Add new namespace directory @@ -372,14 +294,6 @@ module Gitlab File.join(Gitlab.config.repositories.storages[storage].legacy_disk_path, dir_name) end - def authorized_keys_enabled? - # Return true if nil to ensure the authorized_keys methods work while - # fixing the authorized_keys file during migration. - return true if Gitlab::CurrentSettings.current_application_settings.authorized_keys_enabled.nil? - - Gitlab::CurrentSettings.current_application_settings.authorized_keys_enabled - end - private def git_timeout @@ -394,32 +308,6 @@ module Gitlab raise Error, e end - def gitlab_authorized_keys - @gitlab_authorized_keys ||= Gitlab::AuthorizedKeys.new - end - - def batch_read_key_ids(batch_size: 100, &block) - return unless self.authorized_keys_enabled? - - gitlab_authorized_keys.list_key_ids.lazy.each_slice(batch_size) do |key_ids| - yield(key_ids) - end - end - - def strip_key(key) - key.split(/[ ]+/)[0, 2].join(' ') - end - - def add_keys_to_io(keys, io) - keys.each do |k| - key = strip_key(k.key) - - raise Error.new("Invalid key: #{key.inspect}") if key.include?("\t") || key.include?("\n") - - io.puts("#{k.shell_id}\t#{key}") - end - end - class GitalyGitlabProjects attr_reader :shard_name, :repository_relative_path, :output, :gl_project_path diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake index ba3e19caf3b..6586699f8ba 100644 --- a/lib/tasks/gitlab/shell.rake +++ b/lib/tasks/gitlab/shell.rake @@ -89,10 +89,12 @@ namespace :gitlab do puts "" end - Gitlab::Shell.new.remove_all_keys + authorized_keys = Gitlab::AuthorizedKeys.new + + authorized_keys.clear Key.find_in_batches(batch_size: 1000) do |keys| - unless Gitlab::Shell.new.batch_add_keys(keys) + unless authorized_keys.batch_add_keys(keys) puts "Failed to add keys...".color(:red) exit 1 end @@ -103,7 +105,7 @@ namespace :gitlab do end def ensure_write_to_authorized_keys_is_enabled - return if Gitlab::CurrentSettings.current_application_settings.authorized_keys_enabled + return if Gitlab::CurrentSettings.authorized_keys_enabled? puts authorized_keys_is_disabled_warning @@ -113,7 +115,7 @@ namespace :gitlab do end puts 'Enabling the "Write to authorized_keys file" setting...' - Gitlab::CurrentSettings.current_application_settings.update!(authorized_keys_enabled: true) + Gitlab::CurrentSettings.update!(authorized_keys_enabled: true) puts 'Successfully enabled "Write to authorized_keys file"!' puts '' |