1

Introduce buildinfo.pm, update sample config update TODO

+ Add buildinfo.pm - api for slackbuild env metadata
* Update .psgi files
* update sample config
* update TODO - remove checked-in milestones
This commit is contained in:
eleksir
2019-11-14 01:43:38 +03:00
parent 8a02a37c7a
commit 457d289f1c
6 changed files with 80 additions and 6 deletions

4
TODO
View File

@@ -5,12 +5,10 @@
* paste/link shortener
* shortener api for goo.gl or same services
* paste api for some pastebins
* image downloader
* repo uploader
* metagen.pm: make metadata files in atomic way
* metagen.pm: validate metadata
* simple monitoring api (common metrics: cpu, mem, swap, la, etc)
* jabber bot: send memos to offline participants when they return
* announce youtube video title
* common bot functions move to separate module
* bot bridge telegram-irc-jabber
* anounce html page title

View File

@@ -46,4 +46,8 @@
"myslack" : "/var/www/repo/myslack",
"stuff" : "/var/www/repo/stuff"
},
"buildinfo" : {
"backports" : "/path/to/myslack.json",
"thrirdparty" : "/path/to/stuff.json"
}
}

66
lib/buildinfo.pm Normal file
View File

@@ -0,0 +1,66 @@
package buildinfo;
use strict;
use warnings "all";
use vars qw/$VERSION/;
use conf;
use JSON::PP;
use Data::Dumper;
use Exporter qw(import);
our @EXPORT = qw(buildinfo);
$VERSION = "1.0";
my $c = loadConf();
sub buildinfo($) {
my $repo = shift;
my ($status, $content, $msg) = ('400', 'text/plain', "Bad Request?\n");
return ($status, $content, $msg) unless ($repo =~ /\//);
my ($config, $package) = split(/\//, $repo);
unless (defined($c->{buildinfo}->{$config})) {
$msg = "Config repo $config is not defined in config.\n";
return ($status, $content, $msg);
}
open (JSON, "<", $c->{buildinfo}->{$config}) or do {
$status = '500';
$msg = "Unable to open $c->{buildinfo}->{$config}; $!\n";
return ($status, $content, $msg);
};
my $sep = $/;
my $json = <JSON>;
close JSON;
$/ = $sep;
my $j = eval { decode_json($json) } or do {
$status = '500';
$msg = "Error during decoding $c->{buildinfo}->{$config}; $@\n";
return ($status, $content, $msg);
};
unless (defined($j->{$package})) {
$msg = "$package is not defined in config for $config.\n";
return ($status, $content, $msg);
}
$json = JSON::PP->new->pretty->canonical->indent_length(4)->encode($j->{$package}) or do {
$status = '500';
$msg = "Unable to encode json.\n";
return ($status, $content, $msg);
};
$status = '200';
$content = 'application/json';
$msg = $json;
return ($status, $content, $msg);
}
1;
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:

View File

@@ -5,7 +5,7 @@ use warnings "all";
use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5);
use conf;
use jabberbot;
use telegrambot;
use ircbot;
use threads;
my $CONF = loadConf();
@@ -14,7 +14,7 @@ if ($CONF->{api}->{prefix} eq '/') { $CONF->{api}->{prefix} = ''; }
my $prefix = $CONF->{api}->{prefix};
threads->create('run_jabberbot')->detach;
threads->create('run_telegrambot')->detach;
threads->create('run_ircbot')->detach;
my $app = sub {
my $env = shift;

View File

@@ -13,7 +13,7 @@ open (C, $conf) || die "No such file $conf\n";
$jstr = <C>;
close C;
my $c = decode_json($jstr);
my $c = JSON::PP->new->decode($jstr);
my $j = JSON::PP->new->pretty->canonical->indent_length(4);
print $j->encode($c);

View File

@@ -6,6 +6,7 @@ use lib qw(./lib ./vendor_perl ./vendor_perl/lib/perl5);
use conf;
use upload;
use metagen;
use buildinfo;
my $CONF = loadConf();
@@ -38,7 +39,12 @@ my $app = sub {
if (defined($env->{HTTP_REPO})) {
($status, $content, $msg) = metagen($env->{HTTP_REPO});
}
} elsif ($env->{PATH_INFO} eq "$prefix/buildinfo") {
if (defined($env->{HTTP_REPO})) {
($status, $content, $msg) = buildinfo($env->{HTTP_REPO});
}
}
return [