mode 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mode/cli/connect.rb +12 -3
- data/lib/mode/commands/connect.rb +20 -7
- data/lib/mode/connector/data_source.rb +9 -4
- data/lib/mode/version.rb +1 -1
- data/spec/commands/connect_spec.rb +48 -4
- data/spec/commands/login_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d69ae05d944f46182074adaa084e4b22454862
|
4
|
+
data.tar.gz: 111e422dca6963652e892f4543f6b91d13d4bf1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f33ca37d31a1966328a8dadaef02eb0337aac0fcd28be3473b8d21ee50f777023132cfa886641a96b97804bc6d18e640c1bc3f6f101b9d7cc6344158f30a3acd
|
7
|
+
data.tar.gz: df765cb61dd992ec67ce3cd3fe11a04a65d8d45927ca0cb43a6ffa338a487211e5421e2fd24525e53d8c962671597bb34280b54c8ddf2eb594e6b39a5777502d
|
data/lib/mode/cli/connect.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
module Mode
|
2
2
|
module CLI
|
3
3
|
class Base < Thor
|
4
|
-
desc "connect
|
4
|
+
desc "connect COMMAND [-c CONCURRENCY]", "Connect external databases to Mode"
|
5
|
+
long_desc <<-LONGDESC
|
6
|
+
The connect command allows you to connect external databases to Mode's cloud tools.
|
7
|
+
This will make the data in these databases queryable and the schemas indexed and searchable.
|
8
|
+
|
9
|
+
Support values for COMMAND: start, stop, restart, status, verify
|
10
|
+
LONGDESC
|
5
11
|
option :concurrency, :aliases => :c, :default => 4
|
6
12
|
option :host, :default => 'www.modeanalytics.com'
|
7
|
-
def connect(command)
|
8
|
-
if
|
13
|
+
def connect(command = 'start')
|
14
|
+
if command == 'verify'
|
15
|
+
Mode::Commands::Connect.new(command, options).verify!
|
16
|
+
say "Success! All config and connectivity checks passed"
|
17
|
+
elsif ['start', 'status', 'stop', 'restart'].include?(command)
|
9
18
|
Mode::Commands::Connect.new(command, options).execute
|
10
19
|
else
|
11
20
|
say "Error: valid commands for connect are start, stop and restart"
|
@@ -6,31 +6,44 @@ module Mode
|
|
6
6
|
|
7
7
|
attr_reader :command
|
8
8
|
attr_reader :concurrency
|
9
|
-
attr_reader :configuration
|
10
9
|
|
11
10
|
def initialize(command, options = {})
|
12
11
|
@command = command
|
13
12
|
@concurrency = options[:concurrency] || 4
|
14
|
-
|
15
|
-
validate!
|
16
|
-
|
17
|
-
@configuration = Mode::Connector::Config.new(config_dir)
|
18
13
|
end
|
19
14
|
|
20
15
|
def execute
|
16
|
+
validate_config!
|
21
17
|
register! if ['start', 'restart'].include?(command)
|
22
18
|
spawn!
|
23
19
|
end
|
24
20
|
|
21
|
+
def verify!
|
22
|
+
validate_config!
|
23
|
+
configuration.data_sources.each do |data_source|
|
24
|
+
begin
|
25
|
+
unless data_source.connection.test_connection
|
26
|
+
raise StandardError.new("Unknown connection error")
|
27
|
+
end
|
28
|
+
rescue => err
|
29
|
+
raise "Error: Cannot connect to #{data_source.name}. #{err.message}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
private
|
26
35
|
|
27
|
-
def
|
36
|
+
def validate_config!
|
28
37
|
require_config!
|
29
38
|
require_credentials!
|
30
39
|
require_connect_config!
|
31
40
|
configure_api_requests!
|
32
41
|
end
|
33
42
|
|
43
|
+
def configuration
|
44
|
+
@configuration ||= Mode::Connector::Config.new(config_dir)
|
45
|
+
end
|
46
|
+
|
34
47
|
def register!
|
35
48
|
Mode::Connector::Registrar.new(configuration).perform!
|
36
49
|
end
|
@@ -38,7 +51,7 @@ module Mode
|
|
38
51
|
def spawn!
|
39
52
|
if command == 'restart'
|
40
53
|
spawn_restart!
|
41
|
-
elsif ['stop', 'start'].include?(command)
|
54
|
+
elsif ['stop', 'status', 'start'].include?(command)
|
42
55
|
spawn_command!(command)
|
43
56
|
else
|
44
57
|
raise "Unknown command #{command}"
|
@@ -65,7 +65,6 @@ module Mode
|
|
65
65
|
|
66
66
|
if redshift?
|
67
67
|
opts.merge!({
|
68
|
-
:sslmode => ssl_mode,
|
69
68
|
:client_min_messages => '',
|
70
69
|
:force_standard_strings => false
|
71
70
|
})
|
@@ -78,10 +77,16 @@ module Mode
|
|
78
77
|
opts
|
79
78
|
end
|
80
79
|
|
80
|
+
def port_segment
|
81
|
+
port.nil? ? nil : ":#{port}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def password_segment
|
85
|
+
password.nil? ? nil : ":#{password}"
|
86
|
+
end
|
87
|
+
|
81
88
|
def connection_url
|
82
|
-
|
83
|
-
password_segment = password.nil? ? nil : ":#{password}"
|
84
|
-
"#{adapter}://#{username}#{password_segment}@#{host}#{port_segment}/#{database}"
|
89
|
+
"#{adapter}://#{username}#{password_segment}@#{host}#{port_segment}/#{database}"
|
85
90
|
end
|
86
91
|
|
87
92
|
def connection_dataset(query)
|
data/lib/mode/version.rb
CHANGED
@@ -2,8 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mode::Commands::Connect do
|
4
4
|
let(:tmpdir) { Dir.mktmpdir }
|
5
|
-
let(:config) { Mode::
|
6
|
-
|
5
|
+
let(:config) { Mode::Config.init(tmpdir) }
|
6
|
+
let(:connect_config) { Mode::Connector::Config.init(tmpdir) }
|
7
|
+
|
8
|
+
let(:data_source) {
|
9
|
+
Mode::Connector::DataSource.new('testdb', {
|
10
|
+
'adapter' => 'postgres',
|
11
|
+
'host' => 'localhost',
|
12
|
+
'username' => 'postgres',
|
13
|
+
'database' => 'warehouse',
|
14
|
+
'password' => nil
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
7
18
|
before do
|
8
19
|
initialize_logger
|
9
20
|
end
|
@@ -13,12 +24,11 @@ describe Mode::Commands::Connect do
|
|
13
24
|
|
14
25
|
connect.command.should == 'start'
|
15
26
|
connect.concurrency.should == 4
|
16
|
-
connect.configuration.should_not == nil
|
17
27
|
end
|
18
28
|
|
19
29
|
it "registers connector" do
|
20
30
|
connect = Mode::Commands::Connect.new('start')
|
21
|
-
|
31
|
+
|
22
32
|
registrar = double(:registrar, :perform! => true)
|
23
33
|
Mode::Connector::Registrar.should_receive(:new).and_return(registrar)
|
24
34
|
|
@@ -43,6 +53,7 @@ describe Mode::Commands::Connect do
|
|
43
53
|
|
44
54
|
it 'spawns with the start command' do
|
45
55
|
connect = Mode::Commands::Connect.new('start')
|
56
|
+
|
46
57
|
Mode::Connector::Daemon.should_receive(:spawn!).and_return(true)
|
47
58
|
|
48
59
|
connect.send(:spawn!)
|
@@ -50,6 +61,7 @@ describe Mode::Commands::Connect do
|
|
50
61
|
|
51
62
|
it 'spawns with the restart command' do
|
52
63
|
connect = Mode::Commands::Connect.new('restart')
|
64
|
+
|
53
65
|
Mode::Connector::Daemon.should_receive(:spawn!).twice.and_return(true)
|
54
66
|
|
55
67
|
connect.send(:spawn!)
|
@@ -57,6 +69,7 @@ describe Mode::Commands::Connect do
|
|
57
69
|
|
58
70
|
it 'spawns with the stop command' do
|
59
71
|
connect = Mode::Commands::Connect.new('stop')
|
72
|
+
|
60
73
|
Mode::Connector::Daemon.should_receive(:spawn!).and_return(true)
|
61
74
|
|
62
75
|
connect.send(:spawn!)
|
@@ -64,6 +77,7 @@ describe Mode::Commands::Connect do
|
|
64
77
|
|
65
78
|
it 'raises on spawn if the command is unrecognized' do
|
66
79
|
connect = Mode::Commands::Connect.new('fake')
|
80
|
+
|
67
81
|
Mode::Connector::Daemon.should_not_receive(:spawn!)
|
68
82
|
|
69
83
|
expect { connect.send(:spawn!) }.to raise_error
|
@@ -77,4 +91,34 @@ describe Mode::Commands::Connect do
|
|
77
91
|
|
78
92
|
connect.execute
|
79
93
|
end
|
94
|
+
|
95
|
+
it 'verifies configuration and connectivity' do
|
96
|
+
connect = Mode::Commands::Connect.new('verify')
|
97
|
+
|
98
|
+
connect.stub(:config_dir).and_return(tmpdir)
|
99
|
+
connect.should_receive(:validate_config!).and_return(true)
|
100
|
+
|
101
|
+
conn = double(:conn, :test_connection => true)
|
102
|
+
sources = double(:source, :connection => conn)
|
103
|
+
config = double(:config, :data_sources => [sources])
|
104
|
+
|
105
|
+
connect.should_receive(:configuration).and_return(config)
|
106
|
+
|
107
|
+
connect.verify!
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should raise if a connection fails to connect' do
|
111
|
+
connect = Mode::Commands::Connect.new('verify')
|
112
|
+
|
113
|
+
connect.stub(:config_dir).and_return(tmpdir)
|
114
|
+
connect.should_receive(:validate_config!).and_return(true)
|
115
|
+
|
116
|
+
conn = double(:conn, :test_connection => false)
|
117
|
+
sources = double(:source, :name => 'name', :connection => conn)
|
118
|
+
config = double(:config, :data_sources => [sources])
|
119
|
+
|
120
|
+
connect.should_receive(:configuration).and_return(config)
|
121
|
+
|
122
|
+
expect { connect.verify! }.to raise_error
|
123
|
+
end
|
80
124
|
end
|
data/spec/commands/login_spec.rb
CHANGED
@@ -168,6 +168,7 @@ describe Mode::Commands::Login do
|
|
168
168
|
command = Mode::Commands::Login.new(:test => true)
|
169
169
|
Mode::API::Request.should_receive(:get).with(:access_tokens).and_return(tokens_resource)
|
170
170
|
|
171
|
+
command.stub(:say)
|
171
172
|
command.should_receive(:ask).and_return("2")
|
172
173
|
|
173
174
|
chosen_token = command.send(:choose_access_token)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mode Analytics
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|