This file is indexed.

/usr/bin/mrest-cli is in libweb-mrest-cli-perl 0.283-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/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'} || '<NONE>' ) . "\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<Web::MREST> 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<http://metacpan.org/pod/Web::MREST>.