Skip to content

Instantly share code, notes, and snippets.

@hdp
Created September 10, 2011 02:12
Show Gist options
  • Save hdp/1207839 to your computer and use it in GitHub Desktop.
Save hdp/1207839 to your computer and use it in GitHub Desktop.
#!perl
package Test::SSH;
use strict;
use warnings;
use Moose;
use Moose::Util::TypeConstraints;
use MooseX::Types::PortNumber 'PortNumber';
with ( 'MooseX::OneArgNew' => {
type => 'Str',
init_arg => 'host',
});
has ssh => (
is => 'ro',
isa => 'Net::SSH::Perl',
init_arg => undef,
lazy => 1,
builder => '_build_ssh',
);
# new method parameters
has host => (
isa => 'Str',
is => 'ro',
required => 1,
);
enum Protocol => ( '1,2', '2,1', 1, 2 );
has protocol => (
isa => 'Protocol',
is => 'ro',
);
enum Cipher1 => qw( IDEA DES DES3 Blowfish );
enum Cipher2 => qw( arcfour blowfish-cbc 3des-cbc );
# TODO: Check cipher against which protocol is being used.
has cipher => (
isa => 'Cipher1|Cipher2',
is => 'ro',
);
subtype 'Ciphers' => as 'ArrayRef[Cipher2]';
coerce 'Ciphers',
from 'Str',
via { split /,/, $_ };
has ciphers => (
isa => 'Ciphers',
is => 'ro',
coerce => 1,
);
has port => (
isa => 'PortNumber',
is => 'ro',
);
# suppress_shell
has [qw( debug interactive privileged compression use_pty )] => (
isa => 'Bool',
is => 'ro',
);
# TODO: validate file existence for identity_files
has [qw( identity_files options )] => (
isa => 'ArrayRef[Str]',
is => 'ro',
);
# TODO: ignore compression_level if compression is not true
# TODO: validate compression_level
has compression_level => (
isa => 'Int',
is => 'ro',
);
# login method parameters
#has [qw( user password )] => (
# isa => 'Str',
# is => 'ro',
#);
sub _build_ssh {
my $self = shift;
return Net::SSH::Perl->new(
$self->host,
map { $_ => $self->$_ } qw(
protocol cipher ciphers port debug interactive priviledged
identity_files compression compression_level use_pty options
);
);
}
__PACKAGE__->meta->make_immutable;
no Moose;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment