flare-up 0.7 → 0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/flare_up.rb +2 -0
- data/lib/flare_up/boot.rb +20 -17
- data/lib/flare_up/cli.rb +4 -4
- data/lib/flare_up/emitter.rb +17 -16
- data/lib/flare_up/option_store.rb +32 -0
- data/lib/flare_up/version.rb +1 -1
- data/spec/lib/flare_up/boot_spec.rb +34 -30
- data/spec/lib/flare_up/cli_spec.rb +18 -20
- data/spec/lib/flare_up/emitter_spec.rb +37 -4
- data/spec/lib/flare_up/option_store_spec.rb +34 -0
- data/spec/spec_helper.rb +9 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzFmZDVjOWIyZmE4MDcxODhhM2E1YjhmNmE3YmNiODA2NWZhMjhkMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2ZmYTExMTRhMWUxYTdlNDQ4NjA5ZmRmODJiMjQxMDdmNjQ2ZGQyNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGY5YjZjNjI1ZWExZTRhODMyNWU2MzgzMGUyZTQ4NjJjNTk5MjYxNTliNzcw
|
10
|
+
N2M0ZDY0NWZlMmZjZWZiYzc2NTE3NjA3OTRjNTAxNDQ1OGYyMzc3MDFlOWMw
|
11
|
+
NzhlMjlmNDBkMjQ3ZGQ2ZjZhMGFhOTE1NmYyMDZjMjg0NDI5NjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDFjZTI1MDU0OGE2OTcyYmMwOGM1OWIyYWJiYWJmNjFmMGVlYWM4ZWYxMjM2
|
14
|
+
YzIxMmEzMmZmYWY0OTg5YTJlMDRjYjJiMWM3NDExMTUxMGM1OGMxNGE2ZmRi
|
15
|
+
ZDhkNmM1ZmJjOTYyYmIxZDE3NmNkM2ZiMDFmOWMzZDU5MjJkNWU=
|
data/Gemfile.lock
CHANGED
data/lib/flare_up.rb
CHANGED
data/lib/flare_up/boot.rb
CHANGED
@@ -3,13 +3,13 @@ module FlareUp
|
|
3
3
|
class Boot
|
4
4
|
|
5
5
|
# TODO: This control flow is untested and too procedural
|
6
|
-
def self.boot
|
7
|
-
conn = create_connection
|
8
|
-
copy = create_copy_command
|
6
|
+
def self.boot
|
7
|
+
conn = create_connection
|
8
|
+
copy = create_copy_command
|
9
9
|
|
10
10
|
begin
|
11
11
|
trap('SIGINT') do
|
12
|
-
Emitter.warn(
|
12
|
+
Emitter.warn("\nCTRL-C received; cancelling COPY command...")
|
13
13
|
error_message = conn.cancel_current_command
|
14
14
|
if error_message
|
15
15
|
Emitter.error("Error cancelling COPY: #{error_message}")
|
@@ -31,28 +31,30 @@ module FlareUp
|
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.create_connection
|
34
|
+
def self.create_connection
|
35
35
|
FlareUp::Connection.new(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
OptionStore.get(:redshift_endpoint),
|
37
|
+
OptionStore.get(:database),
|
38
|
+
OptionStore.get(:redshift_username),
|
39
|
+
OptionStore.get(:redshift_password)
|
40
40
|
)
|
41
41
|
end
|
42
|
+
private_class_method :create_connection
|
42
43
|
|
43
|
-
def self.create_copy_command
|
44
|
+
def self.create_copy_command
|
44
45
|
copy = FlareUp::CopyCommand.new(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
OptionStore.get(:table),
|
47
|
+
OptionStore.get(:data_source),
|
48
|
+
OptionStore.get(:aws_access_key),
|
49
|
+
OptionStore.get(:aws_secret_key)
|
49
50
|
)
|
50
|
-
copy.columns =
|
51
|
-
copy.options =
|
51
|
+
copy.columns = OptionStore.get(:column_list) if OptionStore.get(:column_list)
|
52
|
+
copy.options = OptionStore.get(:copy_options) if OptionStore.get(:copy_options)
|
52
53
|
copy
|
53
54
|
end
|
55
|
+
private_class_method :create_copy_command
|
54
56
|
|
55
|
-
# TODO:
|
57
|
+
# TODO: Backfill tests
|
56
58
|
def self.handle_load_errors(stl_load_errors)
|
57
59
|
return if stl_load_errors.empty?
|
58
60
|
Emitter.error("There was an error processing the COPY command. Displaying the last (#{stl_load_errors.length}) errors.")
|
@@ -61,6 +63,7 @@ module FlareUp
|
|
61
63
|
end
|
62
64
|
CLI.bailout(1)
|
63
65
|
end
|
66
|
+
private_class_method :handle_load_errors
|
64
67
|
|
65
68
|
end
|
66
69
|
|
data/lib/flare_up/cli.rb
CHANGED
@@ -37,8 +37,9 @@ https://github.com/sharethrough/flare-up/blob/v#{FlareUp::VERSION}/README.md
|
|
37
37
|
CLI.bailout(1)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
OptionStore.store_options(boot_options)
|
41
|
+
|
42
|
+
Boot.boot
|
42
43
|
end
|
43
44
|
|
44
45
|
def self.env_validator(options, option_name, env_variable_name)
|
@@ -47,9 +48,8 @@ https://github.com/sharethrough/flare-up/blob/v#{FlareUp::VERSION}/README.md
|
|
47
48
|
raise ArgumentError, "One of either the --#{option_name} option or the ENV['#{env_variable_name}'] must be set"
|
48
49
|
end
|
49
50
|
|
50
|
-
# TODO: Extract
|
51
51
|
def self.bailout(exit_code)
|
52
|
-
exit(
|
52
|
+
exit(exit_code)
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
data/lib/flare_up/emitter.rb
CHANGED
@@ -9,39 +9,40 @@ module FlareUp
|
|
9
9
|
:redshift_password
|
10
10
|
]
|
11
11
|
|
12
|
-
# TODO: How do we test this?
|
13
12
|
def self.error(message)
|
14
|
-
|
13
|
+
err("\x1b[31m#{message}")
|
15
14
|
end
|
16
15
|
|
17
|
-
# TODO: How do we test this?
|
18
16
|
def self.success(message)
|
19
|
-
|
17
|
+
out("\x1b[32m#{message}")
|
20
18
|
end
|
21
19
|
|
22
|
-
# TODO: How do we test this?
|
23
20
|
def self.warn(message)
|
24
|
-
|
21
|
+
err("\x1b[33m#{message}")
|
25
22
|
end
|
26
23
|
|
27
|
-
# TODO: How do we test this?
|
28
24
|
def self.info(message)
|
29
|
-
|
25
|
+
out(message)
|
30
26
|
end
|
31
27
|
|
32
|
-
|
28
|
+
def self.out(message)
|
29
|
+
$stderr.puts(sanitize(message)) unless ENV['TESTING']
|
30
|
+
end
|
31
|
+
private_class_method :out
|
32
|
+
|
33
|
+
def self.err(message)
|
34
|
+
$stdout.puts(sanitize(message)) unless ENV['TESTING']
|
35
|
+
end
|
36
|
+
private_class_method :err
|
37
|
+
|
33
38
|
def self.sanitize(message)
|
34
39
|
RISKY_OPTIONS.each do |risky_option|
|
35
|
-
message.gsub!(
|
40
|
+
message.gsub!(OptionStore.get(risky_option), 'REDACTED') if OptionStore.get(risky_option)
|
36
41
|
end
|
37
|
-
message.gsub!(/\e\[(\d+)(;\d+)*m/, '') unless
|
42
|
+
message.gsub!(/\e\[(\d+)(;\d+)*m/, '') unless OptionStore.get(:colorize_output)
|
38
43
|
message
|
39
44
|
end
|
40
|
-
|
41
|
-
# TODO: How do we test this?
|
42
|
-
def self.store_options(options)
|
43
|
-
@BOOT_OPTIONS = options
|
44
|
-
end
|
45
|
+
private_class_method :sanitize
|
45
46
|
|
46
47
|
end
|
47
48
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module FlareUp
|
2
|
+
|
3
|
+
class OptionStore
|
4
|
+
|
5
|
+
def self.store_option(name, value)
|
6
|
+
storage[name] = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.store_options(options)
|
10
|
+
storage.merge!(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get(name)
|
14
|
+
storage[name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_options
|
18
|
+
storage
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.clear
|
22
|
+
storage.clear
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.storage
|
26
|
+
@storage ||= {}
|
27
|
+
end
|
28
|
+
private_class_method :storage
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/flare_up/version.rb
CHANGED
@@ -19,7 +19,7 @@ describe FlareUp::Boot do
|
|
19
19
|
let(:copy_command_error) { FlareUp::DataSourceError }
|
20
20
|
it 'should handle the error' do
|
21
21
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
22
|
-
expect { FlareUp::Boot.boot
|
22
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,7 +27,7 @@ describe FlareUp::Boot do
|
|
27
27
|
let(:copy_command_error) { FlareUp::OtherZoneBucketError }
|
28
28
|
it 'should handle the error' do
|
29
29
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
30
|
-
expect { FlareUp::Boot.boot
|
30
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ describe FlareUp::Boot do
|
|
35
35
|
let(:copy_command_error) { FlareUp::SyntaxError }
|
36
36
|
it 'should handle the error' do
|
37
37
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
38
|
-
expect { FlareUp::Boot.boot
|
38
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -52,7 +52,7 @@ describe FlareUp::Boot do
|
|
52
52
|
let(:connection_error) { FlareUp::HostUnknownOrInaccessibleError }
|
53
53
|
it 'should handle the error' do
|
54
54
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
55
|
-
expect { FlareUp::Boot.boot
|
55
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -60,7 +60,7 @@ describe FlareUp::Boot do
|
|
60
60
|
let(:connection_error) { FlareUp::TimeoutError }
|
61
61
|
it 'should handle the error' do
|
62
62
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
63
|
-
expect { FlareUp::Boot.boot
|
63
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -68,7 +68,7 @@ describe FlareUp::Boot do
|
|
68
68
|
let(:connection_error) { FlareUp::NoDatabaseError }
|
69
69
|
it 'should handle the error' do
|
70
70
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
71
|
-
expect { FlareUp::Boot.boot
|
71
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,7 +76,7 @@ describe FlareUp::Boot do
|
|
76
76
|
let(:connection_error) { FlareUp::AuthenticationError }
|
77
77
|
it 'should handle the error' do
|
78
78
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
79
|
-
expect { FlareUp::Boot.boot
|
79
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -84,7 +84,7 @@ describe FlareUp::Boot do
|
|
84
84
|
let(:connection_error) { FlareUp::UnknownError }
|
85
85
|
it 'should handle the error' do
|
86
86
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
87
|
-
expect { FlareUp::Boot.boot
|
87
|
+
expect { FlareUp::Boot.boot }.not_to raise_error
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -93,17 +93,19 @@ describe FlareUp::Boot do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
describe '.create_connection' do
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
before do
|
97
|
+
FlareUp::OptionStore.store_options(
|
98
|
+
{
|
99
|
+
:redshift_endpoint => 'TEST_REDSHIFT_ENDPOINT',
|
100
|
+
:database => 'TEST_DATABASE',
|
101
|
+
:redshift_username => 'TEST_REDSHIFT_USERNAME',
|
102
|
+
:redshift_password => 'TEST_REDSHIFT_PASSWORD'
|
103
|
+
}
|
104
|
+
)
|
105
|
+
end
|
104
106
|
|
105
107
|
it 'should create a connection' do
|
106
|
-
connection = FlareUp::Boot.create_connection
|
108
|
+
connection = FlareUp::Boot.send(:create_connection)
|
107
109
|
expect(connection.host).to eq('TEST_REDSHIFT_ENDPOINT')
|
108
110
|
expect(connection.dbname).to eq('TEST_DATABASE')
|
109
111
|
expect(connection.user).to eq('TEST_REDSHIFT_USERNAME')
|
@@ -113,17 +115,19 @@ describe FlareUp::Boot do
|
|
113
115
|
|
114
116
|
describe '.create_copy_command' do
|
115
117
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
118
|
+
before do
|
119
|
+
FlareUp::OptionStore.store_options(
|
120
|
+
{
|
121
|
+
:table => 'TEST_TABLE',
|
122
|
+
:data_source => 'TEST_DATA_SOURCE',
|
123
|
+
:aws_access_key => 'TEST_ACCESS_KEY',
|
124
|
+
:aws_secret_key => 'TEST_SECRET_KEY'
|
125
|
+
}
|
126
|
+
)
|
127
|
+
end
|
124
128
|
|
125
129
|
it 'should create a proper copy command' do
|
126
|
-
command = FlareUp::Boot.create_copy_command
|
130
|
+
command = FlareUp::Boot.send(:create_copy_command)
|
127
131
|
expect(command.table_name).to eq('TEST_TABLE')
|
128
132
|
expect(command.data_source).to eq('TEST_DATA_SOURCE')
|
129
133
|
expect(command.aws_access_key_id).to eq('TEST_ACCESS_KEY')
|
@@ -132,20 +136,20 @@ describe FlareUp::Boot do
|
|
132
136
|
|
133
137
|
context 'when columns are specified' do
|
134
138
|
before do
|
135
|
-
|
139
|
+
FlareUp::OptionStore.store_option(:column_list, ['c1'])
|
136
140
|
end
|
137
141
|
it 'should create a proper copy command' do
|
138
|
-
command = FlareUp::Boot.create_copy_command
|
142
|
+
command = FlareUp::Boot.send(:create_copy_command)
|
139
143
|
expect(command.columns).to eq(['c1'])
|
140
144
|
end
|
141
145
|
end
|
142
146
|
|
143
147
|
context 'when options are specified' do
|
144
148
|
before do
|
145
|
-
|
149
|
+
FlareUp::OptionStore.store_option(:copy_options, '_')
|
146
150
|
end
|
147
151
|
it 'should create a proper copy command' do
|
148
|
-
command = FlareUp::Boot.create_copy_command
|
152
|
+
command = FlareUp::Boot.send(:create_copy_command)
|
149
153
|
expect(command.options).to eq('_')
|
150
154
|
end
|
151
155
|
end
|
@@ -25,29 +25,29 @@ describe FlareUp::CLI do
|
|
25
25
|
|
26
26
|
describe '#copy' do
|
27
27
|
|
28
|
-
it 'should
|
29
|
-
expect(FlareUp::
|
28
|
+
it 'should boot' do
|
29
|
+
expect(FlareUp::Boot).to receive(:boot)
|
30
30
|
FlareUp::CLI.start(required_arguments)
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'when no options are specified' do
|
34
34
|
it 'should boot with the proper options' do
|
35
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options)
|
36
35
|
FlareUp::CLI.start(required_arguments)
|
36
|
+
expect(FlareUp::OptionStore.get_options).to eq(required_options)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'when column ordering is specified' do
|
41
41
|
it 'should boot with the proper options' do
|
42
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:column_list => %w(c1 c2 c3)))
|
43
42
|
FlareUp::CLI.start(required_arguments + %w(--column_list c1 c2 c3))
|
43
|
+
expect(FlareUp::OptionStore.get(:column_list)).to eq(%w(c1 c2 c3))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'when COPY options are specified' do
|
48
48
|
it 'should boot with the proper options' do
|
49
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:copy_options => 'TEST_COPY_OPTIONS WITH A SPACE'))
|
50
49
|
FlareUp::CLI.start(required_arguments + ['--copy_options', 'TEST_COPY_OPTIONS WITH A SPACE'])
|
50
|
+
expect(FlareUp::OptionStore.get(:copy_options)).to eq('TEST_COPY_OPTIONS WITH A SPACE')
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -55,15 +55,15 @@ describe FlareUp::CLI do
|
|
55
55
|
|
56
56
|
context 'when it is not specified' do
|
57
57
|
it 'should boot with the proper options' do
|
58
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:colorize_output => true))
|
59
58
|
FlareUp::CLI.start(required_arguments)
|
59
|
+
expect(FlareUp::OptionStore.get(:colorize_output)).to eq(true)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when it is specified' do
|
64
64
|
it 'should boot with the proper options' do
|
65
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:colorize_output => false))
|
66
65
|
FlareUp::CLI.start(required_arguments + ['--colorize_output=false'])
|
66
|
+
expect(FlareUp::OptionStore.get(:colorize_output)).to eq(false)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -74,23 +74,21 @@ describe FlareUp::CLI do
|
|
74
74
|
describe 'username' do
|
75
75
|
context 'when it is specified on the CLI' do
|
76
76
|
it 'should boot with the proper options' do
|
77
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:redshift_username => 'CLI_VALUE'))
|
78
77
|
FlareUp::CLI.start(required_arguments + %w(--redshift_username CLI_VALUE))
|
78
|
+
expect(FlareUp::OptionStore.get(:redshift_username)).to eq('CLI_VALUE')
|
79
79
|
end
|
80
80
|
end
|
81
81
|
context 'when it is not specified on the CLI' do
|
82
82
|
context 'when it is available via ENV' do
|
83
83
|
it 'should boot with the key from the environment' do
|
84
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:redshift_username => 'TEST_REDSHIFT_USERNAME'))
|
85
84
|
FlareUp::CLI.start(required_arguments)
|
85
|
+
expect(FlareUp::OptionStore.get(:redshift_username)).to eq('TEST_REDSHIFT_USERNAME')
|
86
86
|
end
|
87
87
|
end
|
88
88
|
context 'when it is not available via ENV' do
|
89
|
-
|
89
|
+
it 'should be an error' do
|
90
90
|
allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_USERNAME').and_return(nil)
|
91
91
|
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
92
|
-
end
|
93
|
-
it 'should be an error' do
|
94
92
|
FlareUp::CLI.start(required_arguments)
|
95
93
|
end
|
96
94
|
end
|
@@ -100,23 +98,23 @@ describe FlareUp::CLI do
|
|
100
98
|
describe 'password' do
|
101
99
|
context 'when it is specified on the CLI' do
|
102
100
|
it 'should boot with the proper options' do
|
103
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:redshift_password => 'CLI_VALUE'))
|
104
101
|
FlareUp::CLI.start(required_arguments + %w(--redshift_password CLI_VALUE))
|
102
|
+
expect(FlareUp::OptionStore.get(:redshift_password)).to eq('CLI_VALUE')
|
105
103
|
end
|
106
104
|
end
|
107
105
|
context 'when it is not specified on the CLI' do
|
108
106
|
context 'when it is available via ENV' do
|
109
107
|
it 'should boot with the key from the environment' do
|
110
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:redshift_password => 'TEST_REDSHIFT_PASSWORD'))
|
111
108
|
FlareUp::CLI.start(required_arguments)
|
109
|
+
expect(FlareUp::OptionStore.get(:redshift_password)).to eq('TEST_REDSHIFT_PASSWORD')
|
112
110
|
end
|
113
111
|
end
|
114
112
|
context 'when it is not available via ENV' do
|
115
113
|
before do
|
116
|
-
allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_PASSWORD').and_return(nil)
|
117
|
-
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
118
114
|
end
|
119
115
|
it 'should be an error' do
|
116
|
+
allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_PASSWORD').and_return(nil)
|
117
|
+
expect(FlareUp::CLI).to receive(:bailout).with(1)
|
120
118
|
FlareUp::CLI.start(required_arguments)
|
121
119
|
end
|
122
120
|
end
|
@@ -130,15 +128,15 @@ describe FlareUp::CLI do
|
|
130
128
|
describe 'access key' do
|
131
129
|
context 'when an AWS access key is specified' do
|
132
130
|
it 'should boot with the proper options' do
|
133
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:aws_access_key => 'CLI_KEY'))
|
134
131
|
FlareUp::CLI.start(required_arguments + %w(--aws_access_key CLI_KEY))
|
132
|
+
expect(FlareUp::OptionStore.get(:aws_access_key)).to eq('CLI_KEY')
|
135
133
|
end
|
136
134
|
end
|
137
135
|
context 'when an AWS access key is not specified' do
|
138
136
|
context 'when the key is available via ENV' do
|
139
137
|
it 'should boot with the key from the environment' do
|
140
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:aws_access_key => 'TEST_AWS_ACCESS_KEY'))
|
141
138
|
FlareUp::CLI.start(required_arguments)
|
139
|
+
expect(FlareUp::OptionStore.get(:aws_access_key)).to eq('TEST_AWS_ACCESS_KEY')
|
142
140
|
end
|
143
141
|
end
|
144
142
|
context 'when the key is not available via ENV' do
|
@@ -156,15 +154,15 @@ describe FlareUp::CLI do
|
|
156
154
|
describe 'secret key' do
|
157
155
|
context 'when an AWS secret key is specified' do
|
158
156
|
it 'should boot with the proper options' do
|
159
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:aws_secret_key => 'CLI_KEY'))
|
160
157
|
FlareUp::CLI.start(required_arguments + %w(--aws_secret_key CLI_KEY))
|
158
|
+
expect(FlareUp::OptionStore.get(:aws_secret_key)).to eq('CLI_KEY')
|
161
159
|
end
|
162
160
|
end
|
163
161
|
context 'when an AWS secret key is not specified' do
|
164
162
|
context 'when the key is available via ENV' do
|
165
163
|
it 'should boot with the key from the environment' do
|
166
|
-
expect(FlareUp::Boot).to receive(:boot).with(required_options.merge(:aws_secret_key => 'TEST_AWS_SECRET_KEY'))
|
167
164
|
FlareUp::CLI.start(required_arguments)
|
165
|
+
expect(FlareUp::OptionStore.get(:aws_secret_key)).to eq('TEST_AWS_SECRET_KEY')
|
168
166
|
end
|
169
167
|
end
|
170
168
|
context 'when the key is not available via ENV' do
|
@@ -1,22 +1,55 @@
|
|
1
1
|
describe FlareUp::Emitter do
|
2
2
|
|
3
|
+
describe '.error' do
|
4
|
+
it 'should emit' do
|
5
|
+
expect(FlareUp::Emitter).to receive(:err).with("\x1b[31mTEST_MESSAGE")
|
6
|
+
FlareUp::Emitter.error('TEST_MESSAGE')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.success' do
|
11
|
+
it 'should emit' do
|
12
|
+
expect(FlareUp::Emitter).to receive(:out).with("\x1b[32mTEST_MESSAGE")
|
13
|
+
FlareUp::Emitter.success('TEST_MESSAGE')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.warn' do
|
18
|
+
it 'should emit' do
|
19
|
+
expect(FlareUp::Emitter).to receive(:err).with("\x1b[33mTEST_MESSAGE")
|
20
|
+
FlareUp::Emitter.warn('TEST_MESSAGE')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.info' do
|
25
|
+
it 'should emit' do
|
26
|
+
expect(FlareUp::Emitter).to receive(:out).with('TEST_MESSAGE')
|
27
|
+
FlareUp::Emitter.info('TEST_MESSAGE')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
3
31
|
describe '.sanitize' do
|
4
32
|
|
5
33
|
context 'when colorize output is disabled' do
|
6
34
|
before do
|
7
|
-
FlareUp::
|
35
|
+
FlareUp::OptionStore.store_option(:colorize_output, false)
|
8
36
|
end
|
9
37
|
it 'should remove color codes' do
|
10
|
-
expect(FlareUp::Emitter.sanitize
|
38
|
+
expect(FlareUp::Emitter.send(:sanitize, "\x1b[31mHello, World")).to eq('Hello, World')
|
11
39
|
end
|
12
40
|
end
|
13
41
|
|
14
42
|
context 'when a risky option is being output' do
|
15
43
|
before do
|
16
|
-
FlareUp::
|
44
|
+
FlareUp::OptionStore.store_options({
|
45
|
+
:aws_access_key => 'access',
|
46
|
+
:aws_secret_key => 'secret',
|
47
|
+
:redshift_username => 'user',
|
48
|
+
:redshift_password => 'pass'
|
49
|
+
})
|
17
50
|
end
|
18
51
|
it 'should hide it' do
|
19
|
-
expect(FlareUp::Emitter.sanitize
|
52
|
+
expect(FlareUp::Emitter.send(:sanitize, 'accesssecretuserpass')).to eq('REDACTEDREDACTEDREDACTEDREDACTED')
|
20
53
|
end
|
21
54
|
end
|
22
55
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
describe FlareUp::OptionStore do
|
2
|
+
|
3
|
+
describe '.store_option' do
|
4
|
+
it 'should store the specified option' do
|
5
|
+
FlareUp::OptionStore.store_option('name', 'value')
|
6
|
+
expect(FlareUp::OptionStore.get('name')).to eq('value')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.store_options' do
|
11
|
+
it 'should store all the options' do
|
12
|
+
FlareUp::OptionStore.store_options(:o1 => 'v1', :o2 => 'v2')
|
13
|
+
expect(FlareUp::OptionStore.get(:o1)).to eq('v1')
|
14
|
+
expect(FlareUp::OptionStore.get(:o2)).to eq('v2')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.get_options' do
|
19
|
+
let(:options) {{:o1 => 'v1', :o2 => 'v2'}}
|
20
|
+
it 'should return all options' do
|
21
|
+
FlareUp::OptionStore.store_options(options)
|
22
|
+
expect(FlareUp::OptionStore.get_options).to eq(options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.clear' do
|
27
|
+
it 'should remove all options' do
|
28
|
+
FlareUp::OptionStore.store_option('name', 'value')
|
29
|
+
FlareUp::OptionStore.clear
|
30
|
+
expect(FlareUp::OptionStore.get('name')).to eq(nil)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flare-up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Slifka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/flare_up/copy_command.rb
|
107
107
|
- lib/flare_up/emitter.rb
|
108
108
|
- lib/flare_up/env_wrap.rb
|
109
|
+
- lib/flare_up/option_store.rb
|
109
110
|
- lib/flare_up/stl_load_error.rb
|
110
111
|
- lib/flare_up/stl_load_error_fetcher.rb
|
111
112
|
- lib/flare_up/version.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- spec/lib/flare_up/connection_spec.rb
|
120
121
|
- spec/lib/flare_up/copy_command_spec.rb
|
121
122
|
- spec/lib/flare_up/emitter_spec.rb
|
123
|
+
- spec/lib/flare_up/option_store_spec.rb
|
122
124
|
- spec/lib/flare_up/stl_load_error_fetcher_spec.rb
|
123
125
|
- spec/lib/flare_up/stl_load_error_spec.rb
|
124
126
|
- spec/spec_helper.rb
|
@@ -151,6 +153,7 @@ test_files:
|
|
151
153
|
- spec/lib/flare_up/connection_spec.rb
|
152
154
|
- spec/lib/flare_up/copy_command_spec.rb
|
153
155
|
- spec/lib/flare_up/emitter_spec.rb
|
156
|
+
- spec/lib/flare_up/option_store_spec.rb
|
154
157
|
- spec/lib/flare_up/stl_load_error_fetcher_spec.rb
|
155
158
|
- spec/lib/flare_up/stl_load_error_spec.rb
|
156
159
|
- spec/spec_helper.rb
|