[open-ils-commits] r15199 - in trunk/Open-ILS/src: perlmods/OpenILS/Application/Trigger/Reactor sql/Pg sql/Pg/upgrade (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Dec 18 15:59:43 EST 2009
Author: erickson
Date: 2009-12-18 15:59:38 -0500 (Fri, 18 Dec 2009)
New Revision: 15199
Added:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm
trunk/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
Log:
Patch from Joe Atzberger to add a generic SendFile reactor. Can be used for sending files to 3rd parties for process (e.g. mailed notices)
Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm 2009-12-18 20:59:38 UTC (rev 15199)
@@ -0,0 +1,101 @@
+package OpenILS::Application::Trigger::Reactor::SendFile;
+use OpenILS::Application::Trigger::Reactor;
+use base 'OpenILS::Application::Trigger::Reactor';
+
+# use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Logger qw/:logger/;
+
+use Data::Dumper;
+use Net::uFTP;
+use File::Temp;
+
+$Data::Dumper::Indent = 0;
+
+use strict;
+use warnings;
+
+sub ABOUT {
+ return <<ABOUT;
+
+The SendFile Reactor Module attempts to transfer a file to a remote server.
+Net::uFTP is used, encapsulating the available options of SCP, FTP and SFTP.
+
+No default template is assumed, and all information is expected to be gathered
+by the Event Definition through event parameters:
+ ~ remote_host (required)
+ ~ remote_user
+ ~ remote_password
+ ~ remote_account
+ ~ type (FTP, SFTP or SCP -- default FTP)
+ ~ port
+ ~ debug
+
+The latter three are optionally passed to the Net::uFTP constructor.
+
+Note: none of the parameters are actually required, except remote_host.
+That is because remote_user, remote_password and remote_account can all be
+extrapolated from other sources, as the Net::FTP docs describe:
+
+ If no arguments are given then Net::FTP uses the Net::Netrc package
+ to lookup the login information for the connected host.
+
+ If no information is found then a login of anonymous is used.
+
+ If no password is given and the login is anonymous then anonymous@
+ will be used for password.
+
+Note that specifying a password will require you to specify a user.
+Similarly, specifying an account requires both user and password.
+That is, there are no assumed defaults when the latter arguments are used.
+
+ABOUT
+}
+
+sub handler {
+ my $self = shift;
+ my $env = shift;
+ my $params = $env->{params};
+
+ my $host = $params->{remote_host};
+ unless ($host) {
+ $logger->error("No remote_host specified in env");
+ return;
+ }
+
+ my %options = ();
+ foreach (qw/debug type port/) {
+ $options{$_} = $params->{$_} if $params->{$_};
+ }
+ my $ftp = Net::uFTP->new($host, %options);
+
+ # my $conf = OpenSRF::Utils::SettingsClient->new;
+ # $$env{something_hardcoded} = $conf->config_value('category', 'whatever');
+
+ my $text = $self->run_TT($env) or return;
+ my $tmp = File::Temp->new(); # magical self-destructing tempfile
+ print $tmp $text;
+ $logger->info("SendFile Reactor: using tempfile $tmp");
+
+ my @login_args = ();
+ foreach (qw/remote_user remote_password remote_account/) {
+ push @login_args, $params->{$_} if $params->{$_};
+ }
+ unless ($ftp->login(@login_args)) {
+ $logger->error("SendFile Reactor: failed login to $host w/ args(" . join(',', @login_args) . ")");
+ return;
+ }
+
+ my @put_args = ($tmp);
+ push @put_args, $params->{remote_file} if $params->{remote_file}; # user can specify remote_file name, optionally
+ my $filename = $ftp->put(@put_args);
+ if ($filename) {
+ $logger->info("SendFile Reactor: successfully sent ${host} $filename");
+ return 1;
+ }
+
+ $logger->error("SendFile Reactor: put to $host failed with error: $!");
+ return;
+}
+
+1;
+
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-12-18 20:17:08 UTC (rev 15198)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-12-18 20:59:38 UTC (rev 15199)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0119'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0120'); -- atz
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-12-18 20:17:08 UTC (rev 15198)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-12-18 20:59:38 UTC (rev 15199)
@@ -2578,7 +2578,17 @@
INSERT INTO action_trigger.reactor (module,description) VALUES ('ApplyPatronPenalty','Applies the conifigured penalty to a patron. Required named environment variables are "user", which refers to the user object, and "context_org", which refers to the org_unit object that acts as the focus for the penalty.');
+INSERT INTO action_trigger.reactor (module,description) VALUES
+( 'SendFile',
+ oils_i18n_gettext(
+ 'SendFile',
+ 'Build and transfer a file to a remote server. Required parameter "remote_host" specifying target server. Optional parameters: remote_user, remote_password, remote_account, port, type (FTP, SFTP or SCP), and debug.',
+ 'atreact',
+ 'description'
+ )
+);
+
INSERT INTO config.org_unit_setting_type (name, label, description, datatype, fm_class)
VALUES (
'circ.claim_return.copy_status',
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql 2009-12-18 20:59:38 UTC (rev 15199)
@@ -0,0 +1,16 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0120'); -- atz
+
+INSERT INTO action_trigger.reactor (module,description) VALUES
+( 'SendFile',
+ oils_i18n_gettext(
+ 'SendFile',
+ 'Build and transfer a file to a remote server. Required parameter "remote_host" specifying target server. Optional parameters: remote_user, remote_password, remote_account, port, type (FTP, SFTP or SCP), and debug.',
+ 'atreact',
+ 'description'
+ )
+);
+
+COMMIT;
+
More information about the open-ils-commits
mailing list