Welcome to mirror list, hosted at ThFree Co, Russian Federation.

migration.rb « container_registry « internal « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b84e14c6f318b3ee2c903cadd094341c7561d1e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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