3 #----------------------------------------------------------------
4 # Generic header for tesing OpenSRF methods
5 #----------------------------------------------------------------
12 use OpenSRF::AppSession;
13 use OpenSRF::EX qw(:try);
14 use Time::HiRes qw/time/;
15 use Digest::MD5 qw(md5_hex);
16 use OpenILS::Utils::Fieldmapper;
17 use OpenILS::Application::AppUtils;
18 use OpenSRF::Utils::SettingsClient;
19 use OpenSRF::Utils::Logger qw/:logger/;
23 our $apputils = "OpenILS::Application::AppUtils";
29 # Some constants for our services
30 our $AUTH = 'open-ils.auth';
31 our $STORAGE = 'open-ils.storage';
32 our $SEARCH = 'open-ils.search';
33 our $CIRC = 'open-ils.circ';
34 our $CAT = 'open-ils.cat';
35 our $MATH = 'opensrf.math';
36 our $SETTINGS = 'opensrf.settings';
37 our $ACTOR = 'open-ils.actor';
39 sub AUTH { return $AUTH; }
40 sub STORAGE { return $STORAGE; }
41 sub SEARCH { return $SEARCH; }
42 sub CIRC { return $CIRC; }
43 sub CAT { return $CAT; }
44 sub MATH { return $MATH; }
45 sub SETTINGS { return $SETTINGS; }
46 sub ACTOR { return $ACTOR; }
49 #----------------------------------------------------------------
51 #----------------------------------------------------------------
53 my ($pkg, $file, $line, $sub) = _caller();
55 die "Script halted with error ".
56 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
59 #----------------------------------------------------------------
61 #----------------------------------------------------------------
62 sub printl { print "@_\n"; }
64 #----------------------------------------------------------------
65 # Print with Data::Dumper
66 #----------------------------------------------------------------
67 sub debug { printl(Dumper(@_)); }
70 #----------------------------------------------------------------
71 # This is not the function you're looking for
72 #----------------------------------------------------------------
74 my ($pkg, $file, $line, $sub) = caller(2);
76 ($pkg, $file, $line) = caller(1);
79 return ($pkg, $file, $line, $sub);
83 #----------------------------------------------------------------
84 # Connect to the servers
85 #----------------------------------------------------------------
88 err("Bootstrap config required") unless $config;
89 OpenSRF::System->bootstrap_client( config_file => $config );
90 Fieldmapper->import(IDL =>
91 OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
96 my ($key) = grep { $_ =~ /OpenILS.*CStoreEditor/o } keys %INC;
99 my $h = $SIG{__WARN__};
100 $SIG{__WARN__} = sub {};
101 require OpenILS::Utils::CStoreEditor;
106 #----------------------------------------------------------------
107 # Get a handle for the memcache object
108 #----------------------------------------------------------------
110 eval 'use OpenSRF::Utils::Cache;';
111 $memcache = OpenSRF::Utils::Cache->new('global') unless $memcache;
115 #----------------------------------------------------------------
116 # Is the given object an OILS event?
117 #----------------------------------------------------------------
120 if( $e and ref($e) eq 'HASH' ) {
121 return 1 if defined($e->{ilsevent});
126 sub oils_event_equals {
127 my( $e, $name ) = @_;
128 return 1 if (oils_is_event($e) and ($e->{textcode} eq $name));
132 #----------------------------------------------------------------
133 # If the given object is an event, this prints the event info
134 # and exits the script
135 #----------------------------------------------------------------
138 my ($pkg, $file, $line, $sub) = _caller();
139 if(oils_is_event($evt)) {
140 if($evt->{ilsevent}) {
141 printl("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
148 #----------------------------------------------------------------
149 # Login to the auth server and set the global $authtoken var
150 #----------------------------------------------------------------
152 my( $username, $password, $type ) = @_;
156 my $seed = $apputils->simplereq( $AUTH,
157 'open-ils.auth.authenticate.init', $username );
158 err("No auth seed") unless $seed;
160 my $response = $apputils->simplereq( $AUTH,
161 'open-ils.auth.authenticate.complete',
162 { username => $username,
163 password => md5_hex($seed . md5_hex($password)),
166 err("No auth response returned on login") unless $response;
168 oils_event_die($response);
170 $authtime = $response->{payload}->{authtime};
171 $authtoken = $response->{payload}->{authtoken};
176 #----------------------------------------------------------------
177 # Destroys the login session on the server
178 #----------------------------------------------------------------
180 $apputils->simplereq(
182 'open-ils.auth.session.delete', $authtoken );
185 #----------------------------------------------------------------
186 # Fetches the user object and sets the global $user var
187 #----------------------------------------------------------------
188 sub oils_fetch_session {
190 my $resp = $apputils->simplereq( $AUTH,
191 'open-ils.auth.session.retrieve', $ses, 'staff' );
192 oils_event_die($resp);
193 return $user = $resp;
196 #----------------------------------------------------------------
197 # var $response = simplereq( $service, $method, @params );
198 #----------------------------------------------------------------
199 sub simplereq { return $apputils->simplereq(@_); }
200 sub osrf_request { return $apputils->simplereq(@_); }