diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 09:07:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 09:07:58 +0000 |
commit | 45b4df3e57c949c88107840c44ccbfaf2eabdf26 (patch) | |
tree | f73c1533a75b03d2ceb1361644e0d8ab97568a8f /lib/api | |
parent | 7421e6f9f2b5889b05738af7eba568af6ae3fcbc (diff) | |
download | gitlab-ce-45b4df3e57c949c88107840c44ccbfaf2eabdf26.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/container_registry_event.rb | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 02b3fe7e03e..bc333880bbd 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -121,6 +121,7 @@ module API mount ::API::BroadcastMessages mount ::API::Commits mount ::API::CommitStatuses + mount ::API::ContainerRegistryEvent mount ::API::DeployKeys mount ::API::DeployTokens mount ::API::Deployments diff --git a/lib/api/container_registry_event.rb b/lib/api/container_registry_event.rb new file mode 100644 index 00000000000..6d93cc65336 --- /dev/null +++ b/lib/api/container_registry_event.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module API + class ContainerRegistryEvent < Grape::API + DOCKER_DISTRIBUTION_EVENTS_V1_JSON = 'application/vnd.docker.distribution.events.v1+json' + + before { authenticate_registry_notification! } + + resource :container_registry_event do + helpers do + def authenticate_registry_notification! + secret_token = Gitlab.config.registry.notification_secret + + unauthorized! unless Devise.secure_compare(secret_token, headers['Authorization']) + end + end + + # Docker Registry sends data in a body of the request as JSON string, + # by setting 'content_type' we make Grape to parse it automatically + content_type :json, DOCKER_DISTRIBUTION_EVENTS_V1_JSON + format :json + + params do + requires :events, type: Array + end + + # This endpoint is used by Docker Registry to push a set of event + # that took place recently. + post 'events' do + params['events'].each do |raw_event| + event = ::ContainerRegistry::Event.new(raw_event) + + if event.supported? + event.handle! + event.track! + end + end + + status :ok + end + end + end +end |