redshift-client 0.2.0 → 0.3.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 +4 -4
- data/lib/redshift/client.rb +2 -0
- data/lib/redshift/client/configuration.rb +43 -10
- data/lib/redshift/client/connection_handling.rb +1 -1
- data/lib/redshift/client/errors.rb +0 -3
- data/lib/redshift/client/loggable.rb +24 -0
- data/lib/redshift/client/version.rb +1 -1
- metadata +5 -8
- data/spec/redshift/client_spec.rb +0 -102
- data/spec/spec_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ccf86e0129abf8d78dd4b7551f1b6dad0d5aa76
|
4
|
+
data.tar.gz: aabd618f7ac00c951abfa34250dc3c27954697fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5a53fd03e12708b9f5d2e94bce1ae9f397faec83efafb3897b37d08a50123e0cbc4a63fd206750d81f48226b570706bbd653bf0f260298ba7a158e8ec1f0f23
|
7
|
+
data.tar.gz: dd412e3922d8c4add73479d784c9c31739cd85283a05ff0b620bac578a1af50578ee51d6fb507e97160760d4a183eee35bffc33975a22c2dc2023fbdb2ff4ac2
|
data/lib/redshift/client.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "redshift/client/version"
|
2
2
|
require "redshift/client/errors"
|
3
3
|
require "redshift/client/configuration"
|
4
|
+
require 'redshift/client/loggable'
|
4
5
|
require "redshift/client/connection"
|
5
6
|
require "redshift/client/connection_handling"
|
6
7
|
|
7
8
|
module Redshift
|
8
9
|
module Client
|
10
|
+
extend Loggable
|
9
11
|
extend ConnectionHandling
|
10
12
|
end
|
11
13
|
end
|
@@ -1,27 +1,59 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
2
4
|
|
3
5
|
module Redshift
|
4
6
|
module Client
|
5
7
|
class Configuration
|
6
8
|
attr_reader :host, :port, :user, :password, :dbname
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
DEFAULT_SSL_MODE = 'allow'.freeze
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def resolve(config = {})
|
14
|
+
config.reverse_merge!(parse_redshift_url)
|
15
|
+
|
16
|
+
Configuration.new(
|
17
|
+
config[:host],
|
18
|
+
config[:port],
|
19
|
+
config[:user],
|
20
|
+
config[:password],
|
21
|
+
config[:dbname],
|
22
|
+
config[:sslmode]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_redshift_url
|
29
|
+
uri = URI.parse(ENV['REDSHIFT_URL'])
|
30
|
+
{
|
31
|
+
host: uri.host,
|
32
|
+
port: uri.port,
|
33
|
+
user: uri.user,
|
34
|
+
password: uri.password,
|
35
|
+
dbname: uri.path[1..-1],
|
36
|
+
sslmode: sslmode(uri)
|
37
|
+
}
|
38
|
+
rescue
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
42
|
+
def sslmode(uri)
|
43
|
+
if uri.query
|
44
|
+
param = CGI.parse(uri.query)['sslmode']
|
45
|
+
param && param[0]
|
46
|
+
end
|
14
47
|
end
|
15
|
-
rescue => e
|
16
|
-
raise ConfigurationError.new(e.message)
|
17
48
|
end
|
18
49
|
|
19
|
-
def initialize(host, port, user, password, dbname)
|
50
|
+
def initialize(host, port, user, password, dbname, sslmode)
|
20
51
|
@host = host
|
21
52
|
@port = port || 5439
|
22
53
|
@user = user
|
23
54
|
@password = password
|
24
55
|
@dbname = dbname
|
56
|
+
@sslmode = sslmode || DEFAULT_SSL_MODE
|
25
57
|
end
|
26
58
|
|
27
59
|
def params
|
@@ -30,7 +62,8 @@ module Redshift
|
|
30
62
|
port: @port,
|
31
63
|
user: @user,
|
32
64
|
password: @password,
|
33
|
-
dbname: @dbname
|
65
|
+
dbname: @dbname,
|
66
|
+
sslmode: @sslmode
|
34
67
|
}
|
35
68
|
end
|
36
69
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Redshift
|
6
|
+
module Client
|
7
|
+
module Loggable
|
8
|
+
def logger
|
9
|
+
@logger || create_default_logger
|
10
|
+
end
|
11
|
+
|
12
|
+
def logger=(logger)
|
13
|
+
@logger = logger
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def create_default_logger
|
18
|
+
@logger = Logger.new($stdout)
|
19
|
+
@logger.level = Logger::INFO
|
20
|
+
@logger
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redshift-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dai Akatsuka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -101,10 +101,9 @@ files:
|
|
101
101
|
- lib/redshift/client/connection.rb
|
102
102
|
- lib/redshift/client/connection_handling.rb
|
103
103
|
- lib/redshift/client/errors.rb
|
104
|
+
- lib/redshift/client/loggable.rb
|
104
105
|
- lib/redshift/client/version.rb
|
105
106
|
- redshift-client.gemspec
|
106
|
-
- spec/redshift/client_spec.rb
|
107
|
-
- spec/spec_helper.rb
|
108
107
|
homepage: https://github.com/dakatsuka/redshift-client
|
109
108
|
licenses:
|
110
109
|
- MIT
|
@@ -125,10 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
124
|
version: '0'
|
126
125
|
requirements: []
|
127
126
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.6.11
|
129
128
|
signing_key:
|
130
129
|
specification_version: 4
|
131
130
|
summary: The ruby client for AWS Redshift.
|
132
|
-
test_files:
|
133
|
-
- spec/redshift/client_spec.rb
|
134
|
-
- spec/spec_helper.rb
|
131
|
+
test_files: []
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Redshift::Client do
|
4
|
-
it 'has a version number' do
|
5
|
-
expect(Redshift::Client::VERSION).not_to be nil
|
6
|
-
end
|
7
|
-
|
8
|
-
describe '#establish_connection' do
|
9
|
-
it 'establishes connection' do
|
10
|
-
expect {
|
11
|
-
Redshift::Client.establish_connection
|
12
|
-
}.to change {
|
13
|
-
Redshift::Client.established?
|
14
|
-
}.from(false).to(true)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#disconnect' do
|
19
|
-
before do
|
20
|
-
Redshift::Client.establish_connection
|
21
|
-
Redshift::Client.connection
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'disconnects from database' do
|
25
|
-
expect {
|
26
|
-
Redshift::Client.disconnect
|
27
|
-
}.to change {
|
28
|
-
Redshift::Client.connected?
|
29
|
-
}.from(true).to(false)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#connected?' do
|
34
|
-
context "when already connected" do
|
35
|
-
before do
|
36
|
-
Redshift::Client.establish_connection
|
37
|
-
Redshift::Client.connection
|
38
|
-
end
|
39
|
-
|
40
|
-
after do
|
41
|
-
Redshift::Client.disconnect
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns true" do
|
45
|
-
expect(Redshift::Client).to be_connected
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when not yet connected" do
|
50
|
-
it "returns false" do
|
51
|
-
expect(Redshift::Client).not_to be_connected
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#connection" do
|
57
|
-
context "when already established" do
|
58
|
-
before do
|
59
|
-
Redshift::Client.establish_connection
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns an instance of connection" do
|
63
|
-
expect(Redshift::Client.connection).to be_instance_of Redshift::Client::Connection
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when not yet established" do
|
68
|
-
before do
|
69
|
-
allow(ActiveSupport).to receive :run_load_hooks
|
70
|
-
end
|
71
|
-
|
72
|
-
it "calls ActiveSupport#run_load_hooks and raise error" do
|
73
|
-
Thread.new {
|
74
|
-
expect { Redshift::Client.connection }.to raise_error(Redshift::Client::ConnectionNotEstablished)
|
75
|
-
expect(ActiveSupport).to have_received(:run_load_hooks).with(:redshift_client_connection).once
|
76
|
-
}.join
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#established?" do
|
82
|
-
context "when already established" do
|
83
|
-
before do
|
84
|
-
Redshift::Client.establish_connection
|
85
|
-
end
|
86
|
-
|
87
|
-
after do
|
88
|
-
Redshift::Client.disconnect
|
89
|
-
end
|
90
|
-
|
91
|
-
it "returns true" do
|
92
|
-
expect(Redshift::Client).to be_established
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when not yet established" do
|
97
|
-
it "returns false" do
|
98
|
-
Thread.new { expect(Redshift::Client).not_to be_established }.join
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
data/spec/spec_helper.rb
DELETED