-
Notifications
You must be signed in to change notification settings - Fork 445
/
Copy pathbuild_controller.rb
179 lines (152 loc) · 6.31 KB
/
build_controller.rb
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
class BuildController < ApplicationController
def index
# for read access and visibility permission check
if params[:package] && ['_repository', '_jobhistory'].exclude?(params[:package])
Package.get_by_project_and_name(params[:project], params[:package], use_source: false, follow_multibuild: true)
else
Project.get_by_name(params[:project])
end
if request.get?
pass_to_backend
return
end
if User.admin_session?
# check for a local package instance
Package.get_by_project_and_name(params[:project], params[:package], use_source: false, follow_project_links: false)
pass_to_backend
else
render_error status: 403, errorcode: 'execute_cmd_no_permission',
message: 'Upload of binaries is only permitted for administrators'
end
end
def project_index
prj = nil
unless params[:project] == '_dispatchprios'
prj = Project.get_by_name(params[:project])
end
if request.get?
pass_to_backend
return
elsif request.post?
# check if user has project modify rights
allowed = false
allowed = true if permissions.global_project_change
allowed = true if permissions.project_change?(prj)
# check for cmd parameter
if params[:cmd].nil?
raise MissingParameterError, "Missing parameter 'cmd'"
end
unless ['wipe', 'restartbuild', 'killbuild', 'abortbuild', 'rebuild', 'unpublish', 'sendsysrq'].include?(params[:cmd])
render_error status: 400, errorcode: 'illegal_request',
message: "unsupported POST command #{params[:cmd]} to #{request.url}"
return
end
unless prj.class == Project
render_error status: 403, errorcode: 'readonly_error',
message: "The project #{params[:project]} is a remote project and therefore readonly."
return
end
if !allowed && !params[:package].nil?
[params[:package]].flatten.each do |pack_name|
pkg = Package.find_by_project_and_name(prj.name, pack_name)
if pkg.nil?
allowed = permissions.project_change?(prj)
unless allowed
render_error status: 403, errorcode: 'execute_cmd_no_permission',
message: "No permission to execute command on package #{pack_name} in project #{prj.name}"
return
end
else
allowed = permissions.package_change?(pkg)
unless allowed
render_error status: 403, errorcode: 'execute_cmd_no_permission',
message: "No permission to execute command on package #{pack_name}"
return
end
end
end
end
unless allowed
render_error status: 403, errorcode: 'execute_cmd_no_permission',
message: "No permission to execute command on project #{params[:project]}"
return
end
pass_to_backend
return
elsif request.put?
if User.admin_session?
pass_to_backend
else
render_error status: 403, errorcode: 'execute_cmd_no_permission',
message: "No permission to execute command on project #{params[:project]}"
end
return
else
render_error status: 400, errorcode: 'illegal_request',
message: "Illegal request: #{request.method.to_s.upcase} #{request.path}"
return
end
end
def buildinfo
required_parameters :project, :repository, :arch, :package
# just for permission checking
if request.post? && Package.striping_multibuild_suffix(params[:package]) == '_repository'
# for osc local package build in this repository
Project.get_by_name(params[:project])
else
Package.get_by_project_and_name(params[:project], params[:package], use_source: false, follow_multibuild: true)
end
path = "/build/#{params[:project]}/#{params[:repository]}/#{params[:arch]}/#{params[:package]}/_buildinfo"
path += "?#{request.query_string}" unless request.query_string.empty?
pass_to_backend(path)
end
# /build/:project/:repository/:arch/_builddepinfo
def builddepinfo
required_parameters :project, :repository, :arch
# just for permission checking
Project.get_by_name(params[:project])
path = "/build/#{params[:project]}/#{params[:repository]}/#{params[:arch]}/_builddepinfo"
path += "?#{request.query_string}" unless request.query_string.empty?
pass_to_backend(path)
end
def logfile
# for permission check
pkg = Package.get_by_project_and_name(params[:project], params[:package], use_source: true, follow_project_links: true, follow_multibuild: true)
if pkg.class == Package && pkg.project.disabled_for?('binarydownload', params[:repository], params[:arch]) &&
!User.possibly_nobody.can_download_binaries?(pkg.project)
render_error status: 403, errorcode: 'download_binary_no_permission',
message: "No permission to download binaries from package #{params[:package]}, project #{params[:project]}"
return
end
pass_to_backend
end
def result
required_parameters :project
# this route is mainly for checking submissions to a target project
return result_lastsuccess if params.key?(:lastsuccess)
# for permission check
Project.get_by_name(params[:project])
pass_to_backend
end
def result_lastsuccess
required_parameters :package, :pathproject
pkg = Package.get_by_project_and_name(params[:project], params[:package],
use_source: false, follow_project_links: true, follow_multibuild: true)
raise RemoteProjectError, 'The package lifes in a remote project, this is not supported atm' unless pkg
tprj = Project.get_by_name(params[:pathproject])
multibuild_package = params[:package] if params[:package].include?(':')
bs = PackageBuildStatus.new(pkg).result(target_project: tprj, srcmd5: params[:srcmd5], multibuild_pkg: multibuild_package)
@result = []
bs.each do |repo, status|
archs = status.map do |arch, archstat|
if archstat[:missing].blank?
[arch, archstat[:result], nil]
else
[arch, archstat[:result], archstat[:missing].join(',')]
end
end
@result << [repo, archs]
end
render xml: render_to_string(partial: 'lastsuccess')
end
end