Class: ESP::ExternalAccountCreator
- Inherits:
-
Object
- Object
- ESP::ExternalAccountCreator
- Defined in:
- lib/esp/external_account_creator.rb
Instance Attribute Summary collapse
-
#aws ⇒ Object
readonly
Returns the value of attribute aws.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize ⇒ ExternalAccountCreator
constructor
A new instance of ExternalAccountCreator.
Constructor Details
#initialize ⇒ ExternalAccountCreator
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
#aws ⇒ Object (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
#create ⇒ Object
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..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!(external_account_id) sleep 10 puts "aws_role_arn = #{aws_role_object.role.arn}, external_id = #{external_account_id}, nickname = #{team_name}, esp_suborg_id = #{sub_organization.id}, esp_team_id = #{team.id}" unless ESP.env.test? # rubocop:disable Rails/Output external_account = ESP::ExternalAccount.create(arn: aws_role_object.role.arn, external_id: external_account_id, name: team_name, sub_organization_id: sub_organization.id, team_id: team.id) fail ESP::AddExternalAccountError, "On External Account: #{external_account.errors..join(', ')}" unless external_account.errors.blank? external_account end |