Class: DrawCloud::IAMPolicy

Inherits:
Base
  • Object
show all
Defined in:
lib/draw_cloud/iam_policy.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#as_groups, #as_launch_configurations, #deletion_policy, #depends_on, #ec2_instances, #elastic_ips, #gateways, #iam_access_keys, #iam_policies, #iam_users, #mappings, #metadata, #network_acls, #network_interfaces, #outputs, #parameters, #parent, #rdses, #resources, #route_tables, #security_groups, #sns_topics, #subnets, #vpcs, #wait_handles

Instance Method Summary collapse

Methods inherited from Base

#[], #accessor, #add_standard_properties, #create_as_group, #create_as_launch_configuration, #create_ec2_instance, #create_ec2_instance_template, #create_elastic_ip, #create_iam_access_key, #create_iam_policy, #create_iam_user, #create_mapping, #create_network_acl, #create_network_interface, #create_output, #create_parameter, #create_rds, #create_route_table, #create_security_group, #create_service, #create_sns_topic, #create_subnet, #create_vpc, #create_wait_handle, #ref, #resource_name

Methods included from Locations

#arn_s3

Methods included from Utilities

#desplice, #fnbase64, #fngetatt, #fnjoin, #hash_to_tag_array, #region, #resource_style, #splice, #stack_name

Constructor Details

#initialize(name, options = {}, &block) ⇒ IAMPolicy

Returns a new instance of IAMPolicy.



25
26
27
28
29
30
31
# File 'lib/draw_cloud/iam_policy.rb', line 25

def initialize(name, options={}, &block)
  @name = name
  @groups = []
  @users = []
  @statements = []
  super(options, &block)
end

Instance Attribute Details

#groupsObject

Returns the value of attribute groups.



21
22
23
# File 'lib/draw_cloud/iam_policy.rb', line 21

def groups
  @groups
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/draw_cloud/iam_policy.rb', line 21

def name
  @name
end

#policy_documentObject Also known as: document

Returns the value of attribute policy_document.



21
22
23
# File 'lib/draw_cloud/iam_policy.rb', line 21

def policy_document
  @policy_document
end

#statementsObject

Returns the value of attribute statements.



21
22
23
# File 'lib/draw_cloud/iam_policy.rb', line 21

def statements
  @statements
end

#usersObject

Returns the value of attribute users.



21
22
23
# File 'lib/draw_cloud/iam_policy.rb', line 21

def users
  @users
end

Instance Method Details

#allow(statement_properties = {}) ⇒ Object



37
38
39
# File 'lib/draw_cloud/iam_policy.rb', line 37

def allow(statement_properties={})
  @statements << resourcify_statement_property(statement_properties.merge(:effect => "Allow"))
end

#deny(statement_properties = {}) ⇒ Object



41
42
43
# File 'lib/draw_cloud/iam_policy.rb', line 41

def deny(statement_properties={})
  @statements << resourcify_statement_property(statement_properties.merge(:effect => "Deny"))
end

#iam_policyObject



33
34
35
# File 'lib/draw_cloud/iam_policy.rb', line 33

def iam_policy
  self
end

#load_into_config(config) ⇒ Object



49
50
51
52
# File 'lib/draw_cloud/iam_policy.rb', line 49

def load_into_config(config)
  config.cf_add_resource resource_name, self
  super(config)
end

#resourcify_statement_property(hash) ⇒ Object



45
46
47
# File 'lib/draw_cloud/iam_policy.rb', line 45

def resourcify_statement_property(hash)
  hash.each_with_object({}) {|(k,v),x| x[DrawCloud.resource_style(k)] = v }
end

#to_hObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/draw_cloud/iam_policy.rb', line 54

def to_h
  h = {
    "Type" => "AWS::IAM::Policy",
    "Properties" => {
      "PolicyName" => resource_name,
      "PolicyDocument" => {
        "Statement" => @statements.collect do |s|
          DrawCloud.ref(s)
        end
      }
    }
  }
  h["Properties"]["Groups"] = groups.collect {|g| DrawCloud.ref(g)} if (groups && !groups.empty?)
  h["Properties"]["Users"] = users.collect {|u| DrawCloud.ref(u)} if (users && !users.empty?)
  add_standard_properties(h)
end