MT#58964 /api/platforminfo add licenses info

* NGCP::Utils::License new function get_licenses()
  that reads /proc/ngcp/flags/ and returns all files
  with content 1.
* api/platforminfo.tt template now calls a stashed
  callback (coderef) that decodes provided json file,
  includes licenses and returns encoded the json back.
* ngcp-panel.service changes
    # Files + directories not directly associated are made
      invisible in the /proc/ file system
    # ProcSubset=pid
    # Disabled: MT#58964, to be able to read /proc/ngcp/flags/

    # Processes owned by other users are hidden from /proc/
    # ProtectProc=invisible
    # Disabled: MT#58964, to be able to read /proc/ngcp/flags/

Change-Id: I84b6707a918e3f4f271e32b9353f320753c5ae68
mr12.5
Kirill Solomko 10 months ago
parent ca908bf629
commit 522fd97020

@ -17,10 +17,12 @@ PIDFile=/run/fastcgi/ngcp-panel.pid
ExecStart=/usr/share/ngcp-panel/ngcp_panel_fastcgi.pl --listen /run/fastcgi/ngcp-panel.sock --pidfile /run/fastcgi/ngcp-panel.pid --nproc $NPROC
# Files + directories not directly associated are made invisible in the /proc/ file system
ProcSubset=pid
# ProcSubset=pid
# Disabled: MT#58964, to be able to read /proc/ngcp/flags/
# Processes owned by other users are hidden from /proc/
ProtectProc=invisible
# ProtectProc=invisible
# Disabled: MT#58964, to be able to read /proc/ngcp/flags/
# Service cannot modify the control group file system (via /sys/fs/cgroup)
ProtectControlGroups=true

@ -9,7 +9,7 @@ use HTTP::Headers qw();
use HTTP::Response qw();
use HTTP::Status qw(:constants);
use File::Find::Rule;
use JSON qw(to_json encode_json);
use JSON qw(to_json encode_json decode_json);
use YAML::XS qw/Dump/;
use Safe::Isa qw($_isa);
use NGCP::Panel::Utils::API;
@ -17,6 +17,7 @@ use List::Util qw(none);
use parent qw/Catalyst::Controller NGCP::Panel::Role::API/;
use NGCP::Panel::Utils::Journal qw();
use NGCP::Panel::Utils::License;
#with 'NGCP::Panel::Role::API';
@ -342,6 +343,17 @@ sub platforminfo :Path('/api/platforminfo') :CaptureArgs(0) {
$c->stash->{ngcp_api_realm} = $c->request->env->{NGCP_API_REALM} // "";
$c->stash(template => 'api/platforminfo.tt');
$c->stash(process_json_file_cb => sub {
my $json_file = shift;
my $json = '';
my $licenses = NGCP::Panel::Utils::License::get_licenses($c);
open(my $fh, '<', $json_file) || return;
$json .= $_ while <$fh>;
close $fh;
my $data = decode_json($json) || return;
$data->{licenses} = $licenses;
return to_json($data, {pretty => 1, canonical => 1});
});
$c->forward($c->view());
}

@ -53,6 +53,37 @@ sub is_license_error {
return $ext || $status;
}
sub get_licenses {
my $c = shift;
my $proc_dir = '/proc/ngcp/flags';
unless (-d $proc_dir) {
$c->log->error("Failed to access $proc_dir");
return;
};
my @lics = ();
opendir(my $dh, $proc_dir) || do {
$c->log->error("Failed to open licenses dir $proc_dir: $!");
return;
};
while (readdir($dh)) {
my $lf = $_;
next if $lf =~ /^\.+$/;
open(my $fh, '<', "$proc_dir/$lf") || do {
$c->log->error("Failed to open license file $lf: $!");
next;
};
my $enabled = <$fh>;
chomp($enabled) if $enabled;
push @lics, $lf if $enabled && $enabled == 1;
close $fh;
}
closedir $dh;
my @sorted_lics = sort @lics;
return \@sorted_lics;
}
1;
=head1 NAME

@ -16,11 +16,11 @@ ELSE;
END;
TRY;
INCLUDE $json_file;
json = c.stash.process_json_file_cb(json_file);
CATCH;
json = '{"error": "an internal error when fetching the config data"}';
END;
json;
-%]
-%]

Loading…
Cancel
Save