]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/perl/lib/OpenSRF/Application.pm
Log redaction for sensitive input values, Perl side
[OpenSRF.git] / src / perl / lib / OpenSRF / Application.pm
1 package OpenSRF::Application;
2 # vim:noet:ts=4
3 use vars qw/$_app $log @_METHODS $thunk $server_class/;
4
5 use base qw/OpenSRF/;
6 use OpenSRF::AppSession;
7 use OpenSRF::DomainObject::oilsMethod;
8 use OpenSRF::DomainObject::oilsResponse qw/:status/;
9 use OpenSRF::Utils::Logger qw/:level $logger/;
10 use Data::Dumper;
11 use Time::HiRes qw/time/;
12 use OpenSRF::EX qw/:try/;
13 use Carp;
14 use OpenSRF::Utils::JSON;
15
16 sub DESTROY{};
17
18 use strict;
19 use warnings;
20
21 $log = 'OpenSRF::Utils::Logger';
22
23 our $in_request = 0;
24 our @pending_requests;
25 our $shared_conf;
26
27 sub package {
28         my $self = shift;
29         return 1 unless ref($self);
30         return $self->{package};
31 }
32
33 sub signature {
34         my $self = shift;
35         return 0 unless ref($self);
36         return $self->{signature};
37 }
38
39 sub strict {
40     my $self = shift; 
41     return 0 unless ref($self);
42     return $self->{strict};
43 }
44
45 sub argc {
46         my $self = shift;
47         return 0 unless ref($self);
48         return $self->{argc};
49 }
50
51 sub max_chunk_size {
52         my $self = shift;
53         return 0 unless ref($self);
54         return $self->{max_chunk_size} if (defined($self->{max_chunk_size}));
55         return 10240;
56 }
57
58 sub max_chunk_count {
59         my $self = shift;
60         return 0 unless ref($self);
61         return $self->{max_chunk_count} || 0;
62 }
63
64 sub api_name {
65         my $self = shift;
66         return 1 unless ref($self);
67         return $self->{api_name};
68 }
69
70 sub api_level {
71         my $self = shift;
72         return 1 unless ref($self);
73         return $self->{api_level};
74 }
75
76 sub session {
77         my $self = shift;
78         my $session = shift;
79
80         if($session) {
81                 $self->{session} = $session;
82         }
83         return $self->{session};
84 }
85
86 sub server_class {
87         my $class = shift;
88         if($class) {
89                 $server_class = $class;
90         }
91         return $server_class;
92 }
93
94 sub thunk {
95         my $self = shift;
96         my $flag = shift;
97         $thunk = $flag if (defined $flag);
98         return $thunk;
99 }
100
101 sub application_implementation {
102         my $self = shift;
103         my $app = shift;
104
105         if (defined $app) {
106                 $_app = $app;
107                 $_app->use;
108                 if( $@ ) {
109                         $log->error( "Error loading application_implementation: $app -> $@", ERROR);
110                 }
111
112         }
113
114         return $_app;
115 }
116
117 sub handler {
118         my ($self, $session, $app_msg) = @_;
119
120         if( ! $app_msg ) {
121                 return 1;  # error?
122         }
123
124         my $app = $self->application_implementation;
125
126         if ($session->last_message_type eq 'REQUEST') {
127
128         my @p = $app_msg->params;
129                 my $method_name = $app_msg->method;
130                 my $method_proto = $session->last_message_api_level;
131
132                 # By default, we log all method params at the info level
133                 # Here we are consult our shared portion of the config file
134                 # to look for any exceptions to this behavior
135                 my $logdata = "CALL: ".$session->service." $method_name ";
136                 my $redact_params = 0;
137                 if (@p) {
138                         foreach my $match_string (@{$shared_conf->shared->log_protect}) {
139                                 if ($method_name =~ /^$match_string/) {
140                                         $redact_params = 1;
141                                         last;
142                                 }
143                         }
144                         if ($redact_params) {
145                                 $logdata .= "**PARAMS REDACTED**";
146                         } else {
147                                 $logdata .= join(', ',@p);
148                         }
149                 }
150                 $log->info($logdata);
151
152                 my $coderef = $app->method_lookup( $method_name, $method_proto, 1, 1 );
153
154                 unless ($coderef) {
155                         $session->status( OpenSRF::DomainObject::oilsMethodException->new( 
156                                                 statusCode => STATUS_NOTFOUND(),
157                                                 status => "Method [$method_name] not found for $app"));
158                         return 1;
159                 }
160
161                 unless ($session->continue_request) {
162                         $session->status(
163                                 OpenSRF::DomainObject::oilsConnectStatus->new(
164                                                 statusCode => STATUS_REDIRECTED(),
165                                                 status => 'Disconnect on max requests' ) );
166                         $session->kill_me;
167                         return 1;
168                 }
169
170                 if (ref $coderef) {
171                         my @args = $app_msg->params;
172                         my $appreq = OpenSRF::AppRequest->new( $session );
173                         $appreq->max_chunk_size( $coderef->max_chunk_size );
174                         $appreq->max_chunk_count( $coderef->max_chunk_count );
175
176                         $log->debug( "in_request = $in_request : [" . $appreq->threadTrace."]", INTERNAL );
177                         if( $in_request ) {
178                                 $log->debug( "Pushing onto pending requests: " . $appreq->threadTrace, DEBUG );
179                                 push @pending_requests, [ $appreq, \@args, $coderef ]; 
180                                 return 1;
181                         }
182
183
184                         $in_request++;
185
186                         $log->debug( "Executing coderef for {$method_name}", INTERNAL );
187
188                         my $resp;
189                         try {
190                                 # un-if(0) this block to enable param checking based on signature and argc
191                                 if ($coderef->strict) {
192                                         if (@args < $coderef->argc) {
193                                                 die     "Not enough params passed to ".
194                                                         $coderef->api_name." : requires ". $coderef->argc
195                                         }
196                                         if (@args) {
197                                                 my $sig = $coderef->signature;
198                                                 if ($sig && exists $sig->{params}) {
199                                                         for my $p (0 .. scalar(@{ $sig->{params} }) - 1 ) {
200                                                                 my $s = $sig->{params}->[$p];
201                                                                 my $a = $args[$p];
202                                                                 if ($s->{class} && OpenSRF::Utils::JSON->lookup_hint(ref $a) ne $s->{class}) {
203                                                                         die "Incorrect param class at position $p : should be a '$$s{class}'";
204                                                                 } elsif ($s->{type}) {
205                                                                         if (lc($s->{type}) eq 'object' && $a !~ /HASH/o) {
206                                                                                 die "Incorrect param type at position $p : should be an 'object'";
207                                                                         } elsif (lc($s->{type}) eq 'array' && $a !~ /ARRAY/o) {
208                                                                                 die "Incorrect param type at position $p : should be an 'array'";
209                                                                         } elsif (lc($s->{type}) eq 'number' && (ref($a) || $a !~ /^-?\d+(?:\.\d+)?$/o)) {
210                                                                                 die "Incorrect param type at position $p : should be a 'number'";
211                                                                         } elsif (lc($s->{type}) eq 'string' && ref($a)) {
212                                                                                 die "Incorrect param type at position $p : should be a 'string'";
213                                                                         }
214                                                                 }
215                                                         }
216                                                 }
217                                         }
218                                 }
219
220                                 my $start = time();
221                                 $resp = $coderef->run( $appreq, @args); 
222                                 my $time = sprintf '%.3f', time() - $start;
223
224                                 $log->debug( "Method duration for [$method_name]:  ". $time );
225                                 $appreq->respond_complete( $resp );
226
227                         } catch Error with {
228                                 my $e = shift;
229                                 warn "Caught error from 'run' method: $e\n";
230
231                                 if(UNIVERSAL::isa($e,"Error")) {
232                                         $e = $e->stringify();
233                                 } 
234                                 my $sess_id = $session->session_id;
235                                 $session->status(
236                                         OpenSRF::DomainObject::oilsMethodException->new(
237                                                         statusCode      => STATUS_INTERNALSERVERERROR(),
238                                                         status          => " *** Call to [$method_name] failed for session ".
239                                                                            "[$sess_id], thread trace ".
240                                                                            "[".$appreq->threadTrace."]:\n$e\n"
241                                         )
242                                 );
243                         };
244
245
246
247                         # ----------------------------------------------
248
249
250                         # XXX may need this later
251                         # $_->[1] = 1 for (@OpenSRF::AppSession::_CLIENT_CACHE);
252
253                         $in_request--;
254
255                         $log->debug( "Pending Requests: " . scalar(@pending_requests), INTERNAL );
256
257                         # cycle through queued requests
258                         while( my $aref = shift @pending_requests ) {
259                                 $in_request++;
260                                 my $resp;
261                                 try {
262                                         # un-if(0) this block to enable param checking based on signature and argc
263                                         if (0) {
264                                                 if (@args < $aref->[2]->argc) {
265                                                         die     "Not enough params passed to ".
266                                                                 $aref->[2]->api_name." : requires ". $aref->[2]->argc
267                                                 }
268                                                 if (@args) {
269                                                         my $sig = $aref->[2]->signature;
270                                                         if ($sig && exists $sig->{params}) {
271                                                                 for my $p (0 .. scalar(@{ $sig->{params} }) - 1 ) {
272                                                                         my $s = $sig->{params}->[$p];
273                                                                         my $a = $args[$p];
274                                                                         if ($s->{class} && OpenSRF::Utils::JSON->lookup_hint(ref $a) ne $s->{class}) {
275                                                                                 die "Incorrect param class at position $p : should be a '$$s{class}'";
276                                                                         } elsif ($s->{type}) {
277                                                                                 if (lc($s->{type}) eq 'object' && $a !~ /HASH/o) {
278                                                                                         die "Incorrect param type at position $p : should be an 'object'";
279                                                                                 } elsif (lc($s->{type}) eq 'array' && $a !~ /ARRAY/o) {
280                                                                                         die "Incorrect param type at position $p : should be an 'array'";
281                                                                                 } elsif (lc($s->{type}) eq 'number' && (ref($a) || $a !~ /^-?\d+(?:\.\d+)?$/o)) {
282                                                                                         die "Incorrect param type at position $p : should be a 'number'";
283                                                                                 } elsif (lc($s->{type}) eq 'string' && ref($a)) {
284                                                                                         die "Incorrect param type at position $p : should be a 'string'";
285                                                                                 }
286                                                                         }
287                                                                 }
288                                                         }
289                                                 }
290                                         }
291
292                                         my $start = time;
293                                         my $response = $aref->[2]->run( $aref->[0], @{$aref->[1]} );
294                                         my $time = sprintf '%.3f', time - $start;
295                                         $log->debug( "Method duration for [".$aref->[2]->api_name." -> ".join(', ',@{$aref->[1]}).']:  '.$time, DEBUG );
296
297                                         $appreq = $aref->[0];   
298                                         $appreq->respond_complete( $response );
299                                         $log->debug( "Executed: " . $appreq->threadTrace, INTERNAL );
300
301                                 } catch Error with {
302                                         my $e = shift;
303                                         if(UNIVERSAL::isa($e,"Error")) {
304                                                 $e = $e->stringify();
305                                         }
306                                         $session->status(
307                                                 OpenSRF::DomainObject::oilsMethodException->new(
308                                                                 statusCode => STATUS_INTERNALSERVERERROR(),
309                                                                 status => "Call to [".$aref->[2]->api_name."] faild:  $e"
310                                                 )
311                                         );
312                                 };
313                                 $in_request--;
314                         }
315
316                         return 1;
317                 } 
318
319                 $log->info("Received non-REQUEST message in Application handler");
320
321                 my $res = OpenSRF::DomainObject::oilsMethodException->new( 
322                                 status => "Received non-REQUEST message in Application handler");
323                 $session->send('ERROR', $res);
324                 $session->kill_me;
325                 return 1;
326
327         } else {
328                 $session->push_queue([ $app_msg, $session->last_threadTrace ]);
329         }
330
331         $session->last_message_type('');
332         $session->last_message_api_level('');
333
334         return 1;
335 }
336
337 sub is_registered {
338         my $self = shift;
339         my $api_name = shift;
340         my $api_level = shift || 1;
341         return exists($_METHODS[$api_level]{$api_name});
342 }
343
344
345 sub normalize_whitespace {
346         my $txt = shift;
347
348         $txt =~ s/^\s+//gso;
349         $txt =~ s/\s+$//gso;
350         $txt =~ s/\s+/ /gso;
351         $txt =~ s/\n//gso;
352         $txt =~ s/\. /\.  /gso;
353
354         return $txt;
355 }
356
357 sub parse_string_signature {
358         my $string = shift;
359         return [] unless $string;
360         my @chunks = split(/\@/smo, $string);
361
362         my @params;
363         my $ret;
364         my $desc = '';
365         for (@chunks) {
366                 if (/^return (.+)$/so) {
367                         $ret = [normalize_whitespace($1)];
368                 } elsif (/^param (\w+) \b(.+)$/so) {
369                         push @params, [ $1, normalize_whitespace($2) ];
370                 } else {
371                         $desc .= '@' if $desc;
372                         $desc .= $_;
373                 }
374         }
375
376         return [normalize_whitespace($desc),\@params, $ret];
377 }
378
379 sub parse_array_signature {
380         my $array = shift;
381         my ($d,$p,$r) = @$array;
382         return {} unless ($d or $p or $r);
383
384         return {
385                 desc    => $d,
386                 params  => [
387                         map { 
388                                 { name  => $$_[0],
389                                   desc  => $$_[1],
390                                   type  => $$_[2],
391                                   class => $$_[3],
392                                 }
393                         } @$p
394                 ],
395                 'return'=>
396                         { desc  => $$r[0],
397                           type  => $$r[1],
398                           class => $$r[2],
399                         }
400         };
401 }
402
403 sub register_method {
404         my $self = shift;
405         my $app = ref($self) || $self;
406         my %args = @_;
407
408
409         throw OpenSRF::DomainObject::oilsMethodException unless ($args{method});
410
411         $args{api_level} = 1 unless(defined($args{api_level}));
412         $args{stream} ||= 0;
413         $args{remote} ||= 0;
414         $args{argc} ||= 0;
415         $args{package} ||= $app;                
416         $args{server_class} = server_class();
417         $args{api_name} ||= $args{server_class} . '.' . $args{method};
418
419         # un-if(0) this block to enable signature parsing
420         if (!$args{signature}) {
421                 if ($args{notes} && !ref($args{notes})) {
422                         $args{signature} =
423                                 parse_array_signature( parse_string_signature( $args{notes} ) );
424                 }
425         } elsif( !ref($args{signature}) ) {
426                 $args{signature} =
427                         parse_array_signature( parse_string_signature( $args{signature} ) );
428         } elsif( ref($args{signature}) eq 'ARRAY') {
429                 $args{signature} =
430                         parse_array_signature( $args{signature} );
431         }
432         
433         unless ($args{object_hint}) {
434                 ($args{object_hint} = $args{package}) =~ s/::/_/go;
435         }
436
437         OpenSRF::Utils::JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" );
438
439         $_METHODS[$args{api_level}]{$args{api_name}} = bless \%args => $app;
440
441         __PACKAGE__->register_method(
442                 stream => 0,
443                 argc => $args{argc},
444                 api_name => $args{api_name}.'.atomic',
445                 method => 'make_stream_atomic',
446                 notes => "This is a system generated method.  Please see the definition for $args{api_name}",
447         ) if ($args{stream});
448 }
449
450 sub retrieve_remote_apis {
451         my $method = shift;
452         my $session = OpenSRF::AppSession->create('router');
453         try {
454                 $session->connect or OpenSRF::EX::WARN->throw("Connection to router timed out");
455         } catch Error with {
456                 my $e = shift;
457                 $log->debug( "Remote subrequest returned an error:\n". $e );
458                 return undef;
459         } finally {
460                 return undef unless ($session->state == $session->CONNECTED);
461         };
462
463         my $req = $session->request( 'opensrf.router.info.class.list' );
464         my $list = $req->recv;
465
466         if( UNIVERSAL::isa($list,"Error") ) {
467                 throw $list;
468         }
469
470         my $content = $list->content;
471
472         $req->finish;
473         $session->finish;
474         $session->disconnect;
475
476         my %u_list = map { ($_ => 1) } @$content;
477
478         for my $class ( keys %u_list ) {
479                 next if($class eq $server_class);
480                 populate_remote_method_cache($class, $method);
481         }
482 }
483
484 sub populate_remote_method_cache {
485         my $class = shift;
486         my $meth = shift;
487
488         my $session = OpenSRF::AppSession->create($class);
489         try {
490                 $session->connect or OpenSRF::EX::WARN->throw("Connection to $class timed out");
491
492                 my $call = 'opensrf.system.method.all' unless (defined $meth);
493                 $call = 'opensrf.system.method' if (defined $meth);
494
495                 my $req = $session->request( $call, $meth );
496
497                 while (my $method = $req->recv) {
498                         next if (UNIVERSAL::isa($method, 'Error'));
499
500                         $method = $method->content;
501                         next if ( exists($_METHODS[$$method{api_level}]) &&
502                                 exists($_METHODS[$$method{api_level}]{$$method{api_name}}) );
503                         $method->{remote} = 1;
504                         bless($method, __PACKAGE__ );
505                         $_METHODS[$$method{api_level}]{$$method{api_name}} = $method;
506                 }
507
508                 $req->finish;
509                 $session->finish;
510                 $session->disconnect;
511
512         } catch Error with {
513                 my $e = shift;
514                 $log->debug( "Remote subrequest returned an error:\n". $e );
515                 return undef;
516         };
517 }
518
519 sub method_lookup {             
520         my $self = shift;
521         my $method = shift;
522         my $proto = shift;
523         my $no_recurse = shift || 0;
524         my $no_remote = shift || 0;
525
526         # this instead of " || 1;" above to allow api_level 0
527         $proto = $self->api_level unless (defined $proto);
528
529         my $class = ref($self) || $self;
530
531         $log->debug("Lookup of [$method] by [$class] in api_level [$proto]", DEBUG);
532         $log->debug("Available methods\n\t".join("\n\t", keys %{ $_METHODS[$proto] }), INTERNAL);
533
534         my $meth;
535         if (__PACKAGE__->thunk) {
536                 for my $p ( reverse(1 .. $proto) ) {
537                         if (exists $_METHODS[$p]{$method}) {
538                                 $meth = $_METHODS[$p]{$method};
539                         }
540                 }
541         } else {
542                 if (exists $_METHODS[$proto]{$method}) {
543                         $meth = $_METHODS[$proto]{$method};
544                 }
545         }
546
547         if (defined $meth) {
548                 if($no_remote and $meth->{remote}) {
549                         $log->debug("OH CRAP We're not supposed to return remote methods", WARN);
550                         return undef;
551                 }
552
553         } elsif (!$no_recurse) {
554                 $log->debug("We didn't find [$method], asking everyone else.", DEBUG);
555                 retrieve_remote_apis($method);
556                 $meth = $self->method_lookup($method,$proto,1);
557         }
558
559         return $meth;
560 }
561
562 sub run {
563         my $self = shift;
564         my $req = shift;
565
566         my $resp;
567         my @params = @_;
568
569         if ( !UNIVERSAL::isa($req, 'OpenSRF::AppRequest') ) {
570                 $log->debug("Creating a SubRequest object", DEBUG);
571                 unshift @params, $req;
572                 $req = OpenSRF::AppSubrequest->new;
573                 $req->session( $self->session ) if ($self->session);
574
575         } else {
576                 $log->debug("This is a top level request", DEBUG);
577         }
578
579         if (!$self->{remote}) {
580                 my $code = \&{$self->{package} . '::' . $self->{method}};
581                 my $err = undef;
582
583                 try {
584                         $resp = $code->($self, $req, @params);
585
586                 } catch Error with {
587                         $err = shift;
588
589                         if( ref($self) eq 'HASH') {
590                                 $log->error("Sub $$self{package}::$$self{method} DIED!!!\n\t$err\n", ERROR);
591                         }
592                 };
593
594                 if($err) {
595                         if(UNIVERSAL::isa($err,"Error")) { 
596                                 throw $err;
597                         } else {
598                                 die $err->stringify; 
599                         }
600                 }
601
602
603                 $log->debug("Coderef for [$$self{package}::$$self{method}] has been run", DEBUG);
604
605                 if ( ref($req) and UNIVERSAL::isa($req, 'OpenSRF::AppSubrequest') ) {
606                         $req->respond($resp) if (defined $resp);
607                         $log->debug("SubRequest object is responding with : " . join(" ",$req->responses), DEBUG);
608                         return $req->responses;
609                 } else {
610                         $log->debug("A top level Request object is responding $resp", DEBUG) if (defined $resp);
611                         return $resp;
612                 }
613         } else {
614                 my $session = OpenSRF::AppSession->create($self->{server_class});
615                 try {
616                         #$session->connect or OpenSRF::EX::WARN->throw("Connection to [$$self{server_class}] timed out");
617                         my $remote_req = $session->request( $self->{api_name}, @params );
618                         while (my $remote_resp = $remote_req->recv) {
619                                 OpenSRF::Utils::Logger->debug("Remote Subrequest Received " . $remote_resp, INTERNAL );
620                                 if( UNIVERSAL::isa($remote_resp,"Error") ) {
621                                         throw $remote_resp;
622                                 }
623                                 $req->respond( $remote_resp->content );
624                         }
625                         $remote_req->finish();
626
627                 } catch Error with {
628                         my $e = shift;
629                         $log->debug( "Remote subrequest returned an error:\n". $e );
630                         return undef;
631                 };
632
633                 if ($session) {
634                         $session->disconnect();
635                         $session->finish();
636                 }
637
638                 $log->debug( "Remote Subrequest Responses " . join(" ", $req->responses), INTERNAL );
639
640                 return $req->responses;
641         }
642         # huh? how'd we get here...
643         return undef;
644 }
645
646 sub introspect {
647         my $self = shift;
648         my $client = shift;
649         my $method = shift;
650         my $limit = shift;
651         my $offset = shift;
652
653         if ($self->api_name =~ /all$/o) {
654                 $offset = $limit;
655                 $limit = $method;
656                 $method = undef; 
657         }
658
659         my ($seen,$returned) = (0,0);
660         for my $api_level ( reverse(1 .. $#_METHODS) ) {
661                 for my $api_name ( sort keys %{$_METHODS[$api_level]} ) {
662                         if (!$offset || $offset <= $seen) {
663                                 if (!$_METHODS[$api_level]{$api_name}{remote}) {
664                                         if (defined($method)) {
665                                                 if ($api_name =~ $method) {
666                                                         if (!$limit || $returned < $limit) {
667                                                                 $client->respond( $_METHODS[$api_level]{$api_name} );
668                                                                 $returned++;
669                                                         }
670                                                 }
671                                         } else {
672                                                 if (!$limit || $returned < $limit) {
673                                                         $client->respond( $_METHODS[$api_level]{$api_name} );
674                                                         $returned++;
675                                                 }
676                                         }
677                                 }
678                         }
679                         $seen++;
680                 }
681         }
682
683         return undef;
684 }
685 __PACKAGE__->register_method(
686         stream => 1,
687         method => 'introspect',
688         api_name => 'opensrf.system.method.all',
689         argc => 0,
690         signature => {
691                 desc => q/This method is used to introspect an entire OpenSRF Application/,
692                 return => {
693                         desc => q/A stream of objects describing the methods available via this OpenSRF Application/,
694                         type => 'object'
695                 }
696         },
697 );
698 __PACKAGE__->register_method(
699         stream => 1,
700         method => 'introspect',
701         argc => 1,
702         api_name => 'opensrf.system.method',
703         argc => 1,
704         signature => {
705                 desc => q/Use this method to get the definition of a single OpenSRF Method/,
706                 params => [
707                         { desc => q/The method to introspect/,
708                           type => 'string' },
709                 ],
710                 return => { desc => q/An object describing the method requested, or an error if it can't be found/,
711                             type => 'object' }
712         },
713 );
714
715 sub echo_method {
716         my $self = shift;
717         my $client = shift;
718         my @args = @_;
719
720         $client->respond( $_ ) for (@args);
721         return undef;
722 }
723 __PACKAGE__->register_method(
724         stream => 1,
725         method => 'echo_method',
726         argc => 1,
727         api_name => 'opensrf.system.echo',
728         signature => {
729                 desc => q/A test method that will echo back it's arguments in a streaming response/,
730                 params => [
731                         { desc => q/One or more arguments to echo back/ }
732                 ],
733                 return => { desc => q/A stream of the arguments passed/ }
734         },
735 );
736
737 sub time_method {
738         my( $self, $conn ) = @_;
739         return CORE::time;
740 }
741 __PACKAGE__->register_method(
742         method => 'time_method',
743         argc => 0,
744         api_name => 'opensrf.system.time',
745         signature => {
746                 desc => q/Returns the current system time as epoch seconds/,
747                 return => { desc => q/epoch seconds/ }
748         }
749 );
750
751 sub make_stream_atomic {
752         my $self = shift;
753         my $req = shift;
754         my @args = @_;
755
756         (my $m_name = $self->api_name) =~ s/\.atomic$//o;
757         my $m = $self->method_lookup($m_name);
758
759         $m->session( $req->session );
760         my @results = $m->run(@args);
761         $m->session('');
762
763         return \@results;
764 }
765
766 1;