From 334aec1e11b07485138e686784ecdf25fbf24fef Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Wed, 18 Apr 2018 16:08:37 +0200
Subject: [PATCH] allow database connection options in configuration

---
 bin/access-check-manager.pl.in |  3 ++-
 conf/manager.conf.in           |  1 +
 lib/AccountManager/App.pm      |  1 +
 lib/AccountManager/DB.pm       | 11 +++++++++--
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/bin/access-check-manager.pl.in b/bin/access-check-manager.pl.in
index b09a2c8..6cfcc7a 100755
--- a/bin/access-check-manager.pl.in
+++ b/bin/access-check-manager.pl.in
@@ -58,7 +58,8 @@ AccountManager::DB->register_db(
     database => $configuration->{database}->{name},
     host     => $configuration->{database}->{host},
     password => $configuration->{database}->{password},
-    username => $configuration->{database}->{username}
+    username => $configuration->{database}->{username},
+    options  => [ split(/, */, $configuration->{database}->{options}) ]
 );
 
 my $db = AccountManager::DB->new();
diff --git a/conf/manager.conf.in b/conf/manager.conf.in
index ebe24fd..8b8941a 100644
--- a/conf/manager.conf.in
+++ b/conf/manager.conf.in
@@ -23,6 +23,7 @@ host = localhost
 name = idp_account_manager
 username = idpadmin
 password = secret
+options  = mysql_enable_utf8
 
 [idp]
 scope = my.fqdn
diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm
index 96e3c15..0c769a5 100644
--- a/lib/AccountManager/App.pm
+++ b/lib/AccountManager/App.pm
@@ -96,6 +96,7 @@ sub new {
             host     => $self->{configuration}->{database}->{host},
             username => $self->{configuration}->{database}->{username},
             password => $self->{configuration}->{database}->{password},
+            options  => [ split(/, */, $self->{configuration}->{database}->{options}) ]
         );
     } else {
         $self->{logger}->fatal(
diff --git a/lib/AccountManager/DB.pm b/lib/AccountManager/DB.pm
index 8703bf7..0c9f98d 100644
--- a/lib/AccountManager/DB.pm
+++ b/lib/AccountManager/DB.pm
@@ -8,7 +8,6 @@ use base 'Rose::DB';
 __PACKAGE__->use_private_registry;
 
 __PACKAGE__->SUPER::register_db (
-    connect_options => { AutoCommit => 1, ChopBlanks => 1 },
     driver          => 'mysql',
     host            => 'localhost',
     database        => 'fake',
@@ -19,8 +18,16 @@ __PACKAGE__->SUPER::register_db (
 sub register_db {
     my ($pkg, %args) = @_;
 
+    my $options = {
+        AutoCommit => 1,
+        ChopBlanks => 1,
+    };
+    if ($args{options}) {
+        $options->{$_} = 1 foreach @{$args{options}};
+    }
+
     __PACKAGE__->SUPER::register_db (
-        connect_options => { AutoCommit => 1, ChopBlanks => 1 },
+        connect_options => $options,
         driver          => $args{driver},
         host            => $args{host},
         database        => $args{database},
-- 
GitLab