mode 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mode/commands/login.rb +9 -1
- data/lib/mode/connector/data_source.rb +33 -9
- data/lib/mode/version.rb +1 -1
- data/spec/connector/data_source_spec.rb +4 -1
- data/spec/connector/scheduler_spec.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03a5f9840967c0b0a7b461ff7ebbef1ceee872f6
|
4
|
+
data.tar.gz: d207b4e636caaf13e1c43ae76aa86e556aba7825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0837b3b8b33c55de80fba1d1ecfc2b16dc47831658f5fee2da7387bff8fba4ea6022a3732b30b020fe8379a66624a8bfd9b53e31d006850eba8a17a3301fda
|
7
|
+
data.tar.gz: 2aff0e732ef9fa57dfec9702e41b14c3377a6a8fe3eded36e05c17c0d7e4a0ae82102b8cab4778878a0b6f8bfaee7d724987ec7f045e92a8cb7a789a70a81243
|
data/lib/mode/commands/login.rb
CHANGED
@@ -63,6 +63,12 @@ module Mode
|
|
63
63
|
end
|
64
64
|
elsif resource.status == 401
|
65
65
|
raise "Login failed, credentials invalid"
|
66
|
+
elsif resource.status == 404
|
67
|
+
raise "Login failed, access tokens not found"
|
68
|
+
elsif resource.status == 500
|
69
|
+
raise "Login failed, internal server error"
|
70
|
+
else
|
71
|
+
raise "Login failed, unknown error"
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
@@ -80,7 +86,9 @@ module Mode
|
|
80
86
|
def choose_access_token
|
81
87
|
access_tokens = fetch_access_tokens
|
82
88
|
|
83
|
-
if access_tokens.
|
89
|
+
if access_tokens.nil?
|
90
|
+
raise "Couldn't retrieve access tokens"
|
91
|
+
elsif access_tokens.length == 1
|
84
92
|
access_tokens.first
|
85
93
|
else
|
86
94
|
chosen = prompt_access_tokens(access_tokens)
|
@@ -30,34 +30,58 @@ module Mode
|
|
30
30
|
props['host']
|
31
31
|
end
|
32
32
|
|
33
|
+
def port
|
34
|
+
props['port']
|
35
|
+
end
|
36
|
+
|
33
37
|
def database
|
34
38
|
props['database']
|
35
39
|
end
|
36
40
|
|
41
|
+
def ssl_mode
|
42
|
+
props['sslmode'] || 'prefer'
|
43
|
+
end
|
44
|
+
|
37
45
|
def select(query, &block)
|
38
46
|
connection_dataset(query).each(&block)
|
39
47
|
end
|
40
48
|
|
41
49
|
def connection
|
42
|
-
|
43
|
-
@connection ||= Sequel.connect(connection_url,
|
44
|
-
:client_min_messages => '',
|
45
|
-
:force_standard_strings => false
|
46
|
-
)
|
47
|
-
else
|
48
|
-
@connection ||= Sequel.connect(connection_url)
|
49
|
-
end
|
50
|
+
@connection ||= Sequel.connect(connection_url, adapter_opts)
|
50
51
|
end
|
51
52
|
|
52
53
|
def redshift?
|
53
54
|
adapter == 'redshift'
|
54
55
|
end
|
55
56
|
|
57
|
+
def postgres?
|
58
|
+
adapter == 'postgres'
|
59
|
+
end
|
60
|
+
|
56
61
|
private
|
57
62
|
|
63
|
+
def adapter_opts
|
64
|
+
opts = {}
|
65
|
+
|
66
|
+
if redshift?
|
67
|
+
opts.merge!({
|
68
|
+
:sslmode => ssl_mode,
|
69
|
+
:client_min_messages => '',
|
70
|
+
:force_standard_strings => false
|
71
|
+
})
|
72
|
+
elsif postgres?
|
73
|
+
opts.merge!({
|
74
|
+
:sslmode => ssl_mode
|
75
|
+
})
|
76
|
+
end
|
77
|
+
|
78
|
+
opts
|
79
|
+
end
|
80
|
+
|
58
81
|
def connection_url
|
82
|
+
port_segment = port.nil? ? nil : ":#{port}"
|
59
83
|
password_segment = password.nil? ? nil : ":#{password}"
|
60
|
-
"#{adapter}://#{username}#{password_segment}@#{host}/#{database}"
|
84
|
+
"#{adapter}://#{username}#{password_segment}@#{host}#{port_segment}/#{database}"
|
61
85
|
end
|
62
86
|
|
63
87
|
def connection_dataset(query)
|
data/lib/mode/version.rb
CHANGED
@@ -54,9 +54,12 @@ describe Mode::Connector::DataSource do
|
|
54
54
|
it 'has a connection dataset' do
|
55
55
|
source = Mode::Connector::DataSource.new('dev', props)
|
56
56
|
|
57
|
+
dataset = double(:dataset, :with_sql => :dataset)
|
58
|
+
connection = double(:connection, :dataset => dataset)
|
59
|
+
Sequel.should_receive(:connect).and_return(connection)
|
57
60
|
dataset = source.send(:connection_dataset, "SELECT * FROM fake")
|
58
61
|
|
59
|
-
dataset.
|
62
|
+
dataset.should == :dataset
|
60
63
|
end
|
61
64
|
|
62
65
|
it "fetches results from dataset" do
|
@@ -25,6 +25,8 @@ describe Mode::Connector::Scheduler do
|
|
25
25
|
rufus.should_receive(:join).and_return(true)
|
26
26
|
rufus.should_receive(:stop).and_return(true)
|
27
27
|
|
28
|
+
Sequel.should_receive(:connect).and_return(:connect)
|
29
|
+
|
28
30
|
scheduler = Mode::Connector::Scheduler.new(data_sources)
|
29
31
|
|
30
32
|
scheduler.start!
|