Class: Cumulus::Configuration

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/conf/Configuration.rb

Overview

Public: Contains the configuration values set in the configuration.json file. Provides a Singleton that can be accessed throughout the application.

Defined Under Namespace

Classes: AutoScalingConfig, CloudFrontConfig, EC2Config, ELBConfig, IamConfig, KinesisConfig, Route53Config, S3Config, SQSConfig, SecurityConfig, VpcConfig

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config

conf_dir, conf_dir=, json, json=

Constructor Details

#initialize(conf_dir, profile, assume_role, autoscaling_force_size, json = nil) ⇒ Configuration

Internal: Constructor. Sets up the ‘instance` variable, which is the access point for the Singleton.

json - a Hash containing the json configuration. If nil, this value will be read in from the default location conf_dir - The String path to the directory the configuration can be found in profile - The String profile name that will be used to make AWS API calls assume_role - The ARN of the role to assume when making AWS API calls autoscaling_force_size

-  Determines whether autoscaling should use configured values for
   min/max/desired group size


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/conf/Configuration.rb', line 101

def initialize(conf_dir, profile, assume_role, autoscaling_force_size, json = nil)
  Config.conf_dir = conf_dir
  Config.json = json.nil? ? JSON.parse(File.read(absolute_path("configuration.json"))) : json
  @colors_enabled = conf "colors-enabled"
  @iam = IamConfig.new
  @autoscaling = AutoScalingConfig.new(autoscaling_force_size)
  @route53 = Route53Config.new
  @security = SecurityConfig.new
  @cloudfront = CloudFrontConfig.new
  @s3 = S3Config.new
  @elb = ELBConfig.new
  @vpc = VpcConfig.new
  @kinesis = KinesisConfig.new
  @sqs = SQSConfig.new
  @ec2 = EC2Config.new

  region = conf "region"
  credentials = if assume_role
    Aws::AssumeRoleCredentials.new(
      client: Aws::STS::Client.new(profile: profile, region: region),
      role_arn: assume_role,
      role_session_name: "#{region}-#{@profile}"
    )
  end

  @client = {
    :region => region,
    :profile => profile,
    :credentials => credentials,
    :stub_responses => conf("stub_aws_responses", true)
  }.reject { |_, v| v.nil? }
end

Instance Attribute Details

#autoscalingObject (readonly)

Returns the value of attribute autoscaling.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def autoscaling
  @autoscaling
end

#clientObject (readonly)

Returns the value of attribute client.



89
90
91
# File 'lib/conf/Configuration.rb', line 89

def client
  @client
end

#cloudfrontObject (readonly)

Returns the value of attribute cloudfront.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def cloudfront
  @cloudfront
end

#colors_enabledObject (readonly)

Returns the value of attribute colors_enabled.



87
88
89
# File 'lib/conf/Configuration.rb', line 87

def colors_enabled
  @colors_enabled
end

#ec2Object (readonly)

Returns the value of attribute ec2.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def ec2
  @ec2
end

#elbObject (readonly)

Returns the value of attribute elb.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def elb
  @elb
end

#iamObject (readonly)

Returns the value of attribute iam.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def iam
  @iam
end

#kinesisObject (readonly)

Returns the value of attribute kinesis.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def kinesis
  @kinesis
end

#route53Object (readonly)

Returns the value of attribute route53.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def route53
  @route53
end

#s3Object (readonly)

Returns the value of attribute s3.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def s3
  @s3
end

#securityObject (readonly)

Returns the value of attribute security.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def security
  @security
end

#sqsObject (readonly)

Returns the value of attribute sqs.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def sqs
  @sqs
end

#vpcObject (readonly)

Returns the value of attribute vpc.



88
89
90
# File 'lib/conf/Configuration.rb', line 88

def vpc
  @vpc
end

Class Method Details

.init(conf_dir, profile, assume_role, autoscaling_force_size) ⇒ Object

Public: Initialize the Configuration Singleton. Must be called before any access to ‘Configuration.instance` is used.

conf_dir - The String path to the directory the configuration can be found in profile - The String profile name that will be used to make AWS API calls assume_role - The ARN of the role to assume when making AWS API calls autoscaling_force_size

-  Determines whether autoscaling should use configured values for
   min/max/desired group size


144
145
146
# File 'lib/conf/Configuration.rb', line 144

def init(conf_dir, profile, assume_role, autoscaling_force_size)
  @@instance = new(conf_dir, profile, assume_role, autoscaling_force_size)
end

.init_from_hash(json, conf_dir, profile, assume_role, autoscaling_force_size) ⇒ Object

Private: Initialize the Configuration Singleton. Must be called before any access to ‘Configuration.instance` is used. Used by the tests to pass in json rather than a file

json - the Hash containing the json configuration conf_dir - The String path to the directory the configuration can be found in profile - The String profile name that will be used to make AWS API calls assume_role - The ARN of the role to assume when making AWS API calls autoscaling_force_size

-  Determines whether autoscaling should use configured values for
   min/max/desired group size


159
160
161
# File 'lib/conf/Configuration.rb', line 159

def init_from_hash(json, conf_dir, profile, assume_role, autoscaling_force_size)
  @@instance = new(conf_dir, profile, assume_role, autoscaling_force_size, json)
end

.instanceObject

Public: The Singleton instance of Configuration.

Returns the Configuration instance.



166
167
168
# File 'lib/conf/Configuration.rb', line 166

def instance
  @@instance
end