* UI and API parts are now under license control * new Util::License::get_license($c, $name) - fetches license status by name (1 if enabled, and also if /proc/ngcp/check if 'ok') * add Catalyst::Plugins::NGCP::License with license($name) to fetch valid license by name from anywhere using $c->license('pbx') or from the templates using c.license('pbx'). It internally uses Util::License::get_license($c, $name) * License::get_license_status($c) now requires $c as first argument as well logs license status check errors. * new ActionRoles::License that enables usage of :Does(License) RequiresLicense('pbx') LicenseDetachTo('/denied_page') in the Controller chains * Add license control for UI elements and return 403 Forbidden if a resource is covered by licenses and the license is not active * Hide UI elements if a license is not active * API/Entities/Entities new $c->set_config key: - per endpoint: $c->set_config({ required_licenses => [qw/pbx device_provisioning/] } - or per method: $c->set_config({ required_licenses => { POST => [qw/pbx device_provisioning/] } } } * In case if an API endpoint does not have a license: 403 Forbidden "Invalid license" reply is returned. * Add license based restrictions to API endpoints * /api documentation: - completely hide endpoints that do not have an active license - hide only methods that does not have an active license Change-Id: Iba45fc5068b02306a617fed7b5405f2210574b61mr13.0
parent
9c103302c8
commit
9d021be65a
@ -0,0 +1,33 @@
|
||||
package Catalyst::Plugin::NGCP::License;
|
||||
use warnings;
|
||||
use strict;
|
||||
use MRO::Compat;
|
||||
|
||||
use NGCP::Panel::Utils::Generic qw();
|
||||
|
||||
sub licenses {
|
||||
return NGCP::Panel::Utils::License::get_licenses(@_);
|
||||
}
|
||||
|
||||
sub license {
|
||||
return NGCP::Panel::Utils::License::get_license(@_);
|
||||
}
|
||||
|
||||
sub license_meta {
|
||||
return NGCP::Panel::Utils::License::get_license_meta(@_);
|
||||
}
|
||||
|
||||
sub license_max_pbx_groups {
|
||||
return NGCP::Panel::Utils::License::get_max_pbx_groups(@_);
|
||||
}
|
||||
|
||||
sub license_max_subscribers {
|
||||
return NGCP::Panel::Utils::License::get_max_subscribers(@_);
|
||||
}
|
||||
|
||||
sub license_max_pbx_subscribers {
|
||||
return NGCP::Panel::Utils::License::get_max_pbx_subscribers(@_);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -0,0 +1,93 @@
|
||||
package NGCP::Panel::ActionRole::License;
|
||||
use Moose::Role;
|
||||
use namespace::autoclean;
|
||||
|
||||
sub BUILD { }
|
||||
|
||||
after BUILD => sub {
|
||||
my $class = shift;
|
||||
my ($args) = @_;
|
||||
|
||||
my $attr = $args->{attributes};
|
||||
|
||||
unless (exists $attr->{RequiresLicense} || exists $attr->{AllowedLicense}) {
|
||||
Catalyst::Exception->throw(
|
||||
"Action '$args->{reverse}' requires at least one RequiresLicense or AllowedLicense attribute");
|
||||
}
|
||||
unless (exists $attr->{LicenseDetachTo} && $attr->{LicenseDetachTo}) {
|
||||
Catalyst::Exception->throw(
|
||||
"Action '$args->{reverse}' requires the LicenseDetachTo(<action>) attribute");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
around execute => sub {
|
||||
my $orig = shift;
|
||||
my $self = shift;
|
||||
my ($controller, $c) = @_;
|
||||
|
||||
if ($self->check_license($c)) {
|
||||
return $self->$orig(@_);
|
||||
}
|
||||
|
||||
my $denied = $self->attributes->{ACLDetachTo}[0];
|
||||
|
||||
$c->detach($denied);
|
||||
};
|
||||
|
||||
sub check_license {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $required = $self->attributes->{RequiresLicense};
|
||||
my $allowed = $self->attributes->{AllowedLicense};
|
||||
|
||||
if ($required && $allowed) {
|
||||
for my $license (@$required) {
|
||||
return unless $c->license($license);
|
||||
}
|
||||
for my $license (@$allowed) {
|
||||
return 1 if $c->license($license);
|
||||
}
|
||||
return;
|
||||
}
|
||||
elsif ($required) {
|
||||
for my $license (@$required) {
|
||||
return unless $c->license($license);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
elsif ($allowed) {
|
||||
for my $license (@$allowed) {
|
||||
return 1 if $c->license($license);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NGCP::Panel::ActionRole::License
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A helper to check NGCP License info
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Sipwise Development Team <support@sipwise.com>
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
This library is free software. You can redistribute it and/or modify
|
||||
it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
# vim: set tabstop=4 expandtab:
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue