Class: Infopark::AwsUtils::Env
- Inherits:
-
Object
- Object
- Infopark::AwsUtils::Env
- Defined in:
- lib/infopark/aws_utils/env.rb
Class Method Summary collapse
Instance Method Summary collapse
- #aas ⇒ Object
- #account_type ⇒ Object
- #alb ⇒ Object
- #as ⇒ Object
- #cw ⇒ Object
- #cwl ⇒ Object
- #dev_account? ⇒ Boolean
- #ec2 ⇒ Object
- #ecr ⇒ Object
- #ecs ⇒ Object
- #find_image_by_id(id) ⇒ Object
- #find_image_by_name(name) ⇒ Object
-
#initialize(profile_name = nil) ⇒ Env
constructor
A new instance of Env.
- #latest_base_image ⇒ Object
- #prod_account? ⇒ Boolean
- #profile_name ⇒ Object
- #sts ⇒ Object
Constructor Details
#initialize(profile_name = nil) ⇒ Env
Returns a new instance of Env.
20 21 22 23 24 25 |
# File 'lib/infopark/aws_utils/env.rb', line 20 def initialize(profile_name = nil) @credentials = Aws::SharedCredentials.new(profile_name: profile_name) @clients = Hash.new do |clients, mod| clients[mod] = mod.const_get(:Client).new(credentials: @credentials, region: 'eu-west-1') end end |
Class Method Details
.profile(name) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/infopark/aws_utils/env.rb', line 10 def profile(name) env_var = "AWS_#{name.upcase}_PROFILE" profile_name = ENV[env_var] || name new(profile_name) rescue Aws::Errors::NoSuchProfileError raise "AWS profile “#{profile_name}” not found."\ " Please provide the #{name} profile via #{env_var}." end |
Instance Method Details
#aas ⇒ Object
51 52 53 |
# File 'lib/infopark/aws_utils/env.rb', line 51 def aas @clients[Aws::ApplicationAutoScaling] end |
#account_type ⇒ Object
68 69 70 71 72 |
# File 'lib/infopark/aws_utils/env.rb', line 68 def account_type return "dev" if dev_account? return "prod" if prod_account? raise "Could not determine account type." end |
#alb ⇒ Object
47 48 49 |
# File 'lib/infopark/aws_utils/env.rb', line 47 def alb @clients[Aws::ElasticLoadBalancingV2] end |
#as ⇒ Object
43 44 45 |
# File 'lib/infopark/aws_utils/env.rb', line 43 def as @clients[Aws::AutoScaling] end |
#cw ⇒ Object
55 56 57 |
# File 'lib/infopark/aws_utils/env.rb', line 55 def cw @clients[Aws::CloudWatch] end |
#cwl ⇒ Object
59 60 61 |
# File 'lib/infopark/aws_utils/env.rb', line 59 def cwl @clients[Aws::CloudWatchLogs] end |
#dev_account? ⇒ Boolean
74 75 76 |
# File 'lib/infopark/aws_utils/env.rb', line 74 def dev_account? account?(DEV_ACCOUNT_ID) end |
#ec2 ⇒ Object
39 40 41 |
# File 'lib/infopark/aws_utils/env.rb', line 39 def ec2 @clients[Aws::EC2] end |
#ecr ⇒ Object
35 36 37 |
# File 'lib/infopark/aws_utils/env.rb', line 35 def ecr @clients[Aws::ECR] end |
#ecs ⇒ Object
31 32 33 |
# File 'lib/infopark/aws_utils/env.rb', line 31 def ecs @clients[Aws::ECS] end |
#find_image_by_id(id) ⇒ Object
93 94 95 |
# File 'lib/infopark/aws_utils/env.rb', line 93 def find_image_by_id(id) AwsUtils.gather_all(ec2, :describe_images, image_ids: [id]).first end |
#find_image_by_name(name) ⇒ Object
97 98 99 100 |
# File 'lib/infopark/aws_utils/env.rb', line 97 def find_image_by_name(name) AwsUtils.gather_all(ec2, :describe_images, owners: [DEV_ACCOUNT_ID], filters: [{name: "name", values: [name]}]).first end |
#latest_base_image ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/infopark/aws_utils/env.rb', line 82 def latest_base_image available_images = AwsUtils.gather_all(ec2, :describe_images, owners: [AWS_AMI_OWNER], filters: [ {name: "root-device-type", values: ["instance-store"]}, {name: "image-type", values: ["machine"]}, {name: "virtualization-type", values: ["hvm"]}, ]).reject {|image| image.name.include?(".rc-") || image.name.include?("-minimal-") } available_images.sort_by(&:creation_date).last end |
#prod_account? ⇒ Boolean
78 79 80 |
# File 'lib/infopark/aws_utils/env.rb', line 78 def prod_account? account?(PROD_ACCOUNT_ID) end |
#profile_name ⇒ Object
27 28 29 |
# File 'lib/infopark/aws_utils/env.rb', line 27 def profile_name @credentials.profile_name end |
#sts ⇒ Object
63 64 65 |
# File 'lib/infopark/aws_utils/env.rb', line 63 def sts @clients[Aws::STS] end |