kumo_dockercloud 2.2.0 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9506aa4ff5a6e5dc9775ba9cf36dc4ad5959bc4
4
- data.tar.gz: 8848e236285eb1043ec39d20930b6f807573e369
3
+ metadata.gz: d871a5f98e09f8794d61c9b79c7742afe3b48f3b
4
+ data.tar.gz: 5d88756a089dc80cba87a897e0d82f2018710c9b
5
5
  SHA512:
6
- metadata.gz: 46f6600d38e3a32f976664d4ddd52e1d494e4b3c2323830f4c689f7c399dbdfa7b1bb16109f62823d106cf864d3c91d4d64b534b23ee8971e82112bd494a302c
7
- data.tar.gz: 02b6be74db826142d5018825b7cacb97529d940ffe026bf1e4f002aef8083f9d24c619bda9e1ab10eeb529693183cf2f9d545543bf21321725c6554edd47ed1b
6
+ metadata.gz: 5ba411d51395fc01b3c240c40dbe4058d977408abcfb6a263323922fd8950459b5509839d69f255745667cb97e64fc1ac51ca33a916c309928007ee50941b363
7
+ data.tar.gz: bcd443b5004db702ecf96eca9f18ff1c746f7c79b79e019fdffec6bb4641f21c9e30feaa4f3e85180bf67aab47d76d73079caa088d4cb5fb4d944f9553a36349
data/README.md CHANGED
@@ -47,3 +47,11 @@ Changes to the gem can be manually tested end to end in a project that uses the
47
47
  3. Commit your changes (`git commit -am 'Add some feature'`)
48
48
  4. Push to the branch (`git push origin my-new-feature`)
49
49
  5. Create a new Pull Request
50
+
51
+ ## Changelog
52
+
53
+ This section records potentially breaking changes to the API or User Experience.
54
+
55
+ ### Version 3.0.0
56
+
57
+ Destroying a stack now requires user confirmation at the console before the action will be carried out.
@@ -4,3 +4,4 @@ require 'kumo_dockercloud/stack'
4
4
  require 'kumo_dockercloud/service'
5
5
  require 'kumo_dockercloud/service_checker'
6
6
  require 'kumo_dockercloud/errors'
7
+ require 'kumo_dockercloud/console_jockey'
@@ -0,0 +1,36 @@
1
+ require 'timeout'
2
+
3
+ module KumoDockerCloud
4
+ class ConsoleJockey
5
+
6
+ def self.flash_message(message)
7
+ puts "\n"
8
+ puts "###################=============================------------"
9
+ puts message
10
+ puts "------------=============================###################"
11
+ puts "\n"
12
+
13
+ $stdout.flush
14
+ end
15
+
16
+ def self.write_line(message)
17
+ puts message
18
+
19
+ $stdout.flush
20
+ end
21
+
22
+ def self.get_confirmation(timeout=30)
23
+ begin
24
+ status = Timeout::timeout(timeout) {
25
+ STDIN.gets.chomp
26
+ }
27
+ rescue
28
+ status = false
29
+ end
30
+
31
+ proceed = status == "yes"
32
+ proceed ? puts('Proceeding.') : puts('Aborted!')
33
+ proceed
34
+ end
35
+ end
36
+ end
@@ -3,10 +3,11 @@ require 'erb'
3
3
  require 'tempfile'
4
4
  require 'forwardable'
5
5
 
6
+ require_relative 'console_jockey'
6
7
  require_relative 'docker_cloud_api'
7
- require_relative 'state_validator'
8
8
  require_relative 'environment_config'
9
9
  require_relative 'stack_file'
10
+ require_relative 'state_validator'
10
11
 
11
12
  #TODO refactor this to use the new checker inside Service
12
13
  module KumoDockerCloud
@@ -19,6 +20,7 @@ module KumoDockerCloud
19
20
  @env_vars = params.fetch(:env_vars, {})
20
21
  @stack_template_path = params.fetch(:stack_template_path)
21
22
  @timeout = params.fetch(:timeout, 120)
23
+ @confirmation_timeout = params.fetch(:confirmation_timeout, 30)
22
24
 
23
25
  app_name = params.fetch(:app_name)
24
26
  @config = EnvironmentConfig.new(app_name: app_name, env_name: @env_name, config_path: params.fetch(:config_path))
@@ -39,6 +41,8 @@ module KumoDockerCloud
39
41
  end
40
42
 
41
43
  def destroy
44
+ ConsoleJockey.flash_message "Warning! You are about to delete the Docker Cloud Stack #{stack_name}, enter 'yes' to continue."
45
+ return unless ConsoleJockey.get_confirmation(@confirmation_timeout)
42
46
  run_command("docker-cloud stack terminate --sync #{stack_name}")
43
47
  end
44
48
 
@@ -1,3 +1,3 @@
1
1
  module KumoDockerCloud
2
- VERSION = '2.2.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe KumoDockerCloud::ConsoleJockey do
5
+ describe "#get_confirmation" do
6
+ let(:timeout) { 0.5 }
7
+ subject { described_class }
8
+
9
+ context 'no timeout' do
10
+
11
+ it 'returns true if user enters yes' do
12
+ allow(STDIN).to receive(:gets) { 'yes'}
13
+ expect(subject.get_confirmation(timeout)).to be true
14
+ end
15
+
16
+ it 'returns false if user enters anything other than yes' do
17
+ allow(STDIN).to receive(:gets) { 'aoisdjofa'}
18
+ expect(subject.get_confirmation).to be false
19
+ end
20
+ end
21
+
22
+ context 'timeout' do
23
+ it 'returns false if there is a timeout' do
24
+ expect(subject.get_confirmation(timeout)).to be false
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -15,10 +15,11 @@ describe KumoDockerCloud::Environment do
15
15
  }
16
16
  }
17
17
  }
18
-
18
+ let(:full_stack_name) { "#{app_name}-test" }
19
+ let(:confirmation_timeout) { 0.5 }
19
20
  let(:stack_template_path) { File.join(__dir__, '../fixtures/stack.yml.erb') }
20
21
 
21
- let(:params) { {name: 'test', env_vars: env_vars, app_name: app_name, config_path: 'a path', stack_template_path: stack_template_path} }
22
+ let(:params) { {name: 'test', env_vars: env_vars, app_name: app_name, config_path: 'a path', stack_template_path: stack_template_path, confirmation_timeout: confirmation_timeout} }
22
23
 
23
24
  subject(:env) { described_class.new(params) }
24
25
 
@@ -29,9 +30,6 @@ describe KumoDockerCloud::Environment do
29
30
 
30
31
  describe "#apply" do
31
32
  subject { env.apply }
32
-
33
- let(:full_stack_name) { "#{app_name}-test" }
34
-
35
33
  before do
36
34
  allow(config).to receive(:image_tag).and_return('latest')
37
35
  allow(env).to receive(:evaluate_command).and_return app_name
@@ -60,7 +58,6 @@ describe KumoDockerCloud::Environment do
60
58
  end
61
59
 
62
60
  describe "waiting for running" do
63
-
64
61
  let(:state_validator) { double(KumoDockerCloud::StateValidator, wait_for_state: nil) }
65
62
 
66
63
  before do
@@ -89,4 +86,29 @@ describe KumoDockerCloud::Environment do
89
86
  subject
90
87
  end
91
88
  end
89
+
90
+
91
+ describe "#destroy" do
92
+ subject { env.destroy }
93
+ before do
94
+ allow(KumoDockerCloud::ConsoleJockey).to receive(:flash_message).with("Warning! You are about to delete the Docker Cloud Stack #{full_stack_name}, enter 'yes' to continue.")
95
+ end
96
+
97
+ it "notifies the user of what it is about to delete" do
98
+ expect(KumoDockerCloud::ConsoleJockey).to receive(:flash_message).with("Warning! You are about to delete the Docker Cloud Stack #{full_stack_name}, enter 'yes' to continue.")
99
+ subject
100
+ end
101
+
102
+ it "does delete the stack if the user confirms" do
103
+ expect(KumoDockerCloud::ConsoleJockey).to receive(:get_confirmation).with(confirmation_timeout).and_return(true)
104
+ expect(env).to receive(:run_command).with("docker-cloud stack terminate --sync #{full_stack_name}")
105
+ subject
106
+ end
107
+
108
+ it "does not delete the stack if the the user refuses confirmation" do
109
+ expect(KumoDockerCloud::ConsoleJockey).to receive(:get_confirmation).with(confirmation_timeout).and_return(false)
110
+ subject
111
+ end
112
+
113
+ end
92
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumo_dockercloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redbubble
@@ -128,6 +128,7 @@ files:
128
128
  - Rakefile
129
129
  - kumo_dockercloud.gemspec
130
130
  - lib/kumo_dockercloud.rb
131
+ - lib/kumo_dockercloud/console_jockey.rb
131
132
  - lib/kumo_dockercloud/deployment.rb
132
133
  - lib/kumo_dockercloud/docker_cloud_api.rb
133
134
  - lib/kumo_dockercloud/environment.rb
@@ -147,6 +148,7 @@ files:
147
148
  - spec/fixtures/config/test_secrets.yml
148
149
  - spec/fixtures/stack.yml.erb
149
150
  - spec/kumo_docker_cloud_spec.rb
151
+ - spec/kumo_dockercloud/console_jockey_spec.rb
150
152
  - spec/kumo_dockercloud/docker_cloud_api_spec.rb
151
153
  - spec/kumo_dockercloud/environment_config_spec.rb
152
154
  - spec/kumo_dockercloud/environment_spec.rb
@@ -186,6 +188,7 @@ test_files:
186
188
  - spec/fixtures/config/test_secrets.yml
187
189
  - spec/fixtures/stack.yml.erb
188
190
  - spec/kumo_docker_cloud_spec.rb
191
+ - spec/kumo_dockercloud/console_jockey_spec.rb
189
192
  - spec/kumo_dockercloud/docker_cloud_api_spec.rb
190
193
  - spec/kumo_dockercloud/environment_config_spec.rb
191
194
  - spec/kumo_dockercloud/environment_spec.rb