in reply to How best to validate the keys of hashref arguments?

I am writing a program that does the same thing with Net::OpenSSH. I've created a OO role written in Moose that wraps Net::OpenSSH and I send commands through the objects that use the role. I call it with: WebServerRemote->new({ssh => 'me@198.168.1.2'}); Then I execute commands like this: $self->grab('ls -l') where "grab" is a wrapper for the capture command. Here's a rough skeleton of it:

package MyOpenSSH 0.000001; use Carp; use Moose::Role; use Modern::Perl; use Net::OpenSSH; use Params::Validate; has 'ssh' => (is => 'rw', isa => 'Net::OpenSSH', required => 1, lazy = +> 0, handles => qr/.*/, ); sub BUILD { # do object validation stuff here } sub exec { my $self = shift; my $opts = shift; if (ref $opts eq 'HASH') { my $cmd = shift; $self->ssh->system($opts, $cmd) || croak 'Command failed: ' . $sel +f->ssh->error; } else { my $cmd = $opts; $self->ssh->system($cmd, @_) || croak 'Command failed: ' . $self-> +ssh->error; } } # wrapper for capture method # this has been edited to simplify and fix a bug since last post. sub grab { my $self = shift; return $self->ssh->capture(@_) if !$self->ssh->error; croak ('ssh command failed'); }

DISCLAIMER: this code is still a work in progress and was written mostly as an experiment as a way for me to get more proficient with Moose and I haven't worked out some details with it. But maybe this will inspire some ideas for you.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^2: How best to validate the keys of hashref arguments?
by cbeckley (Curate) on Mar 16, 2017 at 18:09 UTC

      I have been asking kind of the same question recently. I was told no such animal exists. Read through that discussion on how one might change privileged files securely, though. It's interesting. As pointed out in that thread, there are beasts out there like webmin (which I forgot about years ago) but it is full of security holes and it's ill-advised to use it.

      For now, I'm just kind of writing modules for use on my own personal home network to help me automate set up of websites on local machines with an eye toward eventually being able to automate tasks on a live server as a long term goal. Thanks for the link to the book. Maybe I'll check it out.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        I have been asking kind of the same question recently. I was told no such animal exists.

        First, you should have linked to Re^12: Best way to write to a file owned by root?. Secondly, you were NOT told that no such tool exists:

        Is there some tool or module already out like that that would allow me safely automate updates to my /etc/hosts file?
        I don't know of any.

        One person stating lack of knowledge is quite different from non-existence. Automated, remote administration of a bunch of machines should be a common problem. So, some solutions should exist. How secure those solutions are, and how well they scale, are different questions.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)