Web-MREST-CLI-0.283000755001750000144 012763060303 14052 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/META.yml000444001750000144 220112763060303 15453 0ustar00smithfarmusers000000000000--- abstract: 'CLI components for Web::MEST-based applications' author: - 'Nathan Cutler ' build_requires: File::Basename: '0' File::HomeDir: '0' configure_requires: Module::Build: '0' dynamic_config: 1 generated_by: 'Module::Build version 0.4205, CPAN::Meta::Converter version 2.150005' license: bsd meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Web-MREST-CLI no_index: directory: - config provides: Web::MREST::CLI: file: lib/Web/MREST/CLI.pm version: '0.283' Web::MREST::CLI::Parser: file: lib/Web/MREST/CLI/Parser.pm requires: App::CELL: '0.205' Data::Dumper: '0' Encode: '0' File::HomeDir: '0' File::ShareDir: '1.00' Getopt::Long: '2.32' HTTP::Request::Common: '0' JSON: '0' LWP::Protocol::https: '6.04' LWP::UserAgent: '6.05' Log::Any::Adapter: '0' Params::Validate: '0' Pod::Usage: '0' Term::ReadLine: '0' Test::Deep: '0' Try::Tiny: '0' URI::Escape: '0' perl: '5.012' resources: license: http://opensource.org/licenses/bsd-license.php version: '0.283' x_serialization_backend: 'CPAN::Meta::YAML version 0.012' Web-MREST-CLI-0.283/MANIFEST000444001750000144 37012763060303 15320 0ustar00smithfarmusers000000000000bin/mrest-cli Build.PL Changes config/CLI_Config.pm config/CLI_Message_en.conf config/CLI_MetaConfig.pm lib/Web/MREST/CLI.pm lib/Web/MREST/CLI/Parser.pm LICENSE MANIFEST This list of files MANIFEST.SKIP META.json META.yml README.rst t/001-noop.t Web-MREST-CLI-0.283/Build.PL000444001750000144 307612763060303 15511 0ustar00smithfarmusers000000000000use 5.012000; use strict; use warnings FATAL => 'all'; use Module::Build; my $builder = Module::Build->new( module_name => 'Web::MREST::CLI', license => 'bsd', dist_author => q{Nathan Cutler }, dist_version_from => 'lib/Web/MREST/CLI.pm', create_license => 0, create_readme => 0, release_status => 'stable', share_dir => { dist => [ 'config' ], }, meta_merge => { no_index => { directory => [ "config" ] } }, script_files => [ 'bin/mrest-cli', ], configure_requires => { 'Module::Build' => 0, }, build_requires => { 'File::Basename' => 0, 'File::HomeDir' => 0, }, requires => { 'perl' => 5.012, 'App::CELL' => 0.205, 'Data::Dumper' => 0, 'Encode' => 0, 'File::HomeDir' => 0, 'File::ShareDir' => 0, 'Getopt::Long' => 2.32, 'HTTP::Request::Common' => 0, 'JSON' => 0, 'Log::Any::Adapter' => 0, 'LWP::UserAgent' => 6.05, 'LWP::Protocol::https' => 6.04, 'Params::Validate' => 0, 'Pod::Usage' => 0, 'Term::ReadLine' => 0, 'Test::Deep' => 0, 'Try::Tiny' => 0, 'URI::Escape' => 0, }, add_to_cleanup => [ 'Web-MREST-CLI-*' ], # create_makefile_pl => 'traditional', recursive_test_files => 1, ); $builder->create_build_script(); Web-MREST-CLI-0.283/MANIFEST.SKIP000444001750000144 252112763060303 16105 0ustar00smithfarmusers000000000000#!start included /usr/lib/perl5/5.18.1/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/lib/perl5/5.18.1/ExtUtils/MANIFEST.SKIP # Avoid configuration metadata file ^MYMETA\. # Avoid Module::Build generated and utility files. \bBuild$ \bBuild.bat$ \b_build \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ ^MANIFEST\.SKIP # Avoid archives of this distribution \bApp-Dochazka-Common-[\d\.\_]+ # Avoid release script helper files \bCPAN_NAME$ \bOBS_PROJECT$ \bVERSION_MODULE$ # Avoid perlcritic, travis config files \B\.perlcriticrc\b \B\.travis.yml\b Web-MREST-CLI-0.283/META.json000444001750000144 350012763060303 15626 0ustar00smithfarmusers000000000000{ "abstract" : "CLI components for Web::MEST-based applications", "author" : [ "Nathan Cutler " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4205", "license" : [ "bsd" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Web-MREST-CLI", "no_index" : { "directory" : [ "config" ] }, "prereqs" : { "build" : { "requires" : { "File::Basename" : "0", "File::HomeDir" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0" } }, "runtime" : { "requires" : { "App::CELL" : "0.205", "Data::Dumper" : "0", "Encode" : "0", "File::HomeDir" : "0", "File::ShareDir" : "1.00", "Getopt::Long" : "2.32", "HTTP::Request::Common" : "0", "JSON" : "0", "LWP::Protocol::https" : "6.04", "LWP::UserAgent" : "6.05", "Log::Any::Adapter" : "0", "Params::Validate" : "0", "Pod::Usage" : "0", "Term::ReadLine" : "0", "Test::Deep" : "0", "Try::Tiny" : "0", "URI::Escape" : "0", "perl" : "5.012" } } }, "provides" : { "Web::MREST::CLI" : { "file" : "lib/Web/MREST/CLI.pm", "version" : "0.283" }, "Web::MREST::CLI::Parser" : { "file" : "lib/Web/MREST/CLI/Parser.pm" } }, "release_status" : "stable", "resources" : { "license" : [ "http://opensource.org/licenses/bsd-license.php" ] }, "version" : "0.283", "x_serialization_backend" : "JSON::PP version 2.27203" } Web-MREST-CLI-0.283/README.rst000444001750000144 56412763060303 15663 0ustar00smithfarmusers000000000000Web::MREST::CLI =============== .. image:: https://travis-ci.org/smithfarm/mrest-cli.svg?branch=master :target: https://travis-ci.org/smithfarm/mrest-cli .. image:: https://badge.fury.io/pl/Web-MREST-CLI.svg :target: https://badge.fury.io/pl/Web-MREST-CLI CLI components for Web::MREST Documentation ============= See https://metacpan.org/pod/Web::MREST::CLI Web-MREST-CLI-0.283/Changes000444001750000144 233512763060303 15505 0ustar00smithfarmusers000000000000Revision history for Web::MREST::CLI 0.275 2015-07-27 13:31 CEST - Split off from Web::MREST 0.276 2015-07-27 21:24 CEST - UserAgent.pm: validate arguments sent to send_req(), and explicitly set entity body to an empty string if it is undefined ( fixes https://github.com/smithfarm/dochazka-cli/issues/7 ) - Build.PL: declare Params::Validate dependency 0.277 2015-07-30 15:10 CEST - Implement early debugging feature for mrest-cli - Implement a generalized init_cli_client() routine in CLI.pm and call it from bin/mrest-cli - Drop UserAgent.pm; move contents to Web::MREST::CLI - Move normalize_filespec() from Web::MREST::CLI::UserAgent to Web::MREST::CLI - Build.PL: declare File::HomeDir dependency 0.278 2016-01-10 16:40 CET - CLI.pm: be more careful with early debugging filespec provided by user 0.279 2016-01-12 15:19 CET - Changes: manual edit - release.sh: tweak release script - CLI.pm: fix dochazka-cli bug #26 0.280 2016-01-14 16:05 CET - CLI.pm->send_req: do not UTF-8 decode the response 0.281 2016-09-04 19:54 CEST - init_cli_client: optionally take arrayref of sitedirs - Travis CI 0.282 2016-09-04 19:56 CEST - MANIFEST: now we have README.rst only 0.283 2016-09-04 19:58 CEST - MANIFEST: add t/001-noop.t Web-MREST-CLI-0.283/LICENSE000444001750000144 271112763060303 15215 0ustar00smithfarmusers000000000000Copyright (c) 2014-2015, SUSE LLC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of mrest-cli nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Web-MREST-CLI-0.283/t000755001750000144 012763060303 14315 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/t/001-noop.t000444001750000144 361012763060303 16110 0ustar00smithfarmusers000000000000# ************************************************************************* # Copyright (c) 2014-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* # # initial test ensuring that the test suite will not run outside of the # development environment # #!perl use 5.012; use strict; use warnings; #use App::CELL::Test::LogToFile; use Test::More; note( 'noop test' ); ok( 1 ); done_testing; Web-MREST-CLI-0.283/config000755001750000144 012763060303 15317 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/config/CLI_MetaConfig.pm000444001750000144 364512763060303 20525 0ustar00smithfarmusers000000000000# ************************************************************************* # Copyright (c) 2014-2015-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* # MREST_CLI_URI_BASE # URI of the App::Dochazka::REST server set( 'MREST_CLI_URI_BASE', 'http://localhost:5000' ); # ----------------------------------- # DO NOT EDIT ANYTHING BELOW THIS LINE # ----------------------------------- use strict; use warnings; 1; Web-MREST-CLI-0.283/config/CLI_Config.pm000444001750000144 553612763060303 17717 0ustar00smithfarmusers000000000000# ************************************************************************* # Copyright (c) 2014-2015-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* # ----------------------------------- # Dochazka-CLI # ----------------------------------- # CLI_Config.pm # # Main configuration file # ----------------------------------- # MREST_CLI_COOKIE_JAR # default location of the cookie jar (in user's home directory) # If you don't want it in the user's home directory, specify an absolute # path. set( 'MREST_CLI_COOKIE_JAR', ".cookies.txt" ); # MREST_CLI_LOG_FILE # default location of the log file (in user's home directory) # If you don't want it in the user's home directory, specify an absolute # path. set( 'MREST_CLI_LOG_FILE', "mrest-cli.log" ); # MREST_CLI_LOG_FILE_RESET # if this is set to a true value, the logfile will be wiped each # time mrest-cli is run set( 'MREST_CLI_LOG_FILE_RESET', 1 ); # MREST_CLI_SUPPRESSED_HEADERS # list of headers to be suppressed in the output set ('MREST_CLI_SUPPRESSED_HEADERS', [ qw( accept content-type content-length cache-control pragma expires server Client-Response-Num Client-Peer Client-Date Set-Cookie Date Vary ) ] ); # ----------------------------------- # DO NOT EDIT ANYTHING BELOW THIS LINE # ----------------------------------- use strict; use warnings; 1; Web-MREST-CLI-0.283/config/CLI_Message_en.conf000444001750000144 461612763060303 21067 0ustar00smithfarmusers000000000000# ************************************************************************* # Copyright (c) 2014-2015-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* #-------------------------------------------------------------# # CLI_Message_en.pm # #-------------------------------------------------------------# # MREST_CLI_PARSE_ERROR # command did not parse MREST_CLI_PARSE_ERROR Parse error # MREST_CLI_PARSE_ERROR_NO_BODY # command did not parse due to missing request body MREST_CLI_PARSE_ERROR_NO_BODY Parse error: did you forget a request body? # MREST_CLI_SERVER_ERROR # server error MREST_CLI_SERVER_ERROR Server error: %s # MREST_CLI_HTTP_REQUEST_OK_NODATA # HTTP request succeeded, but no data was returned MREST_CLI_HTTP_REQUEST_OK_NODATA HTTP request succeeded, but no data was returned # MREST_CLI_UNAUTHORIZED MREST_CLI_UNAUTHORIZED The server responded with "401 Unauthorized" Web-MREST-CLI-0.283/lib000755001750000144 012763060303 14620 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/lib/Web000755001750000144 012763060303 15335 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/lib/Web/MREST000755001750000144 012763060303 16227 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/lib/Web/MREST/CLI.pm000444001750000144 2244712763060303 17362 0ustar00smithfarmusers000000000000# ************************************************************************* # Copyright (c) 2014-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* # ------------------------ # Model module # ------------------------ package Web::MREST::CLI; use 5.012; use strict; use warnings; use App::CELL qw( $CELL $log $site $meta ); use App::CELL::Test qw( _touch ); use Carp qw( confess ); use Data::Dumper; use Encode; use Exporter qw( import ); # Exporter was first released with perl 5 use File::HomeDir; # File::HomeDir was not in CORE (or so I think) use File::Spec; # File::Spec was first released with perl 5.00405 use HTTP::Request::Common qw( GET PUT POST DELETE ); use JSON; use Log::Any::Adapter; use LWP::UserAgent; use LWP::Protocol::https; #print "LWP::UserAgent: ".LWP::UserAgent->VERSION,"\n"; #print "LWP::Protocol::https: ".LWP::Protocol::https->VERSION,"\n"; use Params::Validate qw( :all ); use URI::Escape; =head1 NAME Web::MREST::CLI - CLI components for Web::MEST-based applications =head1 VERSION Version 0.283 =cut our $VERSION = '0.283'; =head1 DESCRIPTION Top-level module of the L distribution. Exports some "generalized" functions that are used internally and might also be useful for writing CLI clients in general. =cut =head1 EXPORTS =cut our @EXPORT_OK = qw( init_cli_client normalize_filespec send_req ); =head1 PACKAGE VARIABLES =cut # user agent my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 1, } ); # dispatch table with references to HTTP::Request::Common functions my %methods = ( GET => \&GET, PUT => \&PUT, POST => \&POST, DELETE => \&DELETE, ); my %sh; our $JSON = JSON->new->allow_nonref->convert_blessed->utf8->pretty; =head1 FUNCTIONS =head2 init_cli_client Takes PARAMHASH containing possible parameters C, C, and C. Initializes CLI client and returns a status object. The C string should use hyphens instead of double-colons, i.e. C instead of C. =cut sub init_cli_client { my ( %ARGS ) = validate( @_, { distro => { type => SCALAR }, sitedir => { type => ARRAYREF|SCALAR|UNDEF, optional => 1 }, early_debug => { type => SCALAR|UNDEF, optional => 1 }, } ); my $tf = $ARGS{'early_debug'}; if ( $tf ) { _touch $tf; if ( -r $tf and -w $tf ) { unlink $tf; Log::Any::Adapter->set( 'File', $tf ); $log->debug( __PACKAGE__ . "::init_cli_client activating early debug logging to $tf" ); } else { print "Given unreadable/unwritable early debugging filespec $tf\n"; } } my @targets; if ( defined( $ARGS{'sitedir'} ) ) { if ( ref( $ARGS{'sitedir'} ) eq 'ARRAY' ) { @targets = @{ $ARGS{'sitedir'} }; } if ( ref( $ARGS{'sitedir'} ) eq '' ) { @targets = ( $ARGS{'sitedir'} ); } } my $target = File::ShareDir::dist_dir( $ARGS{'distro'} ); my $status = $CELL->load( verbose => 1, sitedir => $target ); die $status->text unless $status->ok; foreach my $target ( @targets ) { print "Loading configuration files from $target\n"; $status = $CELL->load( verbose => 1, sitedir => $target ); print "WARNING: " . $status->text . "\n" unless $status->ok; } # initialize the LWP::UserAgent object init_ua(); return $CELL->status_ok( 'MREST_CLI_INIT_OK' ); } =head2 normalize_filespec Given a filename (path) which might be relative or absolute, return an absolute version. If the path was relative, it will be anchored to the home directory of the user we are running as. =cut sub normalize_filespec { my $fs = shift; confess "normalize_filespec(): missing argument!" unless $fs; my $is_absolute = File::Spec->file_name_is_absolute( $fs ); if ( $is_absolute ) { return $fs; } return File::Spec->catfile( File::HomeDir->my_home, $fs ); } =head2 init_ua Initialize the LWP::UserAgent singleton object. =cut sub init_ua { my $cookie_jar = $site->MREST_CLI_COOKIE_JAR; if ( $cookie_jar ) { $cookie_jar = normalize_filespec( $cookie_jar ); print( "Cookie jar: $cookie_jar\n" ); } else { die "UFGaRAL! MREST_CLI_COOKIE_JAR site param undefined!"; } $ua->cookie_jar( { file => $cookie_jar } ); return; } =head2 cookie_jar Return the cookie_jar associated with our user agent. =cut sub cookie_jar { $ua->cookie_jar }; =head2 send_req Send a request to the server, get the response, convert it from JSON, and return it to caller. Die on unexpected errors. =cut sub send_req { no strict 'refs'; # process arguments my ( $method, $path, $body_data ) = validate_pos( @_, { type => SCALAR }, { type => SCALAR }, { type => SCALAR|UNDEF, optional => 1 }, ); $log->debug( "Entering " . __PACKAGE__ . "::send_req with $method $path" ); if ( ! defined( $body_data ) ) { # HTTP::Message 6.10 complains if request content is undefined $log->debug( "No request content given; setting to empty string" ); $body_data = ''; } # initialize suppressed headers hash %sh map { $log->debug( "Suppressing header $_" ); $sh{ lc $_ } = ''; } @{ $site->MREST_CLI_SUPPRESSED_HEADERS } unless %sh; $path = "/$path" unless $path =~ m/^\//; $log->debug("send_req: path is $path"); # convert body data to UTF-8 my $encoded_body_data = encode( "UTF-8", $body_data ); # assemble request my $url = $meta->MREST_CLI_URI_BASE || 'http://localhost:5000'; $url .= uri_escape( $path, '%' ); $log->debug( "Encoded URI is $url" ); my $r = $methods{$method}->( $url, Accept => 'application/json', Content_Type => 'application/json', Content => $body_data, ); # add basic auth my $user = $meta->CURRENT_EMPLOYEE_NICK || 'demo'; my $password = $meta->CURRENT_EMPLOYEE_PASSWORD || 'demo'; $log->debug( "send_req: basic auth user $user / pass $password" ); $r->authorization_basic( $user, $password ); # send request, get response my $response = $ua->request( $r ); $log->debug( "Response is " . Dumper( $response ) ); my $code = $response->code; # process response entity my $status; my $content = $response->content; #$log->debug( "Response entity is " . Dumper( $content ) ); if ( $content ) { #my $unicode_content = decode( "UTF-8", $content ); # if the content is a bare string, enclose it in double quotes if ( $content =~ m/^[^\{].*[^\}]$/s ) { $content =~ s/\n//g; $log->debug( "Adding double quotes to bare JSON string" ); $content = '"' . $content . '"'; } my $perl_scalar = $JSON->decode( $content ); if ( ref( $perl_scalar ) ) { # if it's a hash, we have faith that it will bless into a status object $status = bless $perl_scalar, 'App::CELL::Status'; } elsif ( $perl_scalar eq 'Unauthorized' ) { $status = $CELL->status_err( 'MREST_CLI_UNAUTHORIZED', payload => $response->code . ' ' . $response->message ); $log->error("Unauthorized"); } else { $status = $CELL->status_err( 'MREST_OTHER_ERROR_REPORT_THIS_AS_A_BUG', payload => $perl_scalar ); $log->error("Unexpected HTTP response ->$perl_scalar<-" ); } } else { $status = $CELL->status_warn( 'MREST_CLI_HTTP_REQUEST_OK_NODATA' ); } $status->{'http_status'} = $response->code . ' ' . $response->message; # load up headers $status->{'headers'} = {}; $response->headers->scan( sub { my ( $h, $v ) = @_; $status->{'headers'}->{$h} = $v unless exists $sh{ lc $h }; } ); return $status; } 1; Web-MREST-CLI-0.283/lib/Web/MREST/CLI000755001750000144 012763060303 16636 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/lib/Web/MREST/CLI/Parser.pm000444001750000144 1524712763060303 20616 0ustar00smithfarmusers000000000000# ************************************************************************* # Copyright (c) 2014-2015-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* # # parser module # package Web::MREST::CLI::Parser; use 5.012; use strict; use warnings; use App::CELL qw( $CELL $log ); use Test::Deep::NoTest; use Web::MREST::CLI qw( send_req ); our $anything = qr/^.+$/i; =head1 NAME Web::MREST::CLI::Parser - Parser for demo MREST command line client =head1 SYNOPSIS use Try::Tiny; my $status; my @tokens = split /\s+/, 'MY SAMPLE COMMAND'; try { Web::MREST::CLI::Parse::parse_tokens( [], \@tokens ); } catch { $status = $_; }; =head1 CLI COMMANDS The parsing of CLI commands takes place in the C function, which calls itself recursively until it gets to a rather macabre-sounding die send_req . . . This causes control to return to the while loop in C with the return value of the C, which is a status object. All tokens should be chosen to be distinguishable by their first three characters. =cut my $method; # store the HTTP method in a package variable so it is remembered sub parse_tokens { my ( $pre, $tokens ) = @_; return $CELL->status_err( "No more tokens" ) unless ref $tokens; my @tokens = @$tokens; my $token = shift @tokens; # the first token designates the HTTP method if ( @$pre == 0 ) { # first token is supposed to be the HTTP method # GET '' if ( $token =~ m/^GET/i ) { $method = 'GET'; parse_tokens( [ 'GET' ], \@tokens ) if @tokens; die send_req( 'GET', '' ); } # PUT '' elsif ( $token =~ m/^PUT/i ) { $method = 'PUT'; parse_tokens( [ 'PUT' ], \@tokens ) if @tokens; die send_req( 'PUT', '' ); } # POST '' elsif ( $token =~ m/^POS/i ) { $method = 'POST'; parse_tokens( [ 'POST' ], \@tokens ) if @tokens; die send_req( 'POST', '' ); } # DELETE '' elsif ( $token =~ m/^DEL/i ) { $method = 'DELETE'; parse_tokens( [ 'DELETE' ], \@tokens ) if @tokens; die send_req( 'DELETE', '' ); } # EXIT, QUIT, and the like elsif ( $token =~ m/^(exi)|(qu)|(\\q)/i and eq_deeply( $pre, [] ) ) { die $CELL->status_ok( 'MREST_CLI_EXIT' ); } die $CELL->status_err( 'MREST_CLI_PARSE_ERROR' ); } # second token represents the resource class ( top-level, employee, priv, etc.) if ( @$pre == 1 ) { # # root resource # if ( $token eq '/' ) { die send_req( $method, '/' ); } # # # top-level resource: handle it here # # "/bugreport" if ( $token =~ m/^bug/i ) { die send_req( $method, 'bugreport' ); } # "/configinfo" if ( $token =~ m/^con/i ) { die send_req( $method, 'configinfo' ); } # "/docu/{pod,html,text} \"$RESOURCE'"" if ( $token =~ m/^doc/i ) { if ( @tokens ) { my $pod_html = shift @tokens; my $json = join( ' ', @tokens ); if ( $json ) { $json = '"' . $json . '"' unless $json =~ m/^".*"$/; if ( $pod_html =~ m/^pod/i ) { die send_req( $method, 'docu/pod', $json ); } elsif ( $pod_html =~ m/^htm/i ) { die send_req( $method, 'docu/html', $json ); } elsif ( $pod_html =~ m/^tex/i ) { die send_req( $method, 'docu/text', $json ); } } else { print "You should specify a resource\n"; } } else { die send_req( $method, 'docu' ); } } # "/echo [$JSON]" if ( $token =~ m/^ech/i ) { die send_req( $method, 'echo', join(' ', @tokens) ); } # "/noop" if ( $token =~ m/^noo/i ) { die send_req( $method, "noop" ); } # "/param $TYPE $JSON" # "/param/:type/:param" if ( $token =~ m/^par/i ) { if ( scalar( @tokens ) > 1 ) { my $type = $tokens[0]; my $param = $tokens[1]; my $json = join( ' ', @tokens[2..$#tokens] ); die send_req( $method, "param/$type/$param", $json ); } } # "/test/?:specs" if ( $token =~ m/^tes/i ) { my $uri_path; if ( @tokens ) { my $uri_ext .= join( ' ', @tokens ) if @tokens; $uri_path = "test/$uri_ext"; } else { $uri_path = "test"; } die send_req( $method, $uri_path ); } # "/version" if ( $token =~ m/^ver/i and eq_deeply( $pre, [ $method ] ) ) { die send_req( $method, 'version' ); } } # we have gone all the way through the state machine without a match die $CELL->status_err( 'MREST_CLI_PARSE_ERROR' ); } 1; Web-MREST-CLI-0.283/bin000755001750000144 012763060303 14622 5ustar00smithfarmusers000000000000Web-MREST-CLI-0.283/bin/mrest-cli000444001750000144 1440312763060303 16623 0ustar00smithfarmusers000000000000#!/usr/bin/perl # ************************************************************************* # Copyright (c) 2014-2015-2015, SUSE LLC # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of SUSE LLC nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ************************************************************************* # # Dochazka CLI script # use 5.012; use strict; use warnings; use App::CELL qw( $CELL $log $site $meta ); use Data::Dumper; use File::ShareDir; use File::Spec; use Getopt::Long 2.32; use Log::Any::Adapter; use Pod::Usage; use Term::ReadLine; use Try::Tiny; use Web::MREST::CLI qw( init_cli_client normalize_filespec ); use Web::MREST::CLI::Parser; my $Parser = 'Web::MREST::CLI::Parser'; local $Data::Dumper::Terse = 1; # # logger initialization routine # sub init_logger { my $logfile = normalize_filespec( $site->MREST_CLI_LOG_FILE ); print( "Log file is $logfile\n" ); unlink $logfile if $site->MREST_CLI_LOG_FILE_RESET; # ----------------------------------------------------------- # -- to debug configuration file loading issues, uncomment -- # -- this and call init_logger() before $CELL->load(...) -- # ----------------------------------------------------------- #my $logfile = normalize_filespec( "mrest-cli.log" ); #unlink $logfile; Log::Any::Adapter->set('File', $logfile); $log->init( ident => 'mrest-cli', debug_mode => 1 ); $log->debug( 'Logger initialized' ); } # # CLI client initialization routine: might die # sub init { my ( $early_debug ) = @_; die if defined( $site->MREST_CLI_LOG_FILE ); my $status = init_cli_client( distro => 'Web-MREST-CLI', early_debug => $early_debug ); return $status unless $status->ok; die unless defined( $site->MREST_CLI_LOG_FILE ); if ( ! ( $meta->MREST_CLI_URI_BASE ) ) { $meta->set( 'MREST_CLI_URI_BASE', 'http://localhost:5000' ); } print "Using URI base " . $meta->MREST_CLI_URI_BASE . "\n"; print "Hopefully, a server is listening there. . .\n"; # initialize CLI-specific logger init_logger(); return $CELL->status_ok; } # # get prompt # sub get_prompt { "$Parser> " } # ------------------------------------------------------------------------- # main # ------------------------------------------------------------------------- # process command-line options my $help = 0; my $sitedir; my $early_debug; GetOptions( 'help|?' => \$help, 'early-debug|e=s' => \$early_debug, ); pod2usage(1) if $help; if ( $early_debug ) { print "Early debugging activated; will log early messages to $early_debug\n"; } # initialize CLI client my $status; if ( ( my $status = init( $early_debug ) )->not_ok ) { print '(' . $status->level . ') ' . $status->text . "\n"; exit; } my $term = new Term::ReadLine 'mrest-cli'; binmode STDOUT, ":utf8"; my $cmd; while ( defined ( $cmd = $term->readline( get_prompt() ) ) ) { my @tokens = split /\s+/, $cmd; next unless @tokens; #print join( ' ', @tokens ), "\n"; # parse_tokens will die with the status try { Web::MREST::CLI::Parser::parse_tokens( [], \@tokens ); } catch { $status = $_; }; if ( ref( $status ) ne 'App::CELL::Status' ) { $status = $CELL->status_crit( 'MREST_CLI_PARSER_DECEASED', payload => $status ); } last if $status->code eq 'MREST_CLI_EXIT'; if ( $status->code ne 'MREST_CLI_PARSE_ERROR' ) { print "HTTP status: " . ( delete $status->{'http_status'} || '' ) . "\n"; print "Non-suppressed headers: " . Dumper( $status->{'headers'} ) if $status->{'headers'}; delete $status->{'headers'}; my $expurgated_status = $status->expurgate; #print Dumper( $expurgated_status ); print "Response: " . Dumper( $expurgated_status ) . "\n"; } else { print( ( $status->code eq 'MREST_CLI_PARSE_ERROR' ) ? $status->text . "\n" : $status->code . ' (' . $status->level . ') ' . $status->text . "\n" ); } } __END__ =head1 NAME mrest-cli - Web::MREST demo/testing command-line client =head1 SYNOPSIS $ mrest-cli -h --help -h Get help --sitedir -s Specify sitedir (defaults to none) $ mrest-cli Web::MREST> get bugreport DISPATCH_BUGREPORT (OK) See payload for bug reporting instructions HTTP status: 200 OK Non-suppressed headers: { 'X-Web-Machine-Trace' => 'b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,c3,c4,d4,e5,f6,g7,g8,h10,i12,l13,m16,n16,o16,o18,o18b' } Response: { 'report_bugs_to' => 'bug-App-MREST@rt.cpan.org' } =head1 DESCRIPTION This is the L demo/testing command line interface (CLI). It enables the user to generate HTTP requests (GET, PUT, POST, DELETE) to the REST server and view the server's responses. Each REST resource has a documented CLI syntax that can be viewed by querying the REST server -- e.g., via a web browser. For more information, see L.