active_record-ssh_tunnel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7425ebedb1646608ac1a5580935af9367ff01e7c
4
+ data.tar.gz: 81dae2ac29f51c24b965f101714a42a0caea6881
5
+ SHA512:
6
+ metadata.gz: c644a4d1952c71170f5c9a610cb0474297b87aff07b24f847637964d38b81690e3c06038abfd1789664b490fca33d668cfefa1c5182b23b8b91b2480d8fc8592
7
+ data.tar.gz: baefcd76065d8dc6fa6f213fb93780a6925cd8085f1880466b0f1dc739aeaf2730688a921591bf8bc80fc088e5133e71cb7741711e86729b8621e236ce5f949e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-ssh_tunnel.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Activerecord::SshTunnel
2
+
3
+ Connect ActiveRecord with SSH Tunnel
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'activerecord-ssh_tunnel'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install activerecord-ssh_tunnel
20
+
21
+ ## Usage
22
+
23
+ Add `ssh_tunnel_hostname` and `ssh_tunnel_user` to Your database.yml.
24
+
25
+ ```yml
26
+ development:
27
+ adapter: DB_ADAPTER
28
+ username: DB_USERNAME
29
+ password: DB_PASSWORD
30
+ host: DB_HOST
31
+ port: DB_PORT
32
+ database: DB_NAME
33
+ ssh_tunnel_hostname: SSH_GATEWAY_HOST
34
+ ssh_tunnel_user: SSH_USER # <%= ENV['USER'] %>
35
+ ```
36
+
37
+ or
38
+
39
+ ```ruby
40
+ class Item < ActiveRecord::Base
41
+ establish_connection(
42
+ adapter: DB_ADAPTER,
43
+ host: DB_HOST,
44
+ username: DB_USERNAME,
45
+ password: DB_PASSWORD,
46
+ database: DB_NAME,
47
+ port: DB_PORT,
48
+ ssh_tunnel_hostname: SSH_GATEWAY_HOST,
49
+ ssh_tunnel_user: SSH_USER,
50
+ ssh_tunnel_password: SSH_PASSWORD,
51
+ )
52
+ end
53
+ ```
54
+
55
+ ### Other ssh options...
56
+
57
+ Use the options of [Net::SSH](https://github.com/net-ssh/net-ssh) with `ssh_tunnel` prefix.
58
+
59
+ e.g. password
60
+
61
+ ```yml
62
+ ssh_tunnel_password: SSH_PASSWORD
63
+ ```
64
+
65
+ e.g keys
66
+
67
+ ```yml
68
+ ssh_tunnel_keys:
69
+ - "~/.ssh/ssh-key"
70
+ ```
71
+
72
+ ```ruby
73
+ ssh_tunnel_keys: ["~/.ssh/ssh-key"],
74
+ ```
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshiori/activerecord-ssh_tunnel.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_record/ssh_tunnel/version'
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "active_record-ssh_tunnel"
7
+ spec.version = ActiveRecord::SshTunnel::VERSION
8
+ spec.authors = ["Yoshiori SHOJI"]
9
+ spec.email = ["yoshiori@gmail.com"]
10
+
11
+ spec.summary = %q{Connect ActiveRecord with SSH Tunnel.}
12
+ spec.description = %q{Connect ActiveRecord with SSH Tunnel.}
13
+ spec.homepage = "https://github.com/yoshiori/activerecord-ssh_tunnel"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "net-ssh-gateway", "~> 1.2"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rails"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_record/ssh_tunnel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ require "active_record/ssh_tunnel/version"
2
+ require "net/ssh/gateway"
3
+ require "rails/railtie"
4
+
5
+ module ActiveRecord
6
+ module SshTunnel
7
+ class Railtie < ::Rails::Railtie
8
+ ActiveSupport.on_load(:active_record) do
9
+ ActiveRecord::Base.singleton_class.prepend ::ActiveRecord::SshTunnel
10
+ end
11
+ end
12
+
13
+ def establish_connection(spec = nil)
14
+ spec ||= ConnectionHandling::DEFAULT_ENV.call.to_sym
15
+ resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new configurations
16
+ spec = resolver.spec(spec)
17
+
18
+ if spec.config[:ssh_tunnel_hostname]
19
+ ssh_options = Hash[spec.config.keys.select { |key|
20
+ key.to_s.start_with? "ssh_tunnel_"
21
+ }.map{ |key|
22
+ [key.to_s.gsub("ssh_tunnel_", "").to_sym, spec.config[key]]
23
+ }]
24
+
25
+ port = Net::SSH::Gateway.new(
26
+ ssh_options.delete(:hostname),
27
+ ssh_options.delete(:user),
28
+ ssh_options,
29
+ ).open(spec.config[:host], spec.config[:port])
30
+
31
+ spec.config[:host] = "127.0.0.1"
32
+ spec.config[:port] = port
33
+ end
34
+
35
+ remove_connection
36
+ connection_handler.establish_connection self, spec
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module SshTunnel
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record-ssh_tunnel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiori SHOJI
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh-gateway
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Connect ActiveRecord with SSH Tunnel.
84
+ email:
85
+ - yoshiori@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - active_record-ssh_tunnel.gemspec
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/active_record/ssh_tunnel.rb
100
+ - lib/active_record/ssh_tunnel/version.rb
101
+ homepage: https://github.com/yoshiori/activerecord-ssh_tunnel
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Connect ActiveRecord with SSH Tunnel.
124
+ test_files: []