(plugin) os::windows::wsman::mode::liststorages - adding transformation options (#3612)

This commit is contained in:
THEPAUT 2022-04-20 10:21:04 -04:00 committed by GitHub
parent 82c376facd
commit 3b95f55805
1 changed files with 27 additions and 2 deletions

View File

@ -30,7 +30,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => {}); $options{options}->add_options(arguments => {
'display-transform-src:s' => { name => 'display_transform_src' },
'display-transform-dst:s' => { name => 'display_transform_dst' }
});
return $self; return $self;
} }
@ -38,6 +41,7 @@ sub new {
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
} }
my @labels = ('size', 'name', 'label', 'type'); my @labels = ('size', 'name', 'label', 'type');
@ -51,6 +55,18 @@ my $map_types = {
6 => 'ramDisk' 6 => 'ramDisk'
}; };
sub get_display_value {
my ($self, %options) = @_;
my $value = $options{name};
if (defined($self->{option_results}->{display_transform_src})) {
$self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
}
return $value;
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -62,9 +78,10 @@ sub manage_selection {
my $results = {}; my $results = {};
foreach my $entry (@$entries) { foreach my $entry (@$entries) {
my $display_value = $self->get_display_value(name => $entry->{Name} );
$results->{ $entry->{DeviceID} } = { $results->{ $entry->{DeviceID} } = {
size => $entry->{Capacity}, size => $entry->{Capacity},
name => $entry->{Name}, name => $display_value,
label => $entry->{Label}, label => $entry->{Label},
type => $map_types->{ $entry->{DriveType} } type => $map_types->{ $entry->{DriveType} }
}; };
@ -117,6 +134,14 @@ List storages.
=over 8 =over 8
=item B<--display-transform-src>
Regexp src to transform display value. (security risk!!!)
=item B<--display-transform-dst>
Regexp dst to transform display value. (security risk!!!)
=back =back
=cut =cut