Class: Kybus::AWS::Policy

Inherits:
Resource show all
Defined in:
lib/kybus/aws/policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#account_id, #with_retries

Constructor Details

#initialize(config, name, body) ⇒ Policy

Returns a new instance of Policy.



8
9
10
11
12
13
# File 'lib/kybus/aws/policy.rb', line 8

def initialize(config, name, body)
  super(config)
  @name = name
  @body = body
  @iam_client = Aws::IAM::Client.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/kybus/aws/policy.rb', line 6

def name
  @name
end

Instance Method Details

#arnObject



15
16
17
# File 'lib/kybus/aws/policy.rb', line 15

def arn
  "arn:aws:iam::#{}:policy/#{name}"
end

#create_or_update!Object



19
20
21
22
23
24
# File 'lib/kybus/aws/policy.rb', line 19

def create_or_update!
  @iam_client.create_policy(policy_name: @name, policy_document: @body.to_json)
  puts "Policy '#{@name}' created."
rescue Aws::IAM::Errors::EntityAlreadyExists
  puts "Policy '#{@name}' already exists."
end

#destroy!Object



26
27
28
29
30
31
# File 'lib/kybus/aws/policy.rb', line 26

def destroy!
  @iam_client.delete_policy(policy_arn: arn)
  puts "Policy '#{@name}' deleted."
rescue Aws::IAM::Errors::NoSuchEntity
  puts "Policy '#{@name}' not found."
end