sconb 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77df7796fba683040889ddc87e6d957771618e47
4
- data.tar.gz: cc503307d7d92872afe4eaf3875c672803097a65
3
+ metadata.gz: 633f856637a76bba26ed83506c62ea187aa37b68
4
+ data.tar.gz: 2953d0670461bd8331d956daa6584215028ca8c4
5
5
  SHA512:
6
- metadata.gz: 8e0fa3c7eb951ffdf2ed44364017b0485a741d56584244c7ad6d90c5e8b117a4c24c8c1835cecd0c33f6feebb2db7bcbcd907da728157f894dd9506e8f512f87
7
- data.tar.gz: b34a700c97f9880abccabc8de7c476deef36ebcc84cfba9dc15614d0181f686c71ea369b0228414ea84d6efcbdf8f4e6db84cd828d3c3eff27718b8b839f3a44
6
+ metadata.gz: 5d6a82afbe9aa090ccd9ac9844f053dd507c38f9a9ef9366e98c9a8a3855eb0046603a1e5b30f1b5493b8848982d884213b347d28ae1d632444c868e0236b328
7
+ data.tar.gz: fc8c2c6c76d245e35f25ee655d3a2b90f4ede37894e1c0fb40b6578017cd8e1007c1e9173cd87f4a490d1c43afe5c069ec9da7e96571bbf6d7e67f12812d9a24
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/README.md CHANGED
@@ -52,12 +52,8 @@ And append github.com config to .ssh/config
52
52
 
53
53
  ## Contributing
54
54
 
55
- 1. Fork it ( https://github.com/[my-github-username]/sconb/fork )
55
+ 1. Fork it ( https://github.com/k1LoW/sconb/fork )
56
56
  2. Create your feature branch (`git checkout -b my-new-feature`)
57
57
  3. Commit your changes (`git commit -am 'Add some feature'`)
58
58
  4. Push to the branch (`git push origin my-new-feature`)
59
59
  5. Create a new Pull Request
60
-
61
- ## TODO
62
-
63
- - Make test
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ end
8
+
data/lib/sconb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sconb
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/sconb.rb CHANGED
@@ -13,7 +13,10 @@ module Sconb
13
13
  path = options[:config]
14
14
  file = File.expand_path(path)
15
15
  configs = {}
16
- return configs unless File.readable?(file)
16
+ unless File.readable?(file)
17
+ puts configs
18
+ return
19
+ end
17
20
 
18
21
  allconfig = config_load(path, '*')
19
22
  configs['*'] = allconfig unless allconfig.size == 1
@@ -44,14 +47,11 @@ module Sconb
44
47
 
45
48
  desc "restore < dump.json > .ssh/config", "Restore .ssh/config from JSON"
46
49
  def restore()
47
- ssh_config = ''
48
- json = ''
49
- while str = $stdin.gets
50
- json << str
51
- end
50
+ ssh_configs = []
51
+ json = stdin_read
52
52
  configs = JSON.parse(json)
53
53
  configs.each do |host, config|
54
- ssh_config << "\n"
54
+ ssh_config = ''
55
55
  ssh_config << 'Host ' + host + "\n"
56
56
  config.each do |key, value|
57
57
  next if key.downcase == 'host' || key.downcase == 'identityfilecontent'
@@ -63,17 +63,15 @@ module Sconb
63
63
  ssh_config << ' ' + key + ' ' + value + "\n"
64
64
  end
65
65
  end
66
+ ssh_configs.push ssh_config
66
67
  end
67
- puts ssh_config
68
+ puts ssh_configs.join("\n")
68
69
  end
69
70
 
70
71
  method_option :force, :type => :boolean, :aliases => '-f', :default => false, :banner => 'force generate'
71
72
  desc "keyregen < dump.json", "Regenerate private keys from JSON"
72
73
  def keyregen()
73
- json = ''
74
- while str = $stdin.gets
75
- json << str
76
- end
74
+ json = $stdin.read
77
75
  configs = JSON.parse(json)
78
76
  configs.each do |host, config|
79
77
  config.each do |key, value|
@@ -82,7 +80,7 @@ module Sconb
82
80
  value.each_with_index do |keycontent,i|
83
81
  identity_file = File.expand_path(identity_files[i])
84
82
  if File.exists?(identity_file) and !options[:force]
85
- raise Thor::Error, "Error: key exists. If you want to overwrite, use --force option."
83
+ raise Thor::Error, "Error: " + identity_files[i] + " is exists. If you want to overwrite, use --force option."
86
84
  end
87
85
  puts 'Regenerate ' + identity_files[i] + ' ...'
88
86
  File.open(identity_file, 'w') do |file|
@@ -94,7 +92,12 @@ module Sconb
94
92
  end
95
93
  end
96
94
 
97
- # Original code Net::SSH::Config.load
95
+ private
96
+ def stdin_read()
97
+ return $stdin.read
98
+ end
99
+
100
+ # Original code is Net::SSH::Config.load (https://github.com/net-ssh/net-ssh/blob/master/LICENSE.txt)
98
101
  private
99
102
  def config_load(path, host)
100
103
  settings = {}
@@ -169,7 +172,7 @@ module Sconb
169
172
  end
170
173
 
171
174
  private
172
- # Original code Net::SSH::Config.pattern2regex
175
+ # Original code is Net::SSH::Config.pattern2regex (https://github.com/net-ssh/net-ssh/blob/master/LICENSE.txt)
173
176
  def pattern2regex(pattern)
174
177
  pattern = "^" + pattern.to_s.gsub(/\./, "\\.").
175
178
  gsub(/\?/, '.').
data/sconb.gemspec CHANGED
@@ -22,5 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency "json"
23
23
  spec.add_development_dependency "bundler", "~> 1.7"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
25
26
  spec.add_dependency "thor"
26
27
  end
data/spec/config_test ADDED
@@ -0,0 +1,7 @@
1
+ Host github.com
2
+ User git
3
+ Port 22
4
+ Hostname github.com
5
+ IdentityFile spec/github_rsa
6
+ TCPKeepAlive yes
7
+ IdentitiesOnly yes
@@ -0,0 +1,15 @@
1
+ Host github.com
2
+ User git
3
+ Port 22
4
+ Hostname github.com
5
+ IdentityFile spec/github_rsa
6
+ TCPKeepAlive yes
7
+ IdentitiesOnly yes
8
+
9
+ Host gist
10
+ User git
11
+ Port 22
12
+ Hostname gist.github.com
13
+ IdentityFile spec/github_rsa
14
+ TCPKeepAlive yes
15
+ IdentitiesOnly yes
data/spec/github_rsa ADDED
@@ -0,0 +1 @@
1
+ 1234567890
@@ -0,0 +1,141 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Sconb do
5
+ context '`dump` command' do
6
+
7
+ it "should convert from .ssh/config to JSON" do
8
+ expect(capture(:stdout) {
9
+ Sconb::CLI.new.invoke(:dump, [], {config: File.expand_path('../config_test', __FILE__)})
10
+ }).to eq <<OUT
11
+ {
12
+ "github.com": {
13
+ "Host": "github.com",
14
+ "User": "git",
15
+ "Port": "22",
16
+ "Hostname": "github.com",
17
+ "IdentityFile": [
18
+ "spec/github_rsa"
19
+ ],
20
+ "TCPKeepAlive": "yes",
21
+ "IdentitiesOnly": "yes"
22
+ }
23
+ }
24
+ OUT
25
+ end
26
+
27
+ it "should convert from multi config to JSON" do
28
+ expect(capture(:stdout) {
29
+ Sconb::CLI.new.invoke(:dump, [], {config: File.expand_path('../config_test_multi', __FILE__)})
30
+ }).to eq <<OUT
31
+ {
32
+ "github.com": {
33
+ "Host": "github.com",
34
+ "User": "git",
35
+ "Port": "22",
36
+ "Hostname": "github.com",
37
+ "IdentityFile": [
38
+ "spec/github_rsa"
39
+ ],
40
+ "TCPKeepAlive": "yes",
41
+ "IdentitiesOnly": "yes"
42
+ },
43
+ "gist": {
44
+ "Host": "gist",
45
+ "User": "git",
46
+ "Port": "22",
47
+ "Hostname": "gist.github.com",
48
+ "IdentityFile": [
49
+ "spec/github_rsa"
50
+ ],
51
+ "TCPKeepAlive": "yes",
52
+ "IdentitiesOnly": "yes"
53
+ }
54
+ }
55
+ OUT
56
+ end
57
+
58
+ it "should convert from .ssh/config to JSON with private keys" do
59
+ expect(capture(:stdout) {
60
+ Sconb::CLI.new.invoke(:dump, [], {config: File.expand_path('../config_test', __FILE__), all: true})
61
+ }).to eq <<OUT
62
+ {
63
+ "github.com": {
64
+ "Host": "github.com",
65
+ "User": "git",
66
+ "Port": "22",
67
+ "Hostname": "github.com",
68
+ "IdentityFile": [
69
+ "spec/github_rsa"
70
+ ],
71
+ "IdentityFileContent": [
72
+ "1234567890"
73
+ ],
74
+ "TCPKeepAlive": "yes",
75
+ "IdentitiesOnly": "yes"
76
+ }
77
+ }
78
+ OUT
79
+ end
80
+ end
81
+
82
+ context '`restore` command' do
83
+ before do
84
+ @cli = Sconb::CLI.new
85
+ allow(@cli).to receive_messages(:stdin_read => <<INN
86
+ {
87
+ "github.com": {
88
+ "Host": "github.com",
89
+ "User": "git",
90
+ "Port": "22",
91
+ "Hostname": "github.com",
92
+ "IdentityFile": [
93
+ "spec/github_rsa"
94
+ ],
95
+ "IdentityFileContent": [
96
+ "1234567890"
97
+ ],
98
+ "TCPKeepAlive": "yes",
99
+ "IdentitiesOnly": "yes"
100
+ },
101
+ "gist": {
102
+ "Host": "gist",
103
+ "User": "git",
104
+ "Port": "22",
105
+ "Hostname": "gist.github.com",
106
+ "IdentityFile": [
107
+ "spec/github_rsa"
108
+ ],
109
+ "IdentityFileContent": [
110
+ "1234567890"
111
+ ],
112
+ "TCPKeepAlive": "yes",
113
+ "IdentitiesOnly": "yes"
114
+ }
115
+ }
116
+ INN
117
+ )
118
+ end
119
+ it "should convert from JSON to config" do
120
+ expect(capture(:stdout) {
121
+ @cli.restore
122
+ }).to eq <<OUT
123
+ Host github.com
124
+ User git
125
+ Port 22
126
+ Hostname github.com
127
+ IdentityFile spec/github_rsa
128
+ TCPKeepAlive yes
129
+ IdentitiesOnly yes
130
+
131
+ Host gist
132
+ User git
133
+ Port 22
134
+ Hostname gist.github.com
135
+ IdentityFile spec/github_rsa
136
+ TCPKeepAlive yes
137
+ IdentitiesOnly yes
138
+ OUT
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'sconb'
3
+
4
+ # this method is written by wycats
5
+ def capture(stream)
6
+ begin
7
+ stream = stream.to_s
8
+ eval "$#{stream} = StringIO.new"
9
+ yield
10
+ result = eval("$#{stream}").string
11
+ ensure
12
+ eval("$#{stream} = #{stream.upcase}")
13
+ end
14
+
15
+ result
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sconb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: thor
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,7 @@ extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
91
105
  - ".gitignore"
106
+ - ".rspec"
92
107
  - Gemfile
93
108
  - LICENSE.txt
94
109
  - README.md
@@ -97,6 +112,11 @@ files:
97
112
  - lib/sconb.rb
98
113
  - lib/sconb/version.rb
99
114
  - sconb.gemspec
115
+ - spec/config_test
116
+ - spec/config_test_multi
117
+ - spec/github_rsa
118
+ - spec/sconb_spec.rb
119
+ - spec/spec_helper.rb
100
120
  homepage: ''
101
121
  licenses:
102
122
  - MIT
@@ -121,4 +141,9 @@ rubygems_version: 2.2.2
121
141
  signing_key:
122
142
  specification_version: 4
123
143
  summary: Ssh CONfig Buckup tool.
124
- test_files: []
144
+ test_files:
145
+ - spec/config_test
146
+ - spec/config_test_multi
147
+ - spec/github_rsa
148
+ - spec/sconb_spec.rb
149
+ - spec/spec_helper.rb