2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
class ContainerRegistryEvent < ::API::Base
|
2020-04-22 19:07:51 +05:30
|
|
|
DOCKER_DISTRIBUTION_EVENTS_V1_JSON = 'application/vnd.docker.distribution.events.v1+json'
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
feature_category :container_registry
|
|
|
|
urgency :low
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Receives notifications from the container registry when an operation occurs' do
|
|
|
|
detail 'This feature was introduced in GitLab 12.10'
|
|
|
|
consumes [:json, DOCKER_DISTRIBUTION_EVENTS_V1_JSON]
|
2023-03-04 22:38:38 +05:30
|
|
|
success code: 200, message: 'Success'
|
|
|
|
failure [
|
|
|
|
{ code: 401, message: 'Invalid Token' }
|
|
|
|
]
|
|
|
|
tags %w[container_registry_event]
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|