summaryrefslogtreecommitdiff
path: root/lib/api/container_registry_event.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-30 09:07:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-30 09:07:58 +0000
commit45b4df3e57c949c88107840c44ccbfaf2eabdf26 (patch)
treef73c1533a75b03d2ceb1361644e0d8ab97568a8f /lib/api/container_registry_event.rb
parent7421e6f9f2b5889b05738af7eba568af6ae3fcbc (diff)
downloadgitlab-ce-45b4df3e57c949c88107840c44ccbfaf2eabdf26.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/container_registry_event.rb')
-rw-r--r--lib/api/container_registry_event.rb43
1 files changed, 43 insertions, 0 deletions
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