Class: AWS::EC2::PermissionCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aws/ec2/permission_collection.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#add(*users) ⇒ nil

Adds permissions for specific users to launch this AMI.

Parameters:

  • users (Array of Strings)

    The AWS account IDs of the users that should be able to launch this AMI.

Returns:

  • (nil)


90
91
92
# File 'lib/aws/ec2/permission_collection.rb', line 90

def add(*users)
  modify(:add, *users)
end

#each {|user_id| ... } ⇒ Object

Yields:

  • (user_id)

    Each user ID that has explicit permissions to launch this AMI.



35
36
37
38
39
40
41
42
43
# 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?Boolean

Returns True if the collection is empty.

Returns:

  • (Boolean)

    True if the collection is empty.



52
53
54
# File 'lib/aws/ec2/permission_collection.rb', line 52

def empty?
  size == 0
end

#private?Boolean

Returns True if the resource is private (i.e. not public).

Returns:

  • (Boolean)

    True if the resource is private (i.e. not public).



66
67
68
# File 'lib/aws/ec2/permission_collection.rb', line 66

def private?
  !public?
end

#public=(value) ⇒ nil

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.

Parameters:

  • value (Boolean)

    If true, the resource is made public, otherwise the resource is made private.

Returns:

  • (nil)


77
78
79
80
81
82
83
# 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?Boolean

Returns True if the resource is public.

Returns:

  • (Boolean)

    True if the resource is public.



57
58
59
60
61
62
# 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) ⇒ nil

Removes permissions for specific users to launch this AMI.

Parameters:

  • users (Array of Strings)

    The AWS account IDs of the users that should no longer be able to launch this AMI.

Returns:

  • (nil)


98
99
100
# File 'lib/aws/ec2/permission_collection.rb', line 98

def remove(*users)
  modify(:remove, *users)
end

#resetnil

Resets the launch permissions to their default state.

Returns:

  • (nil)


104
105
106
# File 'lib/aws/ec2/permission_collection.rb', line 104

def reset
  client.send(reset_call, reset_params)
end

#sizeInteger

Returns The number of users that have explicit permissions to launch this AMI.

Returns:

  • (Integer)

    The number of users that have explicit permissions to launch this AMI.



47
48
49
# File 'lib/aws/ec2/permission_collection.rb', line 47

def size
  inject(0) { |sum, i| sum + 1 }
end