From 03946ef229ed8658c244f12b9655806e12a2a524 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Wed, 11 Apr 2012 16:18:33 +0000 Subject: [PATCH] Connect as user sipwise to ngcp database. From: Michael Prokop --- debian/control | 2 +- ngcp-check-rev-applied | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index a84f5ec8..00873f96 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Homepage: http://sipwise.com/ Package: ngcp-db-schema Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends}, libconfig-tiny-perl Description: database schema for Sipwise's NGCP platform This package provides the database schema for Sipwise's NGCP platform. diff --git a/ngcp-check-rev-applied b/ngcp-check-rev-applied index 0e6eecec..17e860b1 100755 --- a/ngcp-check-rev-applied +++ b/ngcp-check-rev-applied @@ -5,6 +5,7 @@ use warnings; use DBI; use Getopt::Long; use Pod::Usage; +use Config::Tiny; my $dbhost = 'localhost'; my $dbname = 'ngcp'; @@ -31,7 +32,18 @@ pod2usage(-exitval => 2, -verbose => 2) if $man; pod2usage(2) if !defined $revision; pod2usage(2) if !defined $schema; -my $dbh = DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost") +# connect as user sipwise to DB +my $Config = Config::Tiny->read('/etc/mysql/sipwise.cnf') or die "Could not read /etc/mysql/sipwise.cnf"; +my $dbuser = 'sipwise'; +my $dbpwd = $Config->{_}->{SIPWISE_DB_PASSWORD}; + +if (!defined $dbpwd) { + die "Couldn't identify password for user sipwise to connect to database."; +} + +$dbpwd =~ s/^['"](.*)['"]$/$1/g; # get rid of possibly surrounding quotes + +my $dbh = DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost", $dbuser, $dbpwd) or die "Couldn't connect to database: " . DBI->errstr; $schema = $dbh->quote_identifier($schema);