diff --git a/Build.PL b/Build.PL index 9ad44d50..d3116373 100644 --- a/Build.PL +++ b/Build.PL @@ -9,8 +9,10 @@ my $builder = Module::Build->new( 'DBIx::Class::Schema::Loader' => 0, 'File::Path' => 0, 'Getopt::Long' => 0, + 'MooseX::ClassAttribute' => 0, 'MooseX::FileAttribute' => 0, 'MooseX::NonMoose' => 0, + 'MooseX::Singleton' => 0, 'namespace::sweep' => 0, 'Quantum::Superpositions' => 0, 'Pod::Usage' => 0, diff --git a/lib/NGCP/Schema.pm b/lib/NGCP/Schema.pm index 1a07d5e7..bdcb2e54 100644 --- a/lib/NGCP/Schema.pm +++ b/lib/NGCP/Schema.pm @@ -7,7 +7,9 @@ use Regexp::IPv6 qw($IPv6_re); our $VERSION = '1.000'; -has('config', is => 'rw', lazy => 1, default => sub { NGCP::Schema::Config->new->config }); +has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); method validate($data, $mandatory_params, $optional_params?) { Exception->throw({ @@ -40,7 +42,7 @@ method check_domain($data) { $self->validate($data, ['domain']); my $domain = $data->{domain}; return 1 if $domain =~ /^(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]+$/i; - return 1 if $self->config->config->{allow_ip_as_domain} + return 1 if $self->config->as_hash->{allow_ip_as_domain} and ($self->check_ip4({ip4 => $domain}) || $self->check_ip6_brackets({ip6brackets => $domain})); return; } diff --git a/lib/NGCP/Schema/Config.pm b/lib/NGCP/Schema/Config.pm index ceb251c2..76a3e4b6 100644 --- a/lib/NGCP/Schema/Config.pm +++ b/lib/NGCP/Schema/Config.pm @@ -2,12 +2,13 @@ package NGCP::Schema::Config; use Sipwise::Base; use Log::Log4perl qw(); use MooseX::FileAttribute qw(has_file); +use MooseX::Singleton qw(has); use XML::Simple qw(); our $VERSION = '1.000'; has_file('config_file', is => 'rw', required => 1, default => '/etc/ngcp-ossbss/provisioning.conf'); -has('config', isa => 'HashRef', is => 'rw', lazy => 1, default => method { +has('as_hash', isa => 'HashRef', is => 'rw', lazy => 1, default => method { return $self->check_config(XML::Simple->new->XMLin($self->config_file->stringify, ForceArray => 0)); }); diff --git a/lib/NGCP/Schema/accounting.pm b/lib/NGCP/Schema/accounting.pm index b439fe12..7df465d8 100644 --- a/lib/NGCP/Schema/accounting.pm +++ b/lib/NGCP/Schema/accounting.pm @@ -13,7 +13,15 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-04-09 12:30:37 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/gINj3OenRQkhpdpfbQq4Q +use MooseX::ClassAttribute qw(class_has); + +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); + +method connection { + my %connect_info = %{ $self->config->as_hash->{accountingdb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} -# You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable(inline_constructor => 0); -1; diff --git a/lib/NGCP/Schema/billing.pm b/lib/NGCP/Schema/billing.pm index 830eb76f..ea476f08 100644 --- a/lib/NGCP/Schema/billing.pm +++ b/lib/NGCP/Schema/billing.pm @@ -13,15 +13,24 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-04-09 12:33:44 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pFNyB1lQTWbvEckC6oqjJw +use MooseX::ClassAttribute qw(class_has); use NGCP::Schema qw(); use NGCP::Schema::provisioning qw(); use aliased 'NGCP::Schema::Exception'; +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); has('validator', is => 'rw', isa => 'NGCP::Schema', lazy => 1, default => sub { return NGCP::Schema->new; }); has('provisioning', is => 'rw', isa => 'NGCP::Schema::provisioning', lazy => 1, default => sub { return NGCP::Schema::provisioning->connect; }); +method connection { + my %connect_info = %{ $self->config->as_hash->{billingdb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} + method get_domain($reseller_id, $domain) { my %return; $return{domain} = $domain; diff --git a/lib/NGCP/Schema/carrier.pm b/lib/NGCP/Schema/carrier.pm index 23de4ef2..28c93fa4 100644 --- a/lib/NGCP/Schema/carrier.pm +++ b/lib/NGCP/Schema/carrier.pm @@ -13,7 +13,15 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-04-09 12:33:48 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2tiLLQMoqYYiicae6bptbA +use MooseX::ClassAttribute qw(class_has); + +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); + +method connection { + my %connect_info = %{ $self->config->as_hash->{carrierdb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} -# You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable(inline_constructor => 0); -1; diff --git a/lib/NGCP/Schema/kamailio.pm b/lib/NGCP/Schema/kamailio.pm index 0317613a..27340eb5 100644 --- a/lib/NGCP/Schema/kamailio.pm +++ b/lib/NGCP/Schema/kamailio.pm @@ -13,7 +13,15 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-04-09 12:33:56 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:F+YCA+y1IL8DMrefBOhpIg +use MooseX::ClassAttribute qw(class_has); + +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); + +method connection { + my %connect_info = %{ $self->config->as_hash->{kamailiodb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} -# You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable(inline_constructor => 0); -1; diff --git a/lib/NGCP/Schema/ngcp.pm b/lib/NGCP/Schema/ngcp.pm index e2e62d52..f762e3f9 100644 --- a/lib/NGCP/Schema/ngcp.pm +++ b/lib/NGCP/Schema/ngcp.pm @@ -13,7 +13,15 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-04-09 12:33:59 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:P/HNiALDBrupRVTapqCHkg +use MooseX::ClassAttribute qw(class_has); + +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); + +method connection { + my %connect_info = %{ $self->config->as_hash->{ngcpdb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} -# You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable(inline_constructor => 0); -1; diff --git a/lib/NGCP/Schema/provisioning.pm b/lib/NGCP/Schema/provisioning.pm index 35c46c70..331b50a0 100644 --- a/lib/NGCP/Schema/provisioning.pm +++ b/lib/NGCP/Schema/provisioning.pm @@ -13,11 +13,20 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-04-09 12:34:07 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9CSthIxIDhU92F42rZZoQQ +use MooseX::ClassAttribute qw(class_has); use NGCP::Schema qw(); use aliased 'NGCP::Schema::Exception'; +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); has('validator', is => 'rw', isa => 'NGCP::Schema', lazy => 1, default => sub { return NGCP::Schema->new; }); +method connection { + my %connect_info = %{ $self->config->as_hash->{provisioningdb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} + method _get_domain_id($domain) { my $domainid; try { diff --git a/lib/NGCP/Schema/sipstats.pm b/lib/NGCP/Schema/sipstats.pm index 105c7777..ad62ad73 100644 --- a/lib/NGCP/Schema/sipstats.pm +++ b/lib/NGCP/Schema/sipstats.pm @@ -13,7 +13,15 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-04-09 12:34:11 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Uqcm6asjrNcv63rMCeWfiQ +use MooseX::ClassAttribute qw(class_has); + +class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { + return NGCP::Schema::Config->instance; +}); + +method connection { + my %connect_info = %{ $self->config->as_hash->{sipstatsdb} }; + $self->SUPER::connection(@connect_info{qw(dsn username password)}); +} -# You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable(inline_constructor => 0); -1;