[dancer-users] Flexible credentials with Dancer::Plugin::Database
Lutz Gehlen
lrg_ml at gmx.net
Tue May 6 06:11:04 BST 2014
Hello Maxwell,
thank you for your suggestions.
On Monday 05.05.2014 20:33:08 Maxwell Carey wrote:
[...]
> On 05/03/2014 01:50 PM, Lutz Gehlen wrote:
> In general, you should use .pgpass for storing Postgres connection
> credentials. See the Postgres docs
> <http://www.postgresql.org/docs/9.3/static/libpq-pgpass.html> for
> details. This allows you to save credentials in one place without having
> to hard-code them into every application or config file that needs to
> access the database.
I have used a pgpass file before, you are right, this might be the way to go
here, too.
> Additionally, you should be able to use* a connection service file
> <http://www.postgresql.org/docs/9.3/static/libpq-pgservice.html> to
> configure different connection parameters, e.g. point to the development
> vs. production database. This StackOverflow answer
> <http://stackoverflow.com/a/19980156/176646> provides a good example
> using DBI in a regular Perl script.
>
> * I've used .pgpass but never .pg_service.conf
>
> To configure Dancer::Plugin::Database to use the connections from
> .pg_service.conf, your configuration should look something like:
>
> plugins:
> Database:
> dsn: 'dbi:Pg:service=test'
> dbi_params:
> RaiseError: 1
> AutoCommit: 1
> on_connect_do: ...
>
> (assuming you have a service named "test" in .pg_service.conf, as in the
> StackOverflow answer I cited earlier. You would presumably put the above
> in environments/development.yml)
>
> I haven't tried this with Postgres before so YMMV, but I do something
> similar with MySQL to allow non-Dancer apps and Dancer apps to share the
> same credentials file:
>
> plugins:
> Database:
> dsn: 'dbi:mysql:;mysql_read_default_file=/path/to/database.cfg'
> dbi_params:
> RaiseError: 1
> AutoCommit: 1
>
> Hope this is useful to you.
I didn't know about pg_service, I will certainly look into that.
Thanks a lot,
Lutz
More information about the dancer-users
mailing list