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
64
module API
# Projects API
class Services < Grape::API
before { authenticate! }
before { authorize_admin_project }
resource :projects do
# Set <service_slug> service for project
#
# Example Request:
#
# PUT /projects/:id/services/gitlab-ci
#
put ':id/services/:service_slug' do
if project_service
validators = project_service.class.validators.select do |s|
s.class == ActiveRecord::Validations::PresenceValidator &&
s.attributes != [:project_id]
end
required_attributes! validators.map(&:attributes).flatten.uniq
attrs = attributes_for_keys service_attributes
if project_service.update_attributes(attrs.merge(active: true))
true
else
not_found!
end
end
end
# Delete <service_slug> service for project
#
# Example Request:
#
# DELETE /project/:id/services/gitlab-ci
#
delete ':id/services/:service_slug' do
if project_service
attrs = service_attributes.inject({}) do |hash, key|
hash.merge!(key => nil)
end
if project_service.update_attributes(attrs.merge(active: false))
true
else
not_found!
end
end
end
# Get <service_slug> service settings for project
#
# Example Request:
#
# GET /project/:id/services/gitlab-ci
#
get ':id/services/:service_slug' do
present project_service, with: Entities::ProjectService, include_passwords: current_user.is_admin?
end
end
end
end