Module: AwsConfiguration

Extended by:
ActiveSupport::Concern
Defined in:
lib/app/models/concerns/aws_configuration.rb

Overview

AWS Configuration

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/app/models/concerns/aws_configuration.rb', line 9

def self.included(base)
  base.class_eval do
    #
    # Fields
    #
    field :aws_region, type: String
    field :aws_access_key_id, type: String
    field :aws_secret_access_key, type: String
    field :aws_auto_scaling_group_name, type: String
    field :aws_bucket_name, type: String
  end
end

Instance Method Details

#aws_auto_scaling_configured?Boolean

Determine if auto scaling group is configured

Returns:

  • (Boolean)


39
40
41
# File 'lib/app/models/concerns/aws_configuration.rb', line 39

def aws_auto_scaling_configured?
  aws_configured? && aws_auto_scaling_group_name.present?
end

#aws_configured?Boolean

Determine if AWS is configured

Returns:

  • (Boolean)


32
33
34
# File 'lib/app/models/concerns/aws_configuration.rb', line 32

def aws_configured?
  [aws_region.present?, aws_access_key_id.present?, aws_secret_access_key.present?].all?
end

#aws_ec2_clientObject

AWS client.



46
47
48
49
50
51
52
# File 'lib/app/models/concerns/aws_configuration.rb', line 46

def aws_ec2_client
  return nil unless aws_configured?

  @aws_ec2_client ||= Aws::EC2::Client.new(region: aws_region,
                                           credentials: Aws::Credentials.new(aws_access_key_id,
                                                                             aws_secret_access_key))
end

#aws_s3_clientObject

S3 Client



57
58
59
60
61
62
63
64
65
# File 'lib/app/models/concerns/aws_configuration.rb', line 57

def aws_s3_client
  return nil unless aws_configured?

  # We want this to remake itself each time because it is possible that the
  # => user would change the access keys in between actions. Huh?
  @aws_s3_client ||= Aws::S3::Client.new(region: aws_region,
                                         access_key_id: aws_access_key_id,
                                         secret_access_key: aws_secret_access_key)
end

#secure_fieldsObject

Make sure the password doesn’t get blanked out on an update



25
26
27
# File 'lib/app/models/concerns/aws_configuration.rb', line 25

def secure_fields
  super + %i[aws_secret_access_key]
end