diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/api/internal | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/api/internal')
-rw-r--r-- | lib/api/internal/container_registry/migration.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/api/internal/container_registry/migration.rb b/lib/api/internal/container_registry/migration.rb new file mode 100644 index 00000000000..b84e14c6f31 --- /dev/null +++ b/lib/api/internal/container_registry/migration.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +module API + module Internal + module ContainerRegistry + class Migration < ::API::Base + feature_category :container_registry + + STATUS_PRE_IMPORT_COMPLETE = 'pre_import_complete' + STATUS_PRE_IMPORT_FAILED = 'pre_import_failed' + STATUS_IMPORT_COMPLETE = 'import_complete' + STATUS_IMPORT_FAILED = 'import_failed' + POSSIBLE_VALUES = [ + STATUS_PRE_IMPORT_COMPLETE, + STATUS_PRE_IMPORT_FAILED, + STATUS_IMPORT_COMPLETE, + STATUS_IMPORT_FAILED + ].freeze + + before { authenticate! } + + helpers do + def authenticate! + secret_token = Gitlab.config.registry.notification_secret + + unauthorized! unless Devise.secure_compare(secret_token, headers['Authorization']) + end + + def find_repository!(path) + ::ContainerRepository.find_by_path!(::ContainerRegistry::Path.new(path)) + end + end + + params do + requires :repository_path, type: String, desc: 'The container repository path' + requires :status, type: String, values: POSSIBLE_VALUES, desc: 'The migration step status' + end + put 'internal/registry/repositories/*repository_path/migration/status' do + repository = find_repository!(declared_params[:repository_path]) + + unless repository.migration_in_active_state? + bad_request!("Wrong migration state (#{repository.migration_state})") + end + + case declared_params[:status] + when STATUS_PRE_IMPORT_COMPLETE + unless repository.finish_pre_import_and_start_import + bad_request!("Couldn't transition from pre_importing to importing") + end + when STATUS_IMPORT_COMPLETE + unless repository.finish_import + bad_request!("Couldn't transition from importing to import_done") + end + when STATUS_IMPORT_FAILED, STATUS_PRE_IMPORT_FAILED + repository.abort_import + end + + status 200 + end + end + end + end +end |