class AWS::EC2::PermissionCollection

Represents the collection of permissions for an EC2 resource. Each permission is a string containing the AWS account ID of a user who has permission to use the resource in question. The {Image} and {Snapshot} classes are currently the only ones that use this interface.

Public Class Methods

new(resource, opts = {}) click to toggle source

@private

Calls superclass method AWS::Core::Model.new
# File lib/aws/ec2/permission_collection.rb, line 28
def initialize(resource, opts = {})
  @resource = resource
  super(opts)
end

Public Instance Methods

add(*users) click to toggle source

Adds permissions for specific users to launch this AMI.

@param [Array of Strings] users The AWS account IDs of the

users that should be able to launch this AMI.

@return [nil]

# File lib/aws/ec2/permission_collection.rb, line 90
def add(*users)
  modify(:add, *users)
end
each() { |user_id| ... } click to toggle source

@yield [user_id] Each user ID that has explicit

permissions to launch this AMI.
# File lib/aws/ec2/permission_collection.rb, line 35
def each(&block)
  resp = client.send(describe_call, describe_params)
  resp.send(inflected_permissions_attribute).each do |permission|
    if permission[:user_id]
      user_id = permission[:user_id]
      yield(user_id)
    end
  end
end
empty?() click to toggle source

@return [Boolean] True if the collection is empty.

# File lib/aws/ec2/permission_collection.rb, line 52
def empty?
  size == 0
end
private?() click to toggle source

@return [Boolean] True if the resource is private (i.e. not

public).
# File lib/aws/ec2/permission_collection.rb, line 66
def private?
  !public?
end
public=(value) click to toggle source

Sets whether the resource is public or not. This has no effect on the explicit AWS account IDs that may already have permissions to use the resource.

@param [Boolean] value If true, the resource is made public,

otherwise the resource is made private.

@return [nil]

# File lib/aws/ec2/permission_collection.rb, line 77
def public= value
  params = value ? 
    { :add => [{ :group => "all" }] } :
    { :remove => [{ :group => "all" }] }
  client.send(modify_call, modify_params(params))
  nil
end
public?() click to toggle source

@return [Boolean] True if the resource is public.

# File lib/aws/ec2/permission_collection.rb, line 57
def public?
  resp = client.send(describe_call, describe_params)
  resp.send(inflected_permissions_attribute).any? do |permission|
    permission[:group] and permission[:group] == "all"
  end
end
remove(*users) click to toggle source

Removes permissions for specific users to launch this AMI. @param [Array of Strings] users The AWS account IDs of the

users that should no longer be able to launch this AMI.

@return [nil]

# File lib/aws/ec2/permission_collection.rb, line 98
def remove(*users)
  modify(:remove, *users)
end
reset() click to toggle source

Resets the launch permissions to their default state. @return [nil]

# File lib/aws/ec2/permission_collection.rb, line 104
def reset
  client.send(reset_call, reset_params)
end
size() click to toggle source

@return [Integer] The number of users that have explicit

permissions to launch this AMI.
# File lib/aws/ec2/permission_collection.rb, line 47
def size
  inject(0) { |sum, i| sum + 1 }
end

Private Instance Methods

describe_call() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 110
def describe_call
  "describe_#{resource_name}_attribute"
end
describe_params() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 128
def describe_params
  Hash[[["#{resource_name}_id".to_sym, @resource.send(:__resource_id__)],
        [:attribute, permissions_attribute]]]
end
Also aliased as: reset_params
inflected_permissions_attribute() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 136
def inflected_permissions_attribute
  Core::Inflection.ruby_name(permissions_attribute).to_sym
end
modify(action, *users) click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 154
def modify(action, *users)
  return if users.empty?
  opts = modify_params(Hash[[[action,
                              users.map do |user_id|
                                { :user_id => user_id }
                              end]]])
  client.send(modify_call, opts)
  nil
end
modify_call() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 116
def modify_call
  "modify_#{resource_name}_attribute"
end
modify_params(modifications) click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 166
def modify_params(modifications)
  Hash[[["#{resource_name}_id".to_sym, @resource.send(:__resource_id__)],
        [inflected_permissions_attribute, modifications]]]
end
permissions_attribute() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 142
def permissions_attribute
  @resource.__permissions_attribute__
end
reset_call() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 122
def reset_call
  "reset_#{resource_name}_attribute"
end
reset_params()
Alias for: describe_params
resource_name() click to toggle source

@private

# File lib/aws/ec2/permission_collection.rb, line 148
def resource_name
  @resource.send(:inflected_name)
end