Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
and use it for webapi and scheduler
- Loading branch information
Showing
9 changed files
with
232 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (C) 2016 SUSE LLC | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
package OpenQA::Scheduler::FakeApp; | ||
use Mojo::Log; | ||
use strict; | ||
use warnings; | ||
|
||
# implementing the interface of Mojolicious we need to get the rest doing debug | ||
sub new { | ||
my ($class) = @_; | ||
my $self = bless {}, $class; | ||
$self->{config} = {}; | ||
$self->{log} = Mojo::Log->new; | ||
return $self; | ||
} | ||
|
||
sub mode { | ||
my ($self) = @_; | ||
return 'production'; | ||
} | ||
|
||
sub config { | ||
my ($self) = @_; | ||
return $self->{config}; | ||
} | ||
|
||
sub log { | ||
my ($self) = @_; | ||
return $self->{log}; | ||
} | ||
|
||
sub schema { | ||
my ($self) = @_; | ||
return OpenQA::Schema::connect_db(); | ||
} | ||
|
||
sub log_name { | ||
my ($self) = @_; | ||
return 'scheduler'; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright (C) 2015-2016 SUSE LLC | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
# This package contains shared functions between WebAPI and WebSockets | ||
package OpenQA::ServerStartup; | ||
|
||
use strict; | ||
use warnings; | ||
use Config::IniFiles; | ||
use db_profiler; | ||
use db_helpers; | ||
use OpenQA::Utils; | ||
|
||
sub read_config { | ||
my $app = shift; | ||
|
||
my %defaults = ( | ||
global => { | ||
appname => 'openQA', | ||
base_url => undef, | ||
branding => 'openSUSE', | ||
allowed_hosts => undef, | ||
download_domains => undef, | ||
suse_mirror => undef, | ||
scm => undef, | ||
hsts => 365, | ||
audit_enabled => 1, | ||
plugins => undef, | ||
hide_asset_types => 'repo', | ||
}, | ||
auth => { | ||
method => 'OpenID', | ||
}, | ||
'scm git' => { | ||
do_push => 'no', | ||
}, | ||
logging => { | ||
level => undef, | ||
file => undef, | ||
sql_debug => undef, | ||
}, | ||
openid => { | ||
provider => 'https://www.opensuse.org/openid/user/', | ||
httpsonly => 1, | ||
}, | ||
hypnotoad => { | ||
listen => ['http://localhost:9526/'], | ||
proxy => 1, | ||
}, | ||
audit => { | ||
blacklist => '', | ||
}, | ||
); | ||
|
||
# in development mode we use fake auth and log to stderr | ||
my %mode_defaults = ( | ||
development => { | ||
auth => { | ||
method => 'Fake', | ||
}, | ||
logging => { | ||
file => undef, | ||
level => 'debug', | ||
}, | ||
}, | ||
test => { | ||
auth => { | ||
method => 'Fake', | ||
}, | ||
logging => { | ||
file => undef, | ||
level => 'debug', | ||
}, | ||
}); | ||
|
||
# Mojo's built in config plugins suck. JSON for example does not | ||
# support comments | ||
my $cfgpath = $ENV{OPENQA_CONFIG} || $app->home . '/etc/openqa'; | ||
my $cfg = Config::IniFiles->new(-file => $cfgpath . '/openqa.ini') || undef; | ||
|
||
for my $section (sort keys %defaults) { | ||
for my $k (sort keys %{$defaults{$section}}) { | ||
my $v = $cfg && $cfg->val($section, $k); | ||
$v //= exists $mode_defaults{$app->mode}{$section}->{$k} ? $mode_defaults{$app->mode}{$section}->{$k} : $defaults{$section}->{$k}; | ||
$app->config->{$section}->{$k} = $v if defined $v; | ||
} | ||
} | ||
$app->config->{_openid_secret} = db_helpers::rndstr(16); | ||
} | ||
|
||
sub _log_format { | ||
my ($app, $time, $level, @lines) = @_; | ||
return '[' . localtime($time) . "] [" . $app->log_name . ":$level] " . join "\n", @lines, ''; | ||
} | ||
|
||
sub setup_logging { | ||
my ($app) = @_; | ||
|
||
my $config = $app->config; | ||
my $logfile = $ENV{OPENQA_LOGFILE} || $config->{logging}->{file}; | ||
$app->log->path($logfile); | ||
$app->log->format(sub { _log_format($app, @_); }); | ||
|
||
if ($logfile && $config->{logging}->{level}) { | ||
$app->log->level($config->{logging}->{level}); | ||
} | ||
if ($ENV{OPENQA_SQL_DEBUG} // $config->{logging}->{sql_debug} // 'false' eq 'true') { | ||
# avoid enabling the SQL debug unless we really want to see it | ||
# it's rather expensive | ||
db_profiler::enable_sql_debugging($app); | ||
} | ||
|
||
$OpenQA::Utils::app = $app; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.