Class: Piculet::EC2Wrapper::SecurityGroupCollection::SecurityGroup::PermissionCollection
- Inherits:
-
Object
- Object
- Piculet::EC2Wrapper::SecurityGroupCollection::SecurityGroup::PermissionCollection
- Includes:
- Logger::ClientHelper
- Defined in:
- lib/piculet/wrapper/permission.rb,
lib/piculet/wrapper/permission-collection.rb
Defined Under Namespace
Classes: Permission
Instance Method Summary collapse
- #authorize(protocol, ports, sources, opts = {}) ⇒ Object
- #create(protocol, port_range, dsl) ⇒ Object
- #each ⇒ Object
-
#initialize(security_group, direction, options) ⇒ PermissionCollection
constructor
A new instance of PermissionCollection.
- #log_id ⇒ Object
- #revoke(protocol, ports, sources, opts = {}) ⇒ Object
Methods included from Logger::ClientHelper
Constructor Details
#initialize(security_group, direction, options) ⇒ PermissionCollection
Returns a new instance of PermissionCollection.
8 9 10 11 12 13 |
# File 'lib/piculet/wrapper/permission-collection.rb', line 8 def initialize(security_group, direction, ) @security_group = security_group = security_group.send("#{direction}_ip_permissions") @direction = direction = end |
Instance Method Details
#authorize(protocol, ports, sources, opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/piculet/wrapper/permission-collection.rb', line 23 def (protocol, ports, sources, opts = {}) log(:info, " authorize #{format_sources(sources)}", opts.fetch(:log_color, :green)) unless .dry_run sources = normalize_sources(sources) case @direction when :ingress @security_group.(protocol, ports, *sources) .updated = true when :egress sources.push(:protocol => protocol, :ports => ports) @security_group.(*sources) .updated = true end end end |
#create(protocol, port_range, dsl) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/piculet/wrapper/permission-collection.rb', line 59 def create(protocol, port_range, dsl) dsl_ip_ranges = dsl.ip_ranges || [] dsl_groups = (dsl.groups || []).map do |i| i.kind_of?(Array) ? i : [.ec2.owner_id, i] end sources = dsl_ip_ranges + dsl_groups unless sources.empty? log(:info, 'Create Permission', :cyan, "#{log_id} > #{protocol} #{port_range}") (protocol, port_range, sources, :log_color => :cyan) end end |
#each ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/piculet/wrapper/permission-collection.rb', line 15 def each perm_list = ? .aggregate : [] perm_list.each do |perm| yield(Permission.new(perm, self, )) end end |
#log_id ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/piculet/wrapper/permission-collection.rb', line 73 def log_id vpc = @security_group.vpc_id || :classic name = @security_group.name if @security_group.owner_id and not .ec2.own?(@security_group.owner_id) name = "#{@security_group.owner_id}/#{name}" end "#{vpc} > #{name}(#{@direction})" end |
#revoke(protocol, ports, sources, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/piculet/wrapper/permission-collection.rb', line 41 def revoke(protocol, ports, sources, opts = {}) log(:info, " revoke #{format_sources(sources)}", opts.fetch(:log_color, :green)) unless .dry_run sources = normalize_sources(sources) case @direction when :ingress @security_group.revoke_ingress(protocol, ports, *sources) .updated = true when :egress sources.push(:protocol => protocol, :ports => ports) @security_group.revoke_egress(*sources) .updated = true end end end |