Apache-Sling
view release on metacpan or search on metacpan
lib/Apache/Sling/Group.pm view on Meta::CPAN
my $heading = $column_headings[$i];
my $data = $columns[$i];
my $value = "$heading=$data";
push @properties, $value;
}
$group->add( $id, \@properties );
Apache::Sling::Print::print_result($group);
}
else {
croak 'CSV broken, failed to parse line: '
. $csv->error_input;
}
}
}
close $input or croak q{Problem closing input!};
}
else {
croak "Problem opening file: '$file'";
}
return 1;
}
#}}}
#{{{sub check_exists
sub check_exists {
my ( $group, $act_on_group ) = @_;
my $res = Apache::Sling::Request::request(
\$group,
Apache::Sling::GroupUtil::exists_setup(
$group->{'BaseURL'}, $act_on_group
)
);
my $success = Apache::Sling::GroupUtil::exists_eval($res);
my $message = "Group \"$act_on_group\" ";
$message .= ( $success ? 'exists!' : 'does not exist!' );
$group->set_results( "$message", $res );
return $success;
}
#}}}
#{{{ sub command_line
sub command_line {
my ( $group, @ARGV ) = @_;
my $sling = Apache::Sling->new;
my $config = $group->config( $sling, @ARGV );
return $group->run( $sling, $config );
}
#}}}
#{{{sub config
sub config {
my ( $group, $sling, @ARGV ) = @_;
my $group_config = $group->config_hash( $sling, @ARGV );
GetOptions(
$group_config, 'auth=s', 'help|?', 'log|L=s',
'man|M', 'pass|p=s', 'threads|t=s', 'url|U=s',
'user|u=s', 'verbose|v+', 'add|a=s', 'additions|A=s',
'delete|d=s', 'exists|e=s', 'property|P=s', 'view|V=s'
) or $group->help();
return $group_config;
}
#}}}
#{{{sub config_hash
sub config_hash {
my ( $group, $sling, @ARGV ) = @_;
my $additions;
my $add;
my $delete;
my $exists;
my @property;
my $view;
my %group_config = (
'auth' => \$sling->{'Auth'},
'help' => \$sling->{'Help'},
'log' => \$sling->{'Log'},
'man' => \$sling->{'Man'},
'pass' => \$sling->{'Pass'},
'threads' => \$sling->{'Threads'},
'url' => \$sling->{'URL'},
'user' => \$sling->{'User'},
'verbose' => \$sling->{'Verbose'},
'add' => \$add,
'additions' => \$additions,
'delete' => \$delete,
'exists' => \$exists,
'property' => \@property,
'view' => \$view
);
return \%group_config;
}
#}}}
#{{{sub del
sub del {
my ( $group, $act_on_group ) = @_;
my $res = Apache::Sling::Request::request(
\$group,
Apache::Sling::GroupUtil::delete_setup(
$group->{'BaseURL'}, $act_on_group
)
);
my $success = Apache::Sling::GroupUtil::delete_eval($res);
my $message = "Group: \"$act_on_group\" ";
$message .= ( $success ? 'deleted!' : 'was not deleted!' );
$group->set_results( "$message", $res );
return $success;
}
#}}}
#{{{ sub help
sub help {
print <<"EOF";
Usage: perl $0 [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...]
The following options are accepted:
--additions or -A (file) - file containing list of groups to be added.
--add or -a (actOnGroup) - add specified group.
--auth (type) - Specify auth type. If ommitted, default is used.
--delete or -d (actOnGroup) - delete specified group.
--exists or -e (actOnGroup) - check whether specified group exists.
--help or -? - view the script synopsis and options.
--log or -L (log) - Log script output to specified log file.
--man or -M - view the full script documentation.
--pass or -p (password) - Password of user performing actions.
--property or -P (property=value) - Specify property to set on group.
--threads or -t (threads) - Used with -A, defines number of parallel
processes to have running through file.
--url or -U (URL) - URL for system being tested against.
--user or -u (username) - Name of user to perform any actions as.
--verbose or -v or -vv or -vvv - Increase verbosity of output.
--view or -V (actOnGroup) - view details for specified group in json format.
Options may be merged together. -- stops processing of options.
Space is not required between options and their arguments.
For full details run: perl $0 --man
EOF
return 1;
}
#}}}
#{{{ sub man
sub man {
my ($group) = @_;
print <<'EOF';
group perl script. Provides a means of managing groups in sling from the
command line. The script also acts as a reference implementation for the Group
perl library.
EOF
$group->help();
print <<"EOF";
Example Usage
* Authenticate and add a group with id g-test:
perl group.pl -U http://localhost:8080 -u admin -p admin -a g-test
* Authenticate and check whether group with id g-test exists:
perl group.pl -U http://localhost:8080 -u admin -p admin -a g-test
* Authenticate and view details for group with id g-test:
perl group.pl -U http://localhost:8080 -u admin -p admin -V g-test
* Authenticate and delete group with id g-test:
perl group.pl -U http://localhost:8080 -u admin -p admin -d g-test
* Authenticate and add a group with id g-test and property p1=v1:
perl group.pl -U http://localhost:8080 -u admin -p admin -a g-test -P p1=v1
EOF
return 1;
}
#}}}
( run in 0.685 second using v1.01-cache-2.11-cpan-39bf76dae61 )