sconb 0.0.5 → 0.0.6

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: 633f856637a76bba26ed83506c62ea187aa37b68
4
- data.tar.gz: 2953d0670461bd8331d956daa6584215028ca8c4
3
+ metadata.gz: 5c5e18b93db4b66082d25aa8c270858e572d6bd5
4
+ data.tar.gz: 50eb6adc5e2756f97797b33b898ea70e5f570fa4
5
5
  SHA512:
6
- metadata.gz: 5d6a82afbe9aa090ccd9ac9844f053dd507c38f9a9ef9366e98c9a8a3855eb0046603a1e5b30f1b5493b8848982d884213b347d28ae1d632444c868e0236b328
7
- data.tar.gz: fc8c2c6c76d245e35f25ee655d3a2b90f4ede37894e1c0fb40b6578017cd8e1007c1e9173cd87f4a490d1c43afe5c069ec9da7e96571bbf6d7e67f12812d9a24
6
+ metadata.gz: 2221bdfc63d7912663c82af6181fd0951d4aeff590a6c88b14c1e9e1feb34417af493667f650490ec446502037dfd39563ec78f38529faecb7d8b6127c0b966c
7
+ data.tar.gz: f25ff865d164c8b821385e54376f108a9a6baed156e1fcb66ae42629d29399391719a360eac5fb2a12b4487c59e8fb2ece143ecdfa23d6aa97e1f7a673d63cf3
data/lib/sconb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sconb
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/sconb.rb CHANGED
@@ -2,6 +2,7 @@ require "sconb/version"
2
2
  require "thor"
3
3
  require "net/ssh"
4
4
  require "json"
5
+ require "pp"
5
6
 
6
7
  module Sconb
7
8
  class CLI < Thor
@@ -14,12 +15,12 @@ module Sconb
14
15
  file = File.expand_path(path)
15
16
  configs = {}
16
17
  unless File.readable?(file)
17
- puts configs
18
+ puts configs
18
19
  return
19
20
  end
20
-
21
+
21
22
  allconfig = config_load(path, '*')
22
- configs['*'] = allconfig unless allconfig.size == 1
23
+ configs['*'] = allconfig unless allconfig.size <= 1
23
24
  IO.foreach(file) do |line|
24
25
  next if line =~ /^\s*(?:#.*)?$/
25
26
  if line =~ /^\s*(\S+)\s*=(.*)$/
@@ -28,23 +29,32 @@ module Sconb
28
29
  key, value = line.strip.split(/\s+/, 2)
29
30
  end
30
31
  next if value.nil?
31
- next unless key.downcase == 'host'
32
- negative_hosts, positive_hosts = value.to_s.split(/\s+/).partition { |h| h.start_with?('!') }
33
- positive_hosts.each do | host |
34
- next if host == '*'
35
- config = config_load(path, host)
36
-
37
- allconfig.each do |key, value|
38
- next unless config.key? key
39
- config.delete key if config[key] == allconfig[key]
32
+
33
+ # Host
34
+ if key.downcase == 'host'
35
+ negative_hosts, positive_hosts = value.to_s.split(/\s+/).partition { |h| h.start_with?('!') }
36
+ positive_hosts.each do | host |
37
+ next if host == '*'
38
+ config = config_load(path, host)
39
+
40
+ allconfig.each do |key, value|
41
+ next unless config.key? key
42
+ config.delete key if config[key] == allconfig[key]
43
+ end
44
+
45
+ configs[host] = config
40
46
  end
47
+ end
41
48
 
42
- configs[host] = config
49
+ # Match
50
+ if key.downcase == 'match'
51
+ configs[key + ' ' + value] = config_load(path, value)
43
52
  end
53
+
44
54
  end
45
55
  puts JSON.pretty_generate configs
46
56
  end
47
-
57
+
48
58
  desc "restore < dump.json > .ssh/config", "Restore .ssh/config from JSON"
49
59
  def restore()
50
60
  ssh_configs = []
@@ -52,9 +62,13 @@ module Sconb
52
62
  configs = JSON.parse(json)
53
63
  configs.each do |host, config|
54
64
  ssh_config = ''
55
- ssh_config << 'Host ' + host + "\n"
65
+ unless host.match(/^Match /)
66
+ ssh_config << 'Host ' + host + "\n"
67
+ else
68
+ ssh_config << host + "\n"
69
+ end
56
70
  config.each do |key, value|
57
- next if key.downcase == 'host' || key.downcase == 'identityfilecontent'
71
+ next if key.downcase == 'host' || key.downcase == 'match' || key.downcase == 'identityfilecontent'
58
72
  if key.downcase == 'identityfile'
59
73
  value.each_with_index do |keyfile,i|
60
74
  ssh_config << ' ' + key + ' ' + keyfile + "\n"
@@ -103,7 +117,7 @@ module Sconb
103
117
  settings = {}
104
118
  file = File.expand_path(path)
105
119
  return settings unless File.readable?(file)
106
-
120
+
107
121
  globals = {}
108
122
  matched_host = nil
109
123
  multi_host = []
@@ -136,9 +150,16 @@ module Sconb
136
150
  else
137
151
  matched_host = positive_hosts.select { |h| host =~ pattern2regex(h) }.first
138
152
  end
139
-
153
+ settings[key] = host unless matched_host.nil?
154
+ seen_host = true
155
+ elsif key.downcase == 'match'
156
+ if host == value
157
+ matched_host = true
158
+ else
159
+ matched_host = nil
160
+ end
161
+ settings[key] = host unless matched_host.nil?
140
162
  seen_host = true
141
- settings[key] = host
142
163
  elsif !seen_host
143
164
  if key.downcase == 'identityfile'
144
165
  (globals[key] ||= []) << value
@@ -6,10 +6,13 @@ Host github.com
6
6
  TCPKeepAlive yes
7
7
  IdentitiesOnly yes
8
8
 
9
+ Match exec "nmcli connection status id <ap-name> 2> /dev/null"
10
+ ProxyCommand ssh -W %h:%p github.com
11
+
9
12
  Host gist
10
13
  User git
11
14
  Port 22
12
15
  Hostname gist.github.com
13
16
  IdentityFile spec/github_rsa
14
17
  TCPKeepAlive yes
15
- IdentitiesOnly yes
18
+ IdentitiesOnly yes
data/spec/sconb_spec.rb CHANGED
@@ -40,6 +40,10 @@ OUT
40
40
  "TCPKeepAlive": "yes",
41
41
  "IdentitiesOnly": "yes"
42
42
  },
43
+ "Match exec \\"nmcli connection status id <ap-name> 2> /dev/null\\"": {
44
+ "Match": "exec \\"nmcli connection status id <ap-name> 2> /dev/null\\"",
45
+ "ProxyCommand": "ssh -W %h:%p github.com"
46
+ },
43
47
  "gist": {
44
48
  "Host": "gist",
45
49
  "User": "git",
@@ -111,6 +115,10 @@ OUT
111
115
  ],
112
116
  "TCPKeepAlive": "yes",
113
117
  "IdentitiesOnly": "yes"
118
+ },
119
+ "Match exec \\"nmcli connection status id <ap-name> 2> /dev/null\\"": {
120
+ "Match": "exec \\"nmcli connection status id <ap-name> 2> /dev/null\\"",
121
+ "ProxyCommand": "ssh -W %h:%p github.com"
114
122
  }
115
123
  }
116
124
  INN
@@ -135,6 +143,9 @@ Host gist
135
143
  IdentityFile spec/github_rsa
136
144
  TCPKeepAlive yes
137
145
  IdentitiesOnly yes
146
+
147
+ Match exec "nmcli connection status id <ap-name> 2> /dev/null"
148
+ ProxyCommand ssh -W %h:%p github.com
138
149
  OUT
139
150
  end
140
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sconb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW