Class: Dev::Template::Aws

Inherits:
BaseInterface show all
Defined in:
lib/firespring_dev_commands/templates/aws.rb,
lib/firespring_dev_commands/templates/ci.rb,
lib/firespring_dev_commands/templates/aws/services/route53.rb

Overview

Class contains rake templates for managing your AWS settings and logging in

Defined Under Namespace

Modules: Services Classes: Ci

Instance Attribute Summary

Attributes inherited from BaseInterface

#exclude

Instance Method Summary collapse

Methods inherited from BaseInterface

#create_tasks!, #initialize

Constructor Details

This class inherits a constructor from Dev::Template::BaseInterface

Instance Method Details

#create_ensure_credentials_task!Object

Create the rake task which ensures active credentials are present



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/firespring_dev_commands/templates/aws.rb', line 8

def create_ensure_credentials_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    return if exclude.include?(:ensure_aws_credentials)

    task ensure_aws_credentials: %w(init) do
      raise 'AWS Credentials not found / expired' unless Dev::Aws::Credentials.new.active?
    end
  end
end

#create_eol_task!Object

Create the rake task for the eol method



98
99
100
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
# File 'lib/firespring_dev_commands/templates/aws.rb', line 98

def create_eol_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    return if exclude.include?(:eol)

    task eol: [:'eol:aws'] do
      # This is just a placeholder to execute the dependencies
    end

    namespace :eol do
      desc 'Compares the current date to the EOL date for supported aws resources'
      task aws: %w(init ensure_aws_credentials) do
        next if ENV.fetch('CHECK_AWS', nil).to_s.strip == 'false'

        aws_products = Dev::EndOfLife::Aws.new.default_products
        next if aws_products.empty?

        puts
         = Dev::Aws::Profile.new.current
         = Dev::Aws::.new.()
        puts "AWS product versions (in account #{account_name} / #{account_id})".light_yellow
        Dev::EndOfLife.new(product_versions: aws_products).status
      end
    end
  end
end

#create_login_task!Object

rubocop:disable Metrics/MethodLength Create the rake task for the aws credentials setup and login method



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/firespring_dev_commands/templates/aws.rb', line 54

def 
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :aws do
      return if exclude.include?(:login)

      namespace :configure do
        desc 'Configure the default AWS login settings'
        task default: %w(init default:credentials default:config) do
          puts
        end

        namespace :default do
          desc 'Configure the default AWS login credentials' \
               "\n\t(primarily used for rotating access keys)"
          task credentials: %w(init) do
            Dev::Aws::Credentials.new.base_setup!
          end

          task config: %w(init) do
            Dev::Aws::.new.base_setup!
          end
        end

        Dev::Aws::.new.children.each do ||
          desc "Configure the #{account.name} account login settings"
          task .id => %w(init) do
            Dev::Aws::.new.setup!(.id)
          end
        end
      end

      desc 'Select the account you wish to log in to'
      task login: %w(init) do
        Dev::Aws::.new.login!
      end
    end
  end
end

#create_profile_task!Object

Create the rake task for the aws profile method



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/firespring_dev_commands/templates/aws.rb', line 22

def create_profile_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :aws do
      return if exclude.include?(:profile)

      desc 'Show the current profile/aws account you are configured to use'
      task profile: %w(init) do
        Dev::Aws::Profile.new.info
      end

      namespace :profile do
        desc 'Return the commands to export your AWS credentials into your environment'
        task :export do
          # Turn off all logging except for errors
          LOG.level = Logger::ERROR

          # Run the init
          Rake::Task[:init].invoke

          # Print the export info
          Dev::Aws::Profile.new.export_info
        end
      end
    end
  end
end