Class: BuildCloud::IAMRole
- Inherits:
-
Object
- Object
- BuildCloud::IAMRole
- Includes:
- Component
- Defined in:
- lib/build-cloud/iamrole.rb
Constant Summary collapse
- @@objects =
[]
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ IAMRole
constructor
A new instance of IAMRole.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ IAMRole
Returns a new instance of IAMRole.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/build-cloud/iamrole.rb', line 9 def initialize ( fog_interfaces, log, = {} ) @iam = fog_interfaces[:iam] @log = log = @log.debug( .inspect ) (:rolename, :assume_role_policy_document) end |
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/build-cloud/iamrole.rb', line 21 def create return if exists? @log.info( "Creating new IAM role for #{@options[:rolename]}" ) policies = .delete(:policies) # Genuinely don't think I've understood the data model with # this stuff. In particular how roles, instance profiles etc. relate # # It does what we need right now though, and can be revisited if necessary role = @iam.roles.new( ) role.save @log.debug( role.inspect ) @iam.create_instance_profile( [:rolename] ) policies.each do |policy| @log.debug( "Adding policy #{policy}" ) policy_document = JSON.parse( policy[:policy_document] ) @iam.put_role_policy( [:rolename], policy[:policy_name], policy_document ) end @iam.add_role_to_instance_profile( [:rolename], [:rolename] ) end |
#delete ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/build-cloud/iamrole.rb', line 62 def delete return unless exists? @log.info( "Deleting IAM role for #{@options[:rolename]}" ) instance_profiles = @iam.list_instance_profiles_for_role( [:rolename] ).body['InstanceProfiles'].map { |k| k['InstanceProfileName'] } instance_profiles.each do |ip| @iam.delete_instance_profile( ip ) @iam.remove_role_from_instance_profile( [:rolename], ip ) end policies = @iam.list_role_policies( [:rolename] ).body['PolicyNames'] policies.each do |policy| @iam.delete_role_policy( [:rolename], policy ) end fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
56 57 58 |
# File 'lib/build-cloud/iamrole.rb', line 56 def read @iam.roles.select { |r| r.rolename == [:rolename] }.first end |