# # Copyright (c) 2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary common routines for ## NACL::STask::VserverSecurityFileDirectoryNtfs ## NACL::STask::VserverSecurityFileDirectoryNtfsDacl ## NACL::STask::VserverSecurityFileDirectoryNtfsSacl ## NACL::STask::VserverSecurityFileDirectoryPolicy ## NACL::STask::VserverSecurityFileDirectoryPolicyTask ## ## @author Kathar.Hidayath@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::STask::_Fsecurity; use strict; use warnings; use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NATE::Exceptions::Argument qw(:try); use NATE::BaseException (); use NACL::APISet::Exceptions::ResponseException (); use NACL::C::Exceptions::VserverSecurityFileDirectoryNtfs::AlreadyExists (); use NACL::C::Exceptions::VserverSecurityFileDirectoryNtfs::DoesNotExist ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsDacl::AlreadyExists ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsDacl::DoesNotExist ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsSacl::AlreadyExists ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsSacl::DoesNotExist ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryPolicy::AlreadyExists ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryPolicy::DoesNotExist ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryPolicyTask::AlreadyExists ( ); use NACL::C::Exceptions::VserverSecurityFileDirectoryPolicyTask::DoesNotExist ( ); use NACL::Exceptions::VerifyFailure (); use Params::Validate qw(validate SCALAR validate_with SCALARREF BOOLEAN ); BEGIN { use Exporter qw(import); our %EXPORT_TAGS = ( all => [qw(_add_create_helper _purge_helper )] ); our @EXPORT_OK = @{ $EXPORT_TAGS{all} }; } =head1 NAME NACL::STask::_Fsecurity =head1 DESCRIPTION Common code for Fsecurity stask implementation. =head1 METHODS =head2 _add_create_helper $pkg_or_obj->_add_create_helper(); NACL::STask::_Fsecurity->_add_create_helper( 'command_interface' => $ci, 'vserver' => $vserver, 'ntfs-sd' => $ntfs_sd, 'nacltask_if_exists' => $action # default die %other_options, ); This method will call the base class create or add method of the Fsecurity Stask which invokes this method. The user has to pass the method to be called as one of the input. This method itself verify the creation or addition based on the nacltask_verify(Refer the nacltask_verify pod of NACL::STask::VserverSecurityFileDirectoryNtfs ). =cut sub _add_create_helper { $Log->enter() if $may_enter; my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { nacltask_if_exists => $pkg->_if_exists_validate_spec(), nacltask_verify => { type => BOOLEAN, default => 0 }, _was_created => { type => SCALARREF, optional => 1 }, }, allow_extra => 1 ); # Transform %opts from the options we received into the options to # pass to the base class method. my ( $self, %common_opts, %nacltask_opts ); $pkg->_copy_common_component_params_with_ci( source => \%opts, target => \%common_opts ); $pkg->_move_nacltask_options( source => \%opts, target => \%nacltask_opts ); my $was_created = delete $opts{_was_created}; $$was_created = 0; my $if_exists = $nacltask_opts{'nacltask_if_exists'}; my $verify = $nacltask_opts{'nacltask_verify'}; my $method = delete $opts{'method'}; CREATE: { use warnings; try { my $temp = "C_SUPER::$method"; $self = $pkg->$temp(%opts); $$was_created = 1; } except { my $sub_reference = sub { my $exception = shift; $self = $pkg->_element_exists_handler( create_opts => \%opts, nacltask_if_exists => $if_exists, exception => $exception ); if ( !$self ) { no warnings qw(exiting); redo CREATE; } }; return { 'NACL::C::Exceptions::VserverSecurityFileDirectoryNtfs::AlreadyExists' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsDacl::AlreadyExists' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsSacl::AlreadyExists' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryPolicy::AlreadyExists' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryPolicyTask::AlreadyExists' => $sub_reference, }; }; } if ($verify) { delete $opts{'index'}; delete $opts{'index-num'}; $pkg->verify_state(%opts); } $Log->exit() if $may_exit; return $self; } ## end sub _add_create_helper =head2 _purge_helper $pkg_or_obj->_purge_helper(); NACL::STask::_Fsecurity->_purge_helper( 'command_interface' => $ci, 'vserver' => $vserver, 'ntfs-sd' => $ntfs_sd, %other_options, ); This method will call the base class remove or delete method of the Fsecurity Stask which invokes this method. The user has to pass the method to be called as one of the input. This method itself verify the deletion or removal based on the nacltask_verify(Refer the nacltask_verify pod of NACL::STask::VserverSecurityFileDirectoryNtfs ). =cut sub _purge_helper { $Log->enter() if $may_enter; my $pkg_or_obj = shift; my %orig_opts = @_; my $additional_spec = { nacltask_verify => { type => BOOLEAN, default => 0 }, nacltask_if_purged => { type => BOOLEAN, default => 'pass' }, _was_deleted => { type => SCALARREF, optional => 1 }, method => { type => SCALAR } }; # Throw away options specific to the task $pkg_or_obj->_hash_move( source => \%orig_opts, target => {}, move => [ keys %{$additional_spec} ] ); my %opts = $pkg_or_obj->_common_validate_with( params => \@_, additional_spec => $additional_spec, ); my %common_opts; $pkg_or_obj->_copy_common_component_params_with_ci( source => \%opts, target => \%common_opts ); my $if_purged = delete $opts{nacltask_if_purged}; my $method = delete $opts{'method'}; my $was_deleted = delete $opts{_was_deleted}; $$was_deleted = 0; AGAIN: { use warnings; try { my $temp = "C_SUPER::$method"; $pkg_or_obj->$temp( %common_opts, %orig_opts ); $$was_deleted = 1; } except { my $sub_reference = sub { my $exception = shift; if ( $if_purged !~ /pass/i ) { $Log->exit() if $may_exit; $exception->throw(); } }; return { 'NACL::C::Exceptions::VserverSecurityFileDirectoryNtfs::DoesNotExist' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsDacl::DoesNotExist' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryNtfsSacl::DoesNotExist' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryPolicy::DoesNotExist' => $sub_reference, 'NACL::C::Exceptions::VserverSecurityFileDirectoryPolicyTask::DoesNotExist' => $sub_reference, }; }; } if ( $opts{nacltask_verify} ) { delete $orig_opts{'index'}; $pkg_or_obj->_generic_purge_verify(%orig_opts); } $Log->exit() if $may_exit; } ## end sub _purge_helper 1;