...
 
Commits (2)
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.3
......@@ -10,3 +12,8 @@ Style/FrozenStringLiteralComment:
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
- 'lib/debci/api.rb' # documentation
Metrics/ClassLength:
Exclude:
- 'lib/debci/api.rb' # documentation
......@@ -15,10 +15,6 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
......@@ -321,11 +317,16 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 260
Exclude:
- 'spec/**/*.rb'
- 'lib/debci/api.rb'
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 299
Exclude:
- 'lib/debci/api.rb'
# Offense count: 2
Metrics/CyclomaticComplexity:
......
require 'debci/api'
require 'debci/self_service'
require 'sinatra/content_for'
LISTING = <<~HTMLBLOCK.freeze
<!DOCTYPE html>
......@@ -48,6 +50,9 @@ app = Rack::Builder.new do
map '/api' do
run Debci::API
end
map '/self_service' do
run Debci::SelfService
end
end
run app
......@@ -5,6 +5,7 @@ require 'rdoc'
require 'securerandom'
require 'sinatra'
require "sinatra/namespace"
require "sinatra/content_for"
require 'time'
require 'debci'
......@@ -13,6 +14,7 @@ require 'debci/key'
class SelfDocAPI < Sinatra::Base
helpers Sinatra::ContentFor
get '/doc' do
@doc = self.class.doc
erb :doc
......@@ -243,8 +245,11 @@ module Debci
data.to_json
end
before '/test/:suite/:arch*'do
authenticate!
before '/test/:suite/:arch*' do
@user = ENV['FAKE_CERTIFICATE_USER'] || env['SSL_CLIENT_S_DN_CN']
if not @user
authenticate!
end
@suite = params[:suite]
@arch = params[:arch]
if !Debci.config.arch_list.include?(arch)
......
require 'debci/api'
require 'debci/self_service'
run Debci::API
run Debci::SelfService
......@@ -123,6 +123,9 @@ module Debci
private
# yield_content should do nothing in the Debci::HTML context
def yield_content(template); end
def templates
@templates ||= {}
end
......
......@@ -38,6 +38,9 @@
<li><a href="/api/">API</a></li>
<li><a href="/data/">Data</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/self_service">Self Service</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
......@@ -70,5 +73,6 @@
<script type="text/javascript" src="<%= @root %>/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%= @root %>/app.js"></script>
<%= @footer %>
<%= yield_content :javascript %>
</body>
</html>
<ol class="breadcrumb">
<li><a href="/self_service">Welcome <%= @user %>!</a></li>
<li class="active">Request Test</li>
</ol>
<header class="well">
<h1>Request Test</h1>
<p>You can choose to request a test by either uploading a JSON file or by filling the form.</p>
</header>
<div class="col-xs-12">
<div class="page-header">
<h3>Upload JSON file</h3>
</div>
<form action="/self_service/test/upload" method="post">
<div class="form-group">
<input name="tests" type="file" id="submit-json">
<p class="help-block">You can get an example JSON through exporting the filled-out form below.</p>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-default" autocomplete="off">
Upload JSON File
</button>
</div>
</form>
<div class="page-header">
<h3>Test Request Form</h3>
</div>
<form action="/self_service/test/submit" method="post">
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="trigger">Trigger</label>
<input class="form-control" id="trigger" name="trigger">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="package">Package Name</label>
<input class="form-control" id="package" name="package">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="suite">Suite</label>
<select class="form-control" id="suite" name="suite">
<% @suites.each do |suite| %>
<option><%= suite %></option>
<% end %>
</select>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<label>Architecture</label>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<% @archs.each do |arch| %>
<label class="checkbox-inline">
<input name="arch[]" type="checkbox" value="<%= arch %>"><%= arch %>
</label>
<% end %>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="pin-packages">Pin Packages</label>
<textarea id="pin-packages" name="pin_packages" class="form-control" rows="5" style="resize: vertical"
placeholder="src:bar, experimental"></textarea>
<p class="help-block">
Pin packages are packages that need to be obtained from the main suite that you selected.<br>
This is used e.g. to run tests on testing with a few packages from unstable, or on unstable with a few packages
from experimental.
</p>
<p class="help-block">
Format should be <code>package, ..., package, suite</code><br>
Examples:<br>
<ul>
<li><code>src:bar, unstable</code>: get all binaries built from bar from unstable</li>
<li><code>foo, src:bar, stable</code>: get foo and all binaries built from bar from stable</li>
</ul>
<strong>Note: each suite can be only present once. please seperate by line.</strong>
</p>
</div>
<button type="submit" name="submit" class="btn btn-default" autocomplete="off">
Submit
</button>
<button type="submit" name="export" class="btn btn-default" autocomplete="off">
Export to JSON
</button>
</form>
</div>
<% content_for :javascript do %>
<script>
// put JavaScript for this page here if needed.
</script>
<% end %>
\ No newline at end of file
require 'sinatra'
require 'json'
require 'debci/test'
module Debci
class SelfService < Sinatra::Base
helpers Sinatra::ContentFor
set :views, File.dirname(__FILE__) + '/html'
before '/*' do
@user = ENV['FAKE_CERTIFICATE_USER'] || env['SSL_CLIENT_S_DN_CN']
if not @user
# TODO: change to unauthenticated template
halt(403, "Unauthenticated!\n")
end
end
get '/' do
@suites = Debci.config.suite_list
@archs = Debci.config.arch_list
erb :self_service
end
post '/test/submit' do
trigger = params[:trigger]
package = params[:package]
suite = params[:suite]
arch = params[:arch]
pin_packages = params[:pin_packages].split(/\n+|\r+/).reject(&:empty?)
temp_obj = {}
temp_obj['trigger'] = trigger
temp_obj['package'] = package
temp_obj['suite'] = suite
temp_obj['arch'] = arch
temp_obj['pin-packages']= []
pin_packages.each do |pin_package|
pin_package = pin_package.split(/,\s*/)
temp_obj['pin-packages'].push(pin_package)
end
if params[:export]
[temp_obj].to_json
else
Debci::Test.request_tests([temp_obj], @user)
end
201
end
post '/test/upload' do
begin
tests_file = File.read(params[:tests])
tests = JSON.load(tests_file)
if not tests.kind_of?(Array)
raise "Not an array"
end
Debci::Test.request_tests(tests, @user)
rescue JSON::ParserError => error
halt(400, "Invalid JSON: #{error}")
rescue => error
halt(400, "Error: #{error}")
else
201
end
end
end
end
module Debci
class Test
class << self
def enqueue(job)
priority = 1
job.enqueue(priority)
end
def create_job(package, suite, arch, requestor, status, trigger, pin_packages)
job = Debci::Job.create!(
package: package,
suite: suite,
arch: arch,
requestor: requestor,
status: status,
trigger: trigger,
pin_packages: pin_packages,
)
end
def request_tests(tests, requestor)
tests.each do |test|
pkg = test['package']
enqueue = true
status = nil
if Debci.blacklist.include?(pkg) || !Debci::API.valid_package_name?(pkg)
enqueue = false
status = 'fail'
end
test['arch'].each do |arch|
job = self.create_job(test['package'], test['suite'], arch, requestor, status, test['trigger'], test['pin-packages'])
self.enqueue(job) if enqueue
end
end
end
end
end
end
\ No newline at end of file