taketo 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -2
- data/VERSION +1 -1
- data/bin/taketo +11 -0
- data/features/generate_ssh_config.feature +44 -0
- data/lib/taketo/ssh_config_generator_visitor.rb +36 -0
- data/lib/taketo.rb +0 -1
- data/spec/lib/taketo/ssh_config_generator_visitor_spec.rb +48 -0
- metadata +4 -1
data/README.md
CHANGED
@@ -138,9 +138,15 @@ Also it's possible to specify default server configuration for any scope (whole
|
|
138
138
|
|
139
139
|
Default configs are merged appropriately.
|
140
140
|
|
141
|
+
|
142
|
+
An SSH config file can be generated from taketo config. To do so, run ```taketo --generate-ssh-config```.
|
143
|
+
|
141
144
|
The Changelog:
|
142
145
|
--------------
|
143
146
|
|
147
|
+
### v0.0.10 (17.11.2012) ###
|
148
|
+
* Add ability to generate ssh config
|
149
|
+
|
144
150
|
### v0.0.9 (17.11.2012) ###
|
145
151
|
* Add default_command server config option
|
146
152
|
|
@@ -203,8 +209,6 @@ The Changelog:
|
|
203
209
|
TO-DO:
|
204
210
|
------
|
205
211
|
|
206
|
-
* Override default commands per server
|
207
212
|
* Define servers outside projects and environments
|
208
|
-
* Export SSH config (i.e. for scp)
|
209
213
|
* Destination completion
|
210
214
|
* Command completion
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/bin/taketo
CHANGED
@@ -46,9 +46,15 @@ def parse_options
|
|
46
46
|
end
|
47
47
|
|
48
48
|
opts.on("-v", "--view", "Show config contents and exit") do |v|
|
49
|
+
require 'taketo/config_printer_visitor'
|
49
50
|
options[:view] = v
|
50
51
|
end
|
51
52
|
|
53
|
+
opts.on("--generate-ssh-config", "Generate SSH config from taketo config") do |g|
|
54
|
+
require 'taketo/ssh_config_generator_visitor'
|
55
|
+
options[:generate_ssh_config] = g
|
56
|
+
end
|
57
|
+
|
52
58
|
opts.separator "Special options:"
|
53
59
|
|
54
60
|
opts.on("--dry-run", "Print out what would be run") do |v|
|
@@ -100,6 +106,11 @@ begin
|
|
100
106
|
config_printer = ConfigPrinterVisitor.new
|
101
107
|
traverser.visit_depth_first(config_printer)
|
102
108
|
puts config_printer.result
|
109
|
+
elsif options.delete(:generate_ssh_config)
|
110
|
+
traverser = ConfigTraverser.new(config)
|
111
|
+
ssh_config_generator = SSHConfigGeneratorVisitor.new
|
112
|
+
traverser.visit_depth_first(ssh_config_generator)
|
113
|
+
puts ssh_config_generator.result
|
103
114
|
else
|
104
115
|
server = resolver.resolve
|
105
116
|
server_command = remote_command(server, options)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Feature:
|
2
|
+
In order to eliminate duplication between taketo config and ssh config
|
3
|
+
As a user
|
4
|
+
I want to be able to convert taketo config to ssh config
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I have the following config
|
8
|
+
"""
|
9
|
+
project :foo do
|
10
|
+
environment :bar do
|
11
|
+
server do
|
12
|
+
host "bar.foo.com"
|
13
|
+
port 5678
|
14
|
+
user "pivo"
|
15
|
+
identity_file "~/.ssh/id_rsa"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
project :baz do
|
21
|
+
environment :qux do
|
22
|
+
server :bart do
|
23
|
+
global_alias :bazqux
|
24
|
+
host "2.3.4.5"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"""
|
29
|
+
|
30
|
+
Scenario: Generate ssh config
|
31
|
+
When I run taketo --generate-ssh-config
|
32
|
+
Then the output should contain exactly:
|
33
|
+
"""
|
34
|
+
Host bar.foo.com
|
35
|
+
Hostname bar.foo.com
|
36
|
+
Port 5678
|
37
|
+
User pivo
|
38
|
+
IdentityFile ~/.ssh/id_rsa
|
39
|
+
|
40
|
+
Host bazqux
|
41
|
+
Hostname 2.3.4.5
|
42
|
+
|
43
|
+
"""
|
44
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'taketo/config_visitor'
|
2
|
+
|
3
|
+
module Taketo
|
4
|
+
class SSHConfigGeneratorVisitor < ConfigVisitor
|
5
|
+
def initialize
|
6
|
+
@result = ""
|
7
|
+
end
|
8
|
+
|
9
|
+
visit Server do |server|
|
10
|
+
put "Host #{server.global_alias || server.host}"
|
11
|
+
put "Hostname #{server.host}"
|
12
|
+
put_optional "Port", server.port
|
13
|
+
put_optional "User", server.username
|
14
|
+
put_optional "IdentityFile", server.identity_file
|
15
|
+
put
|
16
|
+
end
|
17
|
+
|
18
|
+
visit Object do |_|
|
19
|
+
# catch all
|
20
|
+
end
|
21
|
+
|
22
|
+
def result
|
23
|
+
@result.chomp
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def put(str = "")
|
29
|
+
@result += str + "\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
def put_optional(str, value)
|
33
|
+
put "#{str} #{value}" if value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/taketo.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'taketo/ssh_config_generator_visitor'
|
3
|
+
|
4
|
+
include Taketo
|
5
|
+
|
6
|
+
describe "SSHConfigGeneratorVisitor" do
|
7
|
+
subject(:generator) { SSHConfigGeneratorVisitor.new }
|
8
|
+
|
9
|
+
describe "#visit_server" do
|
10
|
+
let(:server) { stub(:Server, :name => :sponge, :host => "bar.foo.com", :port => nil, :username => nil, :identity_file => nil, :global_alias => nil) }
|
11
|
+
|
12
|
+
it "renders available server info" do
|
13
|
+
server.stub(:port => 8000, :username => "bob", :identity_file => "path_to_identity_file")
|
14
|
+
generator.visit_server(server)
|
15
|
+
expect(generator.result).to include(<<-SSH.chomp)
|
16
|
+
Host bar.foo.com
|
17
|
+
Hostname bar.foo.com
|
18
|
+
Port 8000
|
19
|
+
User bob
|
20
|
+
IdentityFile path_to_identity_file
|
21
|
+
SSH
|
22
|
+
end
|
23
|
+
|
24
|
+
it "skips undefined options" do
|
25
|
+
generator.visit_server(server)
|
26
|
+
expect(generator.result).to include(<<-SSH.chomp)
|
27
|
+
Host bar.foo.com
|
28
|
+
Hostname bar.foo.com
|
29
|
+
SSH
|
30
|
+
end
|
31
|
+
|
32
|
+
it "prefers global alias as Hostname" do
|
33
|
+
server.stub(:global_alias => "bazqux")
|
34
|
+
generator.visit_server(server)
|
35
|
+
expect(generator.result).to include(<<-SSH.chomp)
|
36
|
+
Host bazqux
|
37
|
+
Hostname bar.foo.com
|
38
|
+
SSH
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "ignores non-server nodes" do
|
43
|
+
expect { generator.visit(1) }.not_to raise_error(/visit/)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taketo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/taketo/constructs_factory.rb
|
103
103
|
- lib/taketo/destination_resolver.rb
|
104
104
|
- lib/taketo/dsl.rb
|
105
|
+
- lib/taketo/ssh_config_generator_visitor.rb
|
105
106
|
- lib/taketo/support/key_error.rb
|
106
107
|
- lib/taketo/support/named_nodes_collection.rb
|
107
108
|
- lib/taketo/support.rb
|
@@ -122,6 +123,7 @@ files:
|
|
122
123
|
- spec/lib/taketo/constructs_factory_spec.rb
|
123
124
|
- spec/lib/taketo/destination_resolver_spec.rb
|
124
125
|
- spec/lib/taketo/dsl_spec.rb
|
126
|
+
- spec/lib/taketo/ssh_config_generator_visitor_spec.rb
|
125
127
|
- spec/lib/taketo/support/named_nodes_collection_spec.rb
|
126
128
|
- spec/spec_helper.rb
|
127
129
|
- spec/support/helpers/construct_spec_helper.rb
|
@@ -135,6 +137,7 @@ files:
|
|
135
137
|
- features/connect_to_server.feature
|
136
138
|
- features/default_server_config.feature
|
137
139
|
- features/error_handling.feature
|
140
|
+
- features/generate_ssh_config.feature
|
138
141
|
- features/help.feature
|
139
142
|
- features/step_definitions/main_steps.rb
|
140
143
|
- features/support/env.rb
|