domed-city 1.6.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d8f26172301e9ca28b6ccac2be14bf9f05ef973
4
- data.tar.gz: c38ca8ff67f62909d5414d02650ea71473eac0ed
3
+ metadata.gz: ed66b624e303da572cb9b8373540c31f87025733
4
+ data.tar.gz: 3c4439e4ede3d703dc60b0098e5cfabd0a6e5a4b
5
5
  SHA512:
6
- metadata.gz: d01788ccba53d666fd49d9d703ff0cfa7848f546dcd3958b700c3b4b40e5ac78a98bb3928f883869a2786c69fabca65e14c5feddb08512eb92b146acb73d507d
7
- data.tar.gz: 55dfde32d29864e0e863ba3d6a66f1d0b4ba9030daf10b40ece824f8ba0937e3dd3ff95604f411978d7d43dcba4c26dff1f185263b24213b0ff0ffc0366b9888
6
+ metadata.gz: 90f0c2c2db637fd0946a507a8434990e37d44b6e6e103aa7eec7d89cd006a5647b4da252da6279eefab99132323b9b54fa1a5210ebe6416c37ac58f79649ab33
7
+ data.tar.gz: e9e87383b69a2e7bf938fb6ee3cac144e3219b8ab429e3b02e7625dd2295f06206dc482099e35e7fde51b377b3e4ef0cda76fdda072001f7342e2f6e1c2fe5d5
data/bin/dome CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'dome'
4
+ require_relative '../lib/dome'
5
5
 
6
6
  opts = Trollop.options do
7
7
  version Dome::VERSION
@@ -3,7 +3,9 @@ require 'aws-sdk'
3
3
  require 'colorize'
4
4
  require 'aws/profile_parser'
5
5
  require 'fileutils'
6
+ require 'yaml'
6
7
 
8
+ require 'dome/settings'
7
9
  require 'dome/version'
8
10
  require 'dome/helpers/shell'
9
11
  require 'dome/environment'
@@ -1,26 +1,23 @@
1
1
  module Dome
2
2
  class Environment
3
- attr_reader :environment, :account
3
+ attr_reader :environment, :account, :settings
4
4
 
5
5
  def initialize(directories = Dir.pwd.split('/'))
6
6
  @environment = directories[-1]
7
7
  @account = directories[-2]
8
+ @settings = Dome::Settings.new
8
9
  end
9
10
 
10
11
  def team
11
- @account.split('-').first
12
+ @settings.parse['project']
12
13
  end
13
14
 
14
15
  def accounts
15
16
  %W(#{team}-dev #{team}-prd)
16
17
  end
17
18
 
18
- def non_production_environments
19
- %w(infradev dev sit qa qa1 qa2 stg)
20
- end
21
-
22
- def production_environments
23
- %w(infraprd prd)
19
+ def environments
20
+ @settings.parse['environments']
24
21
  end
25
22
 
26
23
  def aws_credentials
@@ -40,38 +37,42 @@ module Dome
40
37
  accounts.include? account_name
41
38
  end
42
39
 
43
- def valid_environment?(account_name, environment_name)
40
+ def valid_environment?(environment_name)
44
41
  puts "Environment: #{environment_name.colorize(:green)}"
45
- if account_name.split('-')[1] == 'dev'
46
- non_production_environments.include? environment_name
47
- else
48
- production_environments.include? environment_name
49
- end
42
+ environments.include? environment_name
50
43
  end
51
44
 
52
45
  def invalid_account_message
53
46
  puts "\n'#{@account}' is not a valid account.\n".colorize(:red)
54
- puts "The 'account' and 'environment' variables are assigned based on your current directory.\n".colorize(:red)
55
- puts "The expected directory structure is '.../<account>/<environment>'\n".colorize(:red)
56
- puts "Valid accounts are: #{accounts}."
57
- puts "\nEither:"
58
- puts '1. Set your .aws/config to one of the valid accounts above.'
59
- puts '2. Ensure you are running this from the correct directory.'
47
+ generic_error_message
60
48
  exit 1
61
49
  end
62
50
 
63
51
  def invalid_environment_message
64
- puts "\n'#{@environment}' is not a valid environment for the account: '#{@account}'.\n".colorize(:red)
52
+ puts "\n'#{@environment}' is not a valid environment.\n".colorize(:red)
53
+ generic_error_message
54
+ exit 1
55
+ end
56
+
57
+ private
58
+
59
+ # rubocop:disable Metrics/MethodLength
60
+ # rubocop:disable Metrics/AbcSize
61
+ def generic_error_message
65
62
  puts "The 'account' and 'environment' variables are assigned based on your current directory.\n".colorize(:red)
66
63
  puts "The expected directory structure is '.../<account>/<environment>'\n".colorize(:red)
67
-
68
- env = if account[-4..-1] == '-dev'
69
- non_production_environments
70
- else
71
- production_environments
72
- end
73
- puts "Valid environments are: #{env}."
74
- exit 1
64
+ puts '============================================================================='
65
+ puts "Valid environments are defined using the 'environments' key in your itv.yaml."
66
+ puts "The environments you have defined are: #{environments}."
67
+ puts '============================================================================='
68
+ puts 'Valid accounts are of the format <project>-dev/prd and <project>-prd' \
69
+ " (where 'project' is defined using the 'project' key in your itv.yaml."
70
+ puts "The accounts you have defined are: #{accounts}."
71
+ puts '============================================================================='
72
+ puts 'To fix your issue, try the following:'
73
+ puts '1. Set your .aws/config to one of the valid accounts above.'
74
+ puts '2. Ensure you are running this from the correct directory.'
75
+ puts '3. Update your itv.yaml with the required environments or project.'
75
76
  end
76
77
  end
77
78
  end
@@ -0,0 +1,16 @@
1
+ module Dome
2
+ class Settings
3
+ def parse
4
+ raise('[*] itv.yaml does not exist') unless File.exist? itv_yaml_path
5
+ load_yaml
6
+ end
7
+
8
+ def load_yaml
9
+ @parsed_yaml ||= YAML.load_file(itv_yaml_path)
10
+ end
11
+
12
+ def itv_yaml_path
13
+ '../../../itv.yaml'
14
+ end
15
+ end
16
+ end
@@ -14,7 +14,7 @@ module Dome
14
14
  environment = @environment.environment
15
15
  account = @environment.account
16
16
  @environment.invalid_account_message unless @environment.valid_account? account
17
- @environment.invalid_environment_message unless @environment.valid_environment?(account, environment)
17
+ @environment.invalid_environment_message unless @environment.valid_environment? environment
18
18
  puts "Team: #{@environment.team.colorize(:green)}"
19
19
  puts '----------------------------------------------------------------'
20
20
  @environment.populate_aws_access_keys
@@ -1,3 +1,3 @@
1
1
  module Dome
2
- VERSION = '1.6.1'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domed-city
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Snape
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,6 +143,7 @@ files:
143
143
  - lib/dome.rb
144
144
  - lib/dome/environment.rb
145
145
  - lib/dome/helpers/shell.rb
146
+ - lib/dome/settings.rb
146
147
  - lib/dome/state.rb
147
148
  - lib/dome/terraform.rb
148
149
  - lib/dome/version.rb