| 1 | #!/usr/bin/perl -w | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package Sakai::Nakamura::GroupMember; | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | ▶ | use 5.008008; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Getopt::Long qw(:config bundling); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use Sakai::Nakamura; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Sakai::Nakamura::Authn; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use Sakai::Nakamura::GroupMemberUtil; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 1 | require Exporter; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 1 | ▶ | use base qw(Exporter); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 1 | our @EXPORT_OK = (); | |||||||||||||
| 19 | |||||||||||||||
| 20 | 1 | our $VERSION = '0.13'; | |||||||||||||
| 21 | |||||||||||||||
| 22 | #{{{sub new | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||
| 25 | 1 | my ( $class, $authn, $verbose, $log ) = @_; | |||||||||||||
| 26 | 0 | ▶ | if ( !defined $authn ) { croak 'no authn provided!'; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 1 | my $response; | |||||||||||||
| 28 | 1 | ▶ | $verbose = ( defined $verbose ? $verbose : 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | my $group_member = { | ||||||||||||||
| 30 | 1 | BaseURL => ${$authn}->{'BaseURL'}, | |||||||||||||
| 31 | Authn => $authn, | ||||||||||||||
| 32 | Message => q{}, | ||||||||||||||
| 33 | Response => \$response, | ||||||||||||||
| 34 | Verbose => $verbose, | ||||||||||||||
| 35 | Log => $log | ||||||||||||||
| 36 | }; | ||||||||||||||
| 37 | 1 | bless $group_member, $class; | |||||||||||||
| 38 | 1 | return $group_member; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | #}}} | ||||||||||||||
| 42 | |||||||||||||||
| 43 | #{{{sub set_results | ||||||||||||||
| 44 | 1 | ▶ | sub set_results { | ||||||||||||
|
Subroutine
set_results: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 45 | 1 | my ( $group, $message, $response ) = @_; | |||||||||||||
| 46 | 1 | $group->{'Message'} = $message; | |||||||||||||
| 47 | 1 | $group->{'Response'} = $response; | |||||||||||||
| 48 | 1 | return 1; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | #}}} | ||||||||||||||
| 52 | |||||||||||||||
| 53 | #{{{sub add | ||||||||||||||
| 54 | 0 | ▶ | sub add { | ||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 55 | 0 | my ( $group, $act_on_group, $act_on_role, $add_member ) = @_; | |||||||||||||
| 56 | my $res = Apache::Sling::Request::request( | ||||||||||||||
| 57 | \$group, | ||||||||||||||
| 58 | Sakai::Nakamura::GroupMemberUtil::add_setup( | ||||||||||||||
| 59 | 0 | $group->{'BaseURL'}, $act_on_group, $act_on_role, $add_member | |||||||||||||
| 60 | ) | ||||||||||||||
| 61 | ); | ||||||||||||||
| 62 | 0 | my $success = Sakai::Nakamura::GroupMemberUtil::add_eval($res); | |||||||||||||
| 63 | 0 | my $message = "Member: \"$add_member\" "; | |||||||||||||
| 64 | 0 | ▶ | $message .= ( $success ? 'added' : 'was not added' ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 0 | $message .= " to role \"$act_on_role\" in group \"$act_on_group\"!"; | |||||||||||||
| 66 | 0 | $group->set_results( "$message", $res ); | |||||||||||||
| 67 | 0 | return $success; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | #}}} | ||||||||||||||
| 71 | |||||||||||||||
| 72 | #{{{sub add_from_file | ||||||||||||||
| 73 | 0 | ▶ | sub add_from_file { | ||||||||||||
|
Subroutine
add_from_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 74 | |||||||||||||||
| 75 | # TODO implement | ||||||||||||||
| 76 | 0 | return 1; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | #}}} | ||||||||||||||
| 80 | |||||||||||||||
| 81 | #{{{sub check_exists | ||||||||||||||
| 82 | 0 | ▶ | sub check_exists { | ||||||||||||
|
Subroutine
check_exists: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 83 | |||||||||||||||
| 84 | # TODO implement | ||||||||||||||
| 85 | 0 | return 1; | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | #}}} | ||||||||||||||
| 89 | |||||||||||||||
| 90 | #{{{ sub command_line | ||||||||||||||
| 91 | 0 | ▶ | sub command_line { | ||||||||||||
|
Subroutine
command_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 92 | 0 | my ( $class, @ARGV ) = @_; | |||||||||||||
| 93 | 0 | my $nakamura = Sakai::Nakamura->new; | |||||||||||||
| 94 | 0 | my $config = $class->config( $nakamura, @ARGV ); | |||||||||||||
| 95 | 0 | my $authn = new Sakai::Nakamura::Authn( \$nakamura ); | |||||||||||||
| 96 | 0 | return $class->run( $nakamura, $config ); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | |||||||||||||||
| 99 | #}}} | ||||||||||||||
| 100 | |||||||||||||||
| 101 | #{{{sub config | ||||||||||||||
| 102 | # TODO add config options: | ||||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | ▶ | sub config { | ||||||||||||
|
Subroutine
config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 105 | 0 | my ( $class, $nakamura, @ARGV ) = @_; | |||||||||||||
| 106 | 0 | my $group_member_config = $class->config_hash( $nakamura, @ARGV ); | |||||||||||||
| 107 | |||||||||||||||
| 108 | 0 | ▶ | GetOptions( $group_member_config ) or $class->help(); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | |||||||||||||||
| 110 | 0 | return $group_member_config; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | #}}} | ||||||||||||||
| 114 | |||||||||||||||
| 115 | #{{{sub config_hash | ||||||||||||||
| 116 | # TODO add config options: | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | ▶ | sub config_hash { | ||||||||||||
|
Subroutine
config_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 119 | 0 | my ( $class, $nakamura, @ARGV ) = @_; | |||||||||||||
| 120 | 0 | my %group_member_config = (); | |||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | return \%group_member_config; | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | #}}} | ||||||||||||||
| 126 | |||||||||||||||
| 127 | #{{{sub del | ||||||||||||||
| 128 | 0 | ▶ | sub del { | ||||||||||||
|
Subroutine
del: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 129 | |||||||||||||||
| 130 | # TODO implement | ||||||||||||||
| 131 | 0 | return 1; | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | |||||||||||||||
| 134 | #}}} | ||||||||||||||
| 135 | |||||||||||||||
| 136 | #{{{ sub help | ||||||||||||||
| 137 | 0 | ▶ | sub help { | ||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 138 | |||||||||||||||
| 139 | # TODO: implement | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | print <<"EOF"; | |||||||||||||
| 142 | Usage: perl $0 [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...] | ||||||||||||||
| 143 | The following options are accepted: | ||||||||||||||
| 144 | |||||||||||||||
| 145 | Options may be merged together. -- stops processing of options. | ||||||||||||||
| 146 | Space is not required between options and their arguments. | ||||||||||||||
| 147 | For full details run: perl $0 --man | ||||||||||||||
| 148 | EOF | ||||||||||||||
| 149 | |||||||||||||||
| 150 | 0 | return 1; | |||||||||||||
| 151 | } | ||||||||||||||
| 152 | |||||||||||||||
| 153 | #}}} | ||||||||||||||
| 154 | |||||||||||||||
| 155 | #{{{ sub man | ||||||||||||||
| 156 | 0 | ▶ | sub man { | ||||||||||||
|
Subroutine
man: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 157 | |||||||||||||||
| 158 | # TODO: implement | ||||||||||||||
| 159 | 0 | my ($group_member) = @_; | |||||||||||||
| 160 | |||||||||||||||
| 161 | 0 | print <<'EOF'; | |||||||||||||
| 162 | group membership perl script. Provides a means of managing role members in nakamura from the command | ||||||||||||||
| 163 | line. The script also acts as a reference implementation for the Group Member perl | ||||||||||||||
| 164 | library. | ||||||||||||||
| 165 | |||||||||||||||
| 166 | EOF | ||||||||||||||
| 167 | |||||||||||||||
| 168 | 0 | $group_member->help(); | |||||||||||||
| 169 | |||||||||||||||
| 170 | 0 | print <<"EOF"; | |||||||||||||
| 171 | Example Usage | ||||||||||||||
| 172 | |||||||||||||||
| 173 | * TODO: add examples | ||||||||||||||
| 174 | |||||||||||||||
| 175 | perl $0 -U http://localhost:8080 -u admin -p admin | ||||||||||||||
| 176 | EOF | ||||||||||||||
| 177 | |||||||||||||||
| 178 | 0 | return 1; | |||||||||||||
| 179 | } | ||||||||||||||
| 180 | |||||||||||||||
| 181 | #}}} | ||||||||||||||
| 182 | |||||||||||||||
| 183 | #{{{sub run | ||||||||||||||
| 184 | 0 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 185 | 0 | my ( $group_member, $nakamura, $config ) = @_; | |||||||||||||
| 186 | 0 | ▶ | if ( !defined $config ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 187 | 0 | croak 'No group member config supplied!'; | |||||||||||||
| 188 | } | ||||||||||||||
| 189 | 0 | $nakamura->check_forks; | |||||||||||||
| 190 | my $authn = | ||||||||||||||
| 191 | defined $nakamura->{'Authn'} | ||||||||||||||
| 192 | 0 | ▶ | ? ${ $nakamura->{'Authn'} } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 193 | : new Sakai::Nakamura::Authn( \$nakamura ); | ||||||||||||||
| 194 | |||||||||||||||
| 195 | 0 | my $success = 1; | |||||||||||||
| 196 | |||||||||||||||
| 197 | 0 | ▶ | if ( $nakamura->{'Help'} ) { $group_member->help(); } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 198 | 0 | elsif ( $nakamura->{'Man'} ) { $group_member->man(); } | |||||||||||||
| 199 | |||||||||||||||
| 200 | # TODO: implement | ||||||||||||||
| 201 | |||||||||||||||
| 202 | 0 | return $success; | |||||||||||||
| 203 | } | ||||||||||||||
| 204 | |||||||||||||||
| 205 | #}}} | ||||||||||||||
| 206 | |||||||||||||||
| 207 | #{{{sub view | ||||||||||||||
| 208 | 0 | ▶ | sub view { | ||||||||||||
|
Subroutine
view: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 209 | |||||||||||||||
| 210 | # TODO implement | ||||||||||||||
| 211 | 0 | return 1; | |||||||||||||
| 212 | } | ||||||||||||||
| 213 | |||||||||||||||
| 214 | #}}} | ||||||||||||||
| 215 | |||||||||||||||
| 216 | 1 | 1; | |||||||||||||
| 217 | |||||||||||||||
| 218 | __END__ | ||||||||||||||