simple_deploy 0.9.2 → 0.10.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/lib/simple_deploy/aws/cloud_formation.rb +5 -5
  4. data/lib/simple_deploy/aws/helpers.rb +20 -0
  5. data/lib/simple_deploy/aws/instance_reader.rb +10 -13
  6. data/lib/simple_deploy/aws/simpledb.rb +5 -5
  7. data/lib/simple_deploy/aws.rb +1 -0
  8. data/lib/simple_deploy/cli/attributes.rb +4 -2
  9. data/lib/simple_deploy/cli/clone.rb +8 -3
  10. data/lib/simple_deploy/cli/create.rb +4 -2
  11. data/lib/simple_deploy/cli/deploy.rb +4 -2
  12. data/lib/simple_deploy/cli/destroy.rb +4 -2
  13. data/lib/simple_deploy/cli/events.rb +4 -2
  14. data/lib/simple_deploy/cli/execute.rb +4 -2
  15. data/lib/simple_deploy/cli/instances.rb +4 -2
  16. data/lib/simple_deploy/cli/list.rb +5 -2
  17. data/lib/simple_deploy/cli/outputs.rb +4 -2
  18. data/lib/simple_deploy/cli/parameters.rb +4 -2
  19. data/lib/simple_deploy/cli/protect.rb +4 -2
  20. data/lib/simple_deploy/cli/resources.rb +4 -2
  21. data/lib/simple_deploy/cli/shared.rb +34 -2
  22. data/lib/simple_deploy/cli/status.rb +4 -2
  23. data/lib/simple_deploy/cli/template.rb +4 -2
  24. data/lib/simple_deploy/cli/update.rb +4 -2
  25. data/lib/simple_deploy/configuration.rb +39 -4
  26. data/lib/simple_deploy/version.rb +1 -1
  27. data/spec/aws/cloud_formation_spec.rb +162 -135
  28. data/spec/aws/helpers_spec.rb +51 -0
  29. data/spec/aws/instance_reader_spec.rb +181 -167
  30. data/spec/aws/simpledb_spec.rb +78 -50
  31. data/spec/cli/attributes_spec.rb +22 -2
  32. data/spec/cli/clone_spec.rb +7 -8
  33. data/spec/cli/deploy_spec.rb +7 -10
  34. data/spec/cli/destroy_spec.rb +3 -4
  35. data/spec/cli/protect_spec.rb +7 -11
  36. data/spec/cli/shared_spec.rb +107 -17
  37. data/spec/cli/update_spec.rb +4 -7
  38. data/spec/config_spec.rb +50 -3
  39. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebaeaca78fc47bc6bccf96bc14c6e9e45674d2d2
4
- data.tar.gz: f73df170ccaa5d0f646d87e084e4815e62ef3c3d
3
+ metadata.gz: 087c4e0c37329c2f21af41d9f923315eff58b30b
4
+ data.tar.gz: c2986b982379d6479e4c171dd45dd45dc7bac1f3
5
5
  SHA512:
6
- metadata.gz: 1c4c6995dc63e8ae6126cba0c4c7c391b50f854b1c1b2a291a4e2b27db0a645166c841a19a46fbb9ad057496979ec03bfe3cf897e29c3524c8996df3ac56ffb1
7
- data.tar.gz: 2385d7000d4fba22b0ede10ff47a1ddf7230970565ab5fe8780baaf4b22da15e38886563cbf8506e2d3d2aada49bdf844dc321096fddd2a0549cdbe3cb4e1586
6
+ metadata.gz: c851300e97e2f000dcfcea67e0c1c270d48ef866cfda0c92d822c0c55c2a1cb1d4d4638f2e1f25e4e1e74f73d6a9db08bb8ca3e3ff342aa2e784e5a8bf0953f5
7
+ data.tar.gz: a838a2de6528b110e98318ccba7af8ca47fb3ae79509060bd2f5f1a3a333c869da2f772971d2045e6758a484803818e62e03ec06bc8e0a957d1432ffe2f0e970
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## HEAD
2
2
 
3
+ * Add support for setting configuration through env vars
4
+ * Add support for temporary AWS credentials
5
+
3
6
  ## v0.9.2 (04/29/14):
4
7
 
5
8
  * Skip nested stack if status is deleted (thanks @liwenbing)
@@ -4,12 +4,12 @@ module SimpleDeploy
4
4
  class AWS
5
5
  class CloudFormation
6
6
 
7
+ include Helpers
8
+
7
9
  def initialize
8
- @config = SimpleDeploy.config
9
- @logger = SimpleDeploy.logger
10
- @connect = Fog::AWS::CloudFormation.new :aws_access_key_id => @config.access_key,
11
- :aws_secret_access_key => @config.secret_key,
12
- :region => @config.region
10
+ @config = SimpleDeploy.config
11
+ @logger = SimpleDeploy.logger
12
+ @connect = Fog::AWS::CloudFormation.new connection_args
13
13
  end
14
14
 
15
15
  def create(args)
@@ -0,0 +1,20 @@
1
+ module SimpleDeploy
2
+ class AWS
3
+ module Helpers
4
+
5
+ def connection_args
6
+ {
7
+ aws_access_key_id: @config.access_key,
8
+ aws_secret_access_key: @config.secret_key,
9
+ region: @config.region
10
+ }.tap do |a|
11
+
12
+ if @config.temporary_credentials?
13
+ a.merge!({ aws_session_token: @config.security_token })
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -1,14 +1,19 @@
1
1
  module SimpleDeploy
2
2
  class AWS
3
3
  class InstanceReader
4
+
5
+ include Helpers
6
+
4
7
  def initialize
5
- @config = SimpleDeploy.config
8
+ @config = SimpleDeploy.config
9
+ @asg_connect = Fog::AWS::AutoScaling.new connection_args
10
+ @ec2_connect = Fog::Compute::AWS.new connection_args
6
11
  end
7
12
 
8
13
  def list_stack_instances(stack_name)
9
14
 
10
15
  instances = []
11
-
16
+
12
17
  #Nested stack
13
18
  nested_stacks = nested_stacks_names(stack_name)
14
19
  instances = nested_stacks.map {|stack| list_stack_instances stack }.flatten if nested_stacks.any?
@@ -28,11 +33,7 @@ module SimpleDeploy
28
33
  private
29
34
 
30
35
  def list_instances(asg_id)
31
- @asg ||= Fog::AWS::AutoScaling.new :aws_access_key_id => @config.access_key,
32
- :aws_secret_access_key => @config.secret_key,
33
- :region => @config.region
34
-
35
- body = @asg.describe_auto_scaling_groups('AutoScalingGroupNames' => [asg_id]).body
36
+ body = @asg_connect.describe_auto_scaling_groups('AutoScalingGroupNames' => [asg_id]).body
36
37
  result = body['DescribeAutoScalingGroupsResult']['AutoScalingGroups'].last
37
38
  return [] unless result
38
39
 
@@ -40,12 +41,8 @@ module SimpleDeploy
40
41
  end
41
42
 
42
43
  def describe_instances(instances)
43
- @ec2 ||= Fog::Compute::AWS.new :aws_access_key_id => @config.access_key,
44
- :aws_secret_access_key => @config.secret_key,
45
- :region => @config.region
46
-
47
- @ec2.describe_instances('instance-state-name' => 'running',
48
- 'instance-id' => instances).body['reservationSet']
44
+ @ec2_connect.describe_instances('instance-state-name' => 'running',
45
+ 'instance-id' => instances).body['reservationSet']
49
46
  end
50
47
 
51
48
  def cloud_formation
@@ -4,11 +4,11 @@ module SimpleDeploy
4
4
  class AWS
5
5
  class SimpleDB
6
6
 
7
+ include Helpers
8
+
7
9
  def initialize
8
- c = SimpleDeploy.config
9
- @connect = Fog::AWS::SimpleDB.new :aws_access_key_id => c.access_key,
10
- :aws_secret_access_key => c.secret_key,
11
- :region => c.region
10
+ @config = SimpleDeploy.config
11
+ @connect = Fog::AWS::SimpleDB.new connection_args
12
12
  end
13
13
 
14
14
  def domains
@@ -31,7 +31,7 @@ module SimpleDeploy
31
31
  options = { 'ConsistentRead' => true }
32
32
  data = {}
33
33
  next_token = nil
34
-
34
+
35
35
  while true
36
36
  options.merge! 'NextToken' => next_token
37
37
  chunk = @connect.select(query, options).body
@@ -1,3 +1,4 @@
1
+ require "simple_deploy/aws/helpers"
1
2
  require "simple_deploy/aws/cloud_formation"
2
3
  require "simple_deploy/aws/cloud_formation/error"
3
4
  require "simple_deploy/aws/instance_reader"
@@ -23,12 +23,14 @@ EOS
23
23
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
24
24
  :default => 'info'
25
25
  opt :name, "Stack name to manage", :type => :string
26
+ opt :read_from_env, "Read credentials and region from environment variables"
26
27
  end
27
28
 
28
29
  valid_options? :provided => @opts,
29
- :required => [:environment, :name]
30
+ :required => [:environment, :name, :read_from_env]
30
31
 
31
- SimpleDeploy.create_config @opts[:environment]
32
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
33
+ SimpleDeploy.create_config config_arg
32
34
  SimpleDeploy.logger @opts[:log_level]
33
35
  @stack = Stack.new :name => @opts[:name],
34
36
  :environment => @opts[:environment]
@@ -21,7 +21,7 @@ EOS
21
21
  opt :environment, "Set the target environment", :type => :string
22
22
  opt :input_stack, "Read outputs from given stack(s) and map them \
23
23
  to parameter inputs in the new stack. These will be passed to inputs with \
24
- matching or pluralized names. Can be specified multiple times.", :type => :string,
24
+ matching or pluralized names. Can be specified multiple times.", :type => :string,
25
25
  :multi => true
26
26
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
27
27
  :default => 'info'
@@ -30,12 +30,17 @@ matching or pluralized names. Can be specified multiple times.", :type => :stri
30
30
  opt :attributes, "= separated attribute and it's value", :type => :string,
31
31
  :multi => true
32
32
  opt :template, "Path to a new template file", :type => :string
33
+ opt :read_from_env, "Read credentials and region from environment variables"
33
34
  end
34
35
 
35
36
  valid_options? :provided => @opts,
36
- :required => [:environment, :source_name, :new_name]
37
+ :required => [:environment,
38
+ :source_name,
39
+ :new_name,
40
+ :read_from_env]
37
41
 
38
- SimpleDeploy.create_config @opts[:environment]
42
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
43
+ SimpleDeploy.create_config config_arg
39
44
  SimpleDeploy.logger @opts[:log_level]
40
45
 
41
46
  override_attributes = parse_attributes :attributes => @opts[:attributes]
@@ -28,13 +28,15 @@ matching or pluralized names. Can be specified multiple times.", :type => :stri
28
28
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
29
29
  :default => 'info'
30
30
  opt :name, "Stack name(s) of stack to deploy", :type => :string
31
+ opt :read_from_env, "Read credentials and region from environment variables"
31
32
  opt :template, "Path to the template file", :type => :string
32
33
  end
33
34
 
34
35
  valid_options? :provided => @opts,
35
- :required => [:environment, :name, :template]
36
+ :required => [:environment, :name, :read_from_env, :template]
36
37
 
37
- SimpleDeploy.create_config @opts[:environment]
38
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
39
+ SimpleDeploy.create_config config_arg
38
40
  SimpleDeploy.logger @opts[:log_level]
39
41
  stack = Stack.new :name => @opts[:name],
40
42
  :environment => @opts[:environment]
@@ -49,14 +49,16 @@ EOS
49
49
  opt :name, "Stack name(s) of stack to deploy", :type => :string,
50
50
  :multi => true
51
51
  opt :quiet, "Quiet, do not send notifications"
52
+ opt :read_from_env, "Read credentials and region from environment variables"
52
53
  opt :external, "Use external IP for ssh commands"
53
54
  opt :internal, "Use internal IP for ssh commands"
54
55
  end
55
56
 
56
57
  valid_options? :provided => @opts,
57
- :required => [:environment, :name]
58
+ :required => [:environment, :name, :read_from_env]
58
59
 
59
- SimpleDeploy.create_config @opts[:environment]
60
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
61
+ SimpleDeploy.create_config config_arg
60
62
  logger = SimpleDeploy.logger @opts[:log_level]
61
63
 
62
64
  new_attributes = parse_attributes :attributes => @opts[:attributes]
@@ -21,12 +21,14 @@ EOS
21
21
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
22
22
  :default => 'info'
23
23
  opt :name, "Stack name(s) of stack to deploy", :type => :string
24
+ opt :read_from_env, "Read credentials and region from environment variables"
24
25
  end
25
26
 
26
27
  valid_options? :provided => @opts,
27
- :required => [:environment, :name]
28
+ :required => [:environment, :name, :read_from_env]
28
29
 
29
- SimpleDeploy.create_config @opts[:environment]
30
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
31
+ SimpleDeploy.create_config config_arg
30
32
  SimpleDeploy.logger @opts[:log_level]
31
33
  stack = Stack.new :name => @opts[:name],
32
34
  :environment => @opts[:environment]
@@ -21,12 +21,14 @@ EOS
21
21
  :default => 3
22
22
  opt :environment, "Set the target environment", :type => :string
23
23
  opt :name, "Stack name to manage", :type => :string
24
+ opt :read_from_env, "Read credentials and region from environment variables"
24
25
  end
25
26
 
26
27
  valid_options? :provided => @opts,
27
- :required => [:environment, :name]
28
+ :required => [:environment, :name, :read_from_env]
28
29
 
29
- SimpleDeploy.create_config @opts[:environment]
30
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
31
+ SimpleDeploy.create_config config_arg
30
32
  SimpleDeploy.logger @opts[:log_level]
31
33
  stack = Stack.new :name => @opts[:name],
32
34
  :environment => @opts[:environment]
@@ -36,13 +36,15 @@ EOS
36
36
  opt :name, "Stack name(s) of stack to deploy", :type => :string,
37
37
  :multi => true
38
38
  opt :pty, "Set pty to true when executing commands."
39
+ opt :read_from_env, "Read credentials and region from environment variables"
39
40
  opt :sudo, "Execute command with sudo"
40
41
  end
41
42
 
42
43
  valid_options? :provided => @opts,
43
- :required => [:environment, :name]
44
+ :required => [:environment, :name, :read_from_env]
44
45
 
45
- SimpleDeploy.create_config @opts[:environment]
46
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
47
+ SimpleDeploy.create_config config_arg
46
48
  logger = SimpleDeploy.logger @opts[:log_level]
47
49
 
48
50
  @opts[:name].each do |name|
@@ -29,12 +29,14 @@ EOS
29
29
  opt :name, "Stack name to manage", :type => :string
30
30
  opt :external, "Return external IP for instances."
31
31
  opt :internal, "Return internal IP for instances."
32
+ opt :read_from_env, "Read credentials and region from environment variables"
32
33
  end
33
34
 
34
35
  valid_options? :provided => @opts,
35
- :required => [:environment, :name]
36
+ :required => [:environment, :name, :read_from_env]
36
37
 
37
- SimpleDeploy.create_config @opts[:environment]
38
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
39
+ SimpleDeploy.create_config config_arg
38
40
  logger = SimpleDeploy.logger @opts[:log_level]
39
41
 
40
42
  stack = Stack.new :name => @opts[:name],
@@ -21,13 +21,16 @@ EOS
21
21
  opt :environment, "Set the target environment", :type => :string
22
22
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
23
23
  :default => 'info'
24
+ opt :read_from_env, "Read credentials and region from environment variables"
24
25
  opt :help, "Display Help"
25
26
  end
26
27
 
27
28
  valid_options? :provided => @opts,
28
- :required => [:environment]
29
+ :required => [:environment, :read_from_env]
30
+
31
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
32
+ SimpleDeploy.create_config config_arg
29
33
 
30
- SimpleDeploy.create_config @opts[:environment]
31
34
  SimpleDeploy.logger @opts[:log_level]
32
35
 
33
36
  stacks = SimpleDeploy::StackLister.new.all.sort
@@ -23,12 +23,14 @@ EOS
23
23
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
24
24
  :default => 'warn'
25
25
  opt :name, "Stack name to manage", :type => :string
26
+ opt :read_from_env, "Read credentials and region from environment variables"
26
27
  end
27
28
 
28
29
  valid_options? :provided => @opts,
29
- :required => [:environment, :name]
30
+ :required => [:environment, :name, :read_from_env]
30
31
 
31
- SimpleDeploy.create_config @opts[:environment]
32
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
33
+ SimpleDeploy.create_config config_arg
32
34
  logger = SimpleDeploy.logger @opts[:log_level]
33
35
  stack = Stack.new :name => @opts[:name],
34
36
  :environment => @opts[:environment]
@@ -21,12 +21,14 @@ EOS
21
21
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
22
22
  :default => 'warn'
23
23
  opt :name, "Stack name to manage", :type => :string
24
+ opt :read_from_env, "Read credentials and region from environment variables"
24
25
  end
25
26
 
26
27
  valid_options? :provided => @opts,
27
- :required => [:environment, :name]
28
+ :required => [:environment, :name, :read_from_env]
28
29
 
29
- SimpleDeploy.create_config @opts[:environment]
30
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
31
+ SimpleDeploy.create_config config_arg
30
32
  SimpleDeploy.logger @opts[:log_level]
31
33
  stack = Stack.new :name => @opts[:name],
32
34
  :environment => @opts[:environment]
@@ -24,12 +24,14 @@ EOS
24
24
  :default => 'info'
25
25
  opt :name, "Stack name(s) of stacks to protect", :type => :string,
26
26
  :multi => true
27
+ opt :read_from_env, "Read credentials and region from environment variables"
27
28
  end
28
29
 
29
30
  valid_options? :provided => @opts,
30
- :required => [:environment, :name]
31
+ :required => [:environment, :name, :read_from_env]
31
32
 
32
- SimpleDeploy.create_config @opts[:environment]
33
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
34
+ SimpleDeploy.create_config config_arg
33
35
  SimpleDeploy.logger @opts[:log_level]
34
36
 
35
37
  @opts[:name].each do |name|
@@ -22,12 +22,14 @@ EOS
22
22
  opt :log_level, "Log level: debug, info, warn, error", :type => :string,
23
23
  :default => 'info'
24
24
  opt :name, "Stack name to manage", :type => :string
25
+ opt :read_from_env, "Read credentials and region from environment variables"
25
26
  end
26
27
 
27
28
  valid_options? :provided => @opts,
28
- :required => [:environment, :name]
29
+ :required => [:environment, :name, :read_from_env]
29
30
 
30
- SimpleDeploy.create_config @opts[:environment]
31
+ config_arg = @opts[:read_from_env] ? :read_from_env : @opts[:environment]
32
+ SimpleDeploy.create_config config_arg
31
33
  SimpleDeploy.logger @opts[:log_level]
32
34
  stack = Stack.new :name => @opts[:name],
33
35
  :environment => @opts[:environment]
@@ -20,14 +20,29 @@ module SimpleDeploy
20
20
  provided = args[:provided]
21
21
  required = args[:required]
22
22
 
23
- required.each do |opt|
23
+ if provided[:environment] && provided[:read_from_env]
24
+ SimpleDeploy.logger.error "You cannot specify both --environment and --read-from-env"
25
+ exit 1
26
+ end
27
+
28
+ if required.include?(:environment) && required.include?(:read_from_env)
29
+ if !provided.include?(:environment) && !provided.include?(:read_from_env)
30
+ msg = "Either '--environment' or '--read-from-env' is required but not specified"
31
+ SimpleDeploy.logger.error msg
32
+ exit 1
33
+ end
34
+ end
35
+
36
+ required.reject { |i| [:environment, :read_from_env].include? i }.each do |opt|
24
37
  unless provided[opt]
25
38
  SimpleDeploy.logger.error "Option '#{opt} (-#{opt[0]})' required but not specified."
26
39
  exit 1
27
40
  end
28
41
  end
29
42
 
30
- if required.include? :environment
43
+ validate_credential_env_vars if provided.has_key?(:read_from_env)
44
+
45
+ if provided[:environment]
31
46
  unless SimpleDeploy.environments.keys.include? provided[:environment]
32
47
  SimpleDeploy.logger.error "Environment '#{provided[:environment]}' does not exist."
33
48
  exit 1
@@ -45,6 +60,23 @@ module SimpleDeploy
45
60
  exit 1
46
61
  end
47
62
 
63
+ private
64
+
65
+ def credential_env_vars_exist?
66
+ !!ENV['AWS_ACCESS_KEY_ID'] &&
67
+ !!ENV['AWS_SECRET_ACCESS_KEY'] &&
68
+ !!ENV['AWS_REGION']
69
+ end
70
+
71
+ def validate_credential_env_vars
72
+ unless credential_env_vars_exist?
73
+ msg = "The following environment variables must be set when using --read-from-env: "
74
+ msg << "AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION"
75
+ SimpleDeploy.logger.error msg
76
+ exit 1
77
+ end
78
+ end
79
+
48
80
  end
49
81
 
50
82
  end