Class: ESP::ExternalAccountCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/esp/external_account_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExternalAccountCreator

Returns a new instance of ExternalAccountCreator.



26
27
28
# File 'lib/esp/external_account_creator.rb', line 26

def initialize
  @aws = AWSClients.new
end

Instance Attribute Details

#awsObject (readonly)

Returns the value of attribute aws.



24
25
26
# File 'lib/esp/external_account_creator.rb', line 24

def aws
  @aws
end

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/esp/external_account_creator.rb', line 30

def create
  fail ESP::AddExternalAccountError, aws.errors.full_messages.join(', ') unless aws.valid?

  puts "adding AWS account #{aws.owner_id} to ESP as #{team_name}" unless ESP.env.test? # rubocop:disable Rails/Output
  aws_role_object = aws.create_and_attach_role!()
  sleep 10

  puts "aws_role_arn = #{aws_role_object.role.arn}, external_id = #{}, nickname = #{team_name}, esp_suborg_id = #{sub_organization.id}, esp_team_id = #{team.id}" unless ESP.env.test? # rubocop:disable Rails/Output
   = ESP::ExternalAccount.create(arn: aws_role_object.role.arn, external_id: , name: team_name, sub_organization_id: sub_organization.id, team_id: team.id)
  fail ESP::AddExternalAccountError, "On External Account: #{.errors.full_messages.join(', ')}" unless .errors.blank?
  
end