| 1 | package VM::EC2::SecurityGroup::GroupPermission; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::SecurityGroup::GroupPermission - Object describing an authorized group within a security group firewall rule | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | $ec2 = VM::EC2->new(...); | ||
| 10 | $sg = $ec2->describe_security_groups(-name=>'My Group'); | ||
| 11 | @rules = $sg->ipPermissions; | ||
| 12 | $rule = $rules[0]; | ||
| 13 | |||
| 14 | @groups = $rule->groups; | ||
| 15 | for my $g (@groups) { | ||
| 16 | $userId = $g->userId; | ||
| 17 | $name = $g>groupName; | ||
| 18 | $id = $g->groupId; | ||
| 19 | $group_object = $g->security_group; | ||
| 20 | } | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | This object describes a security group whose instances are granted | ||
| 25 | permission to exchange data traffic with another group of | ||
| 26 | instances. It is returned by the groups() method of | ||
| 27 | L<VM::EC2::SecurityGroup::ipPermission>. | ||
| 28 | |||
| 29 | Note that this object is not the same as a bona fide | ||
| 30 | L<VM::EC2::SecurityGroup>, which has access to the group's firewall | ||
| 31 | rules. This object contains just the name, id and owner of a group | ||
| 32 | used within a firewall rule. For groups that belong to you, you can | ||
| 33 | get the full VM::EC2::SecurityGroup object by calling the | ||
| 34 | security_group() method. These details are not available to groups | ||
| 35 | that belong to other accounts. | ||
| 36 | |||
| 37 | =head1 METHODS | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | |||
| 42 | use strict; | ||
| 43 | use base 'VM::EC2::Generic'; | ||
| 44 | |||
| 45 | =head2 $id = $group->groupId | ||
| 46 | |||
| 47 | Return the group's unique ID. | ||
| 48 | |||
| 49 | =head2 $id = $group->userId | ||
| 50 | |||
| 51 | Return the account ID of the owner of this group. | ||
| 52 | |||
| 53 | =head2 $id = $group->groupName | ||
| 54 | |||
| 55 | Return this group's name. | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub valid_fields { | ||
| 60 | qw(userId groupId groupName); | ||
| 61 | } | ||
| 62 | |||
| 63 | =head2 $string = $group->short_name | ||
| 64 | |||
| 65 | Return a string for use in string overloading. See L</STRING | ||
| 66 | OVERLOADING>. | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | sub short_name { | ||
| 71 | my $self = shift; | ||
| 72 | my $name = $self->groupName or return $self->groupId; | ||
| 73 | my $userid = $self->userId; | ||
| 74 | my $ownerid= $self->ownerId; | ||
| 75 | my $gname = $userid eq $ownerid ? $name : "$userid/$name"; | ||
| 76 | return $gname; | ||
| 77 | } | ||
| 78 | |||
| 79 | =head2 $sg = $group->security_group | ||
| 80 | |||
| 81 | For groups that belong to the current account, calls | ||
| 82 | VM::EC2->describe_security_groups() to turn the group name into a | ||
| 83 | L<VM::EC2::SecurityGroup>. For groups that belong to a different | ||
| 84 | account, will return undef, since describe_security_groups() on other | ||
| 85 | accounts is not allowed by Amazon. | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | sub security_group { | ||
| 90 | my $self = shift; | ||
| 91 | my $gid = $self->groupId or return; | ||
| 92 | return $self->aws->describe_security_groups($gid); | ||
| 93 | } | ||
| 94 | |||
| 95 | sub ownerId { | ||
| 96 | my $self = shift; | ||
| 97 | my $d = $self->{ownerId}; | ||
| 98 | $self->{ownerId} = shift if @_; | ||
| 99 | $d; | ||
| 100 | } | ||
| 101 | |||
| 102 | =head1 STRING OVERLOADING | ||
| 103 | |||
| 104 | When used in a string context, this object will interpolate the user | ||
| 105 | id and group name in the form "userId/groupName" for groups that | ||
| 106 | belong to other accounts, and the groupName alone in the case of | ||
| 107 | groups that belong to you. | ||
| 108 | |||
| 109 | =head1 SEE ALSO | ||
| 110 | |||
| 111 | L<VM::EC2> | ||
| 112 | L<VM::EC2::Generic> | ||
| 113 | L<VM::EC2::SecurityGroup> | ||
| 114 | L<VM::EC2::SecurityGroup::IpPermission> | ||
| 115 | |||
| 116 | =head1 AUTHOR | ||
| 117 | |||
| 118 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 119 | |||
| 120 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 121 | |||
| 122 | This package and its accompanying libraries is free software; you can | ||
| 123 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 124 | version 1, or at your option, any later version) or the Artistic | ||
| 125 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 126 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 127 | |||
| 128 | =cut | ||
| 129 | |||
| 130 | |||
| 131 | 1; | ||
| 132 |