From: Peter van Dijk Date: Mon, 22 Apr 2013 08:18:31 +0000 (+0000) Subject: add testbench script for remotebackend development, thanks Aki. Closes #742 X-Git-Tag: auth-3.3-rc1~170 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62b38b0fb34996cb08e676608943a61e90688988;p=pdns add testbench script for remotebackend development, thanks Aki. Closes #742 git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3171 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/contrib/remotebackend-pipe-test.pl b/contrib/remotebackend-pipe-test.pl new file mode 100644 index 000000000..13d6bbac5 --- /dev/null +++ b/contrib/remotebackend-pipe-test.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl +### This script is intended for testing/developing remotebackend scripts +### To use, please install libjson-any-perl (JSON::Any) and libjson-xs-perl (JSON::XS) +### (c) Aki Tuomi 2013 - Distributed under same license as PowerDNS Authoritative Server +use strict; +use warnings; +use 5.005; +use IPC::Open2; +use JSON::Any; + +### CONFIGURATION SECTION + +## Full path to your remotebackend script +my $script = "/home/cmouse/projects/pdns-v6-autorev/rev.pl"; + +## These are used to send initialize method before your actual code +my $initparams = { value => "foo", value2 => "bar" }; + +## END CONFIGURATION + +$|=1; +my $in; +my $out; +my $pid = open2($in,$out,$script); + +my $j = JSON::Any->new; + +sub rpc { + my $meth = shift; + my %p = @_; + + print $j->encode({method => $meth, parameters => \%p}),"\r\n"; + print $out $j->encode({method => $meth, parameters => \%p}),"\r\n"; + my $res = <$in>; + if ($res) { + chomp $res; + print $res,"\n"; + } +} + +rpc 'initialize', %$initparams; + +if (@ARGV>1) { + +## this lets you call whatever method with simple parameters +## like this: + +# perl remotebackend-pipe-test.pl lookup qtype SOA qname powerdns.com + +## this will execute +## {"parameters":{"qname":"powerdns.com","qtype":"SOA"},"method":"lookup"} +## on your remotebackend + +my $meth = shift; +rpc $meth, @ARGV; + + +} else { + +## Put whatever you want to run here. Or leave it empty if you +## only want to use the command line + +#rpc 'lookup', qname => 'powerdns.com', qtype => 'SOA'; + +}