# Nymphia [![Build Status](https://travis-ci.org/mozamimy/nymphia.svg?branch=master)](https://travis-ci.org/mozamimy/nymphia) Nymphia is a DSL to generate a ssh config file more structurally. You can use full Ruby syntax and useful methods provided by Nymphia. There is a Vim syntax ([nymphia.vim](https://github.com/mozamimy/nymphia.vim)) if you want to edit colorfully in Vim. ## Installation Just type gem command, ``` $ gem install nymphia ``` ## CLI interface ``` $ nymphia --help nymphia -f, --file=FILE Your DSL code file -o, --output=FILE Output file (default: stdout) ``` ## Getting started ### Basis Following code is a small example. ```ruby identity_file :private, '~/.ssh/id_rsa.1' my_server_port = 4321 host('alice', 'my server on VPS') { hostname 'alice.example.com' user 'alice' port my_server_port use_identify_file :private } ``` Following ssh config file is generated after the code is compiled. ``` # # This config is generated by Nymphia 0.1.2 # @ 2017-12-08T16:34:15+09:00 # # my server on VPS Host alice Hostname alice.example.com User alice Port 4321 IdentityFile ~/.ssh/id_rsa.1 ``` Method `identity_file` register your identity file with a name. You can use registered identity file by `use_identify_file` in `host` block. Method `host` generate `Host` directive. First argument is name of host, Second argument is description of the host. Description is optional. ### Splitting files You can use `include_file` method to include other Nymphia file like following example. Absolute path and relative path are acceptable as the file path. We could use `load` in previous version, but `load` is obsoleted now. ```ruby identity_file :private, '~/.ssh/id_rsa.1' host('alice', 'my server on VPS') { hostname 'alice.example.com' user 'alice' port 4321 use_identify_file :private } include_file 'other_nymphia_file.rb' ``` ### Proxy method Method `proxy` is almost same to `host`, but `local_forward` method can be used in `proxy`. Following code is small example of `proxy`. ```ruby identity_file :company_gateway, '~/.ssh/id_rsa.company.gw' proxy('awsproxy.company.apne1') { hostname 'gw.apne1.example.com' user 'alice' port 19822 use_identify_file :company_gateway # SOCKS proxy dynamic_forward 23921 # ssh tunnels local_forward 'mysql-server', { 'localhost' => 13306, 'mysql.apne.aws.example.com' => 3306, } local_forward 'ldap', { 'localhost' => 10389, 'ldap.apne.aws.example.com' => 398, } } ``` Following ssh config file is generated after the code is compiled. ``` # # This config is generated by Nymphia 0.1.2 # @ 2017-12-08T16:34:15+09:00 # Host awsproxy.company.apne1 Hostname gw.apne1.example.com User alice Port 19822 IdentityFile ~/.ssh/id_rsa.company.gw DynamicForward 23921 LocalForward localhost:13306 mysql.apne.aws.example.com:3306 LocalForward localhost:10389 ldap.apne.aws.example.com:398 ``` ### Advanced: Grouping and use_gateway, default_params Nymphia has `group` and `gateway` method to make ssh config more structurally. Following code is small example of grouping. ```ruby identity_file :company, '~/.ssh/id_rsa.company' identity_file :company_gateway, '~/.ssh/id_rsa.company.gw' gateway('company.gateway') { hostname 'gw.example.com' user 'alice' port 19822 } group('company.ap-northeast-1') { use_gateway 'company.gateway' default_params { check_host_ip 'no' strict_host_key_checking 'no' user 'alice' port 9822 use_identify_file :company, :company_gateway } host('*.apne.aws.example.com') host('alice.apne.aws.example.com') { hostname '10.16.16.16' user 'white_rabbit' port 7777 } } ``` Following ssh config file is generated after the code is compiled. ``` # # This config is generated by Nymphia 0.1.2 # @ 2017-12-08T16:34:15+09:00 # Host company.gateway Hostname gw.example.com User alice Port 19822 Host *.apne.aws.example.com CheckHostIp no StrictHostKeyChecking no User alice Port 9822 IdentityFile ~/.ssh/id_rsa.company IdentityFile ~/.ssh/id_rsa.company.gw ProxyCommand ssh company.gateway -q -W %h:%p Host alice.apne.aws.example.com CheckHostIp no StrictHostKeyChecking no IdentityFile ~/.ssh/id_rsa.company IdentityFile ~/.ssh/id_rsa.company.gw ProxyCommand ssh company.gateway -q -W %h:%p Hostname 10.16.16.16 User white_rabbit Port 7777 ``` Method `gateway` is almost same to `host`, but it can be used in a group by `use_gateway` method. When write `use_gateway` in a group, `ProxyCommand ssh #{gateway name} -q -W %h:%p` directive is added automatically to hosts in the group. Method `default_params` defines default parameters of hosts in the group including `default_params`. In this example, `host '*.apne.aws.example.com'` has no parameters, but `Host *.apne.aws.example.com` in result is filled by default parameters. The default parameters can be overide like `host 'alice.apne.aws.example.com'`. ## Vim syntax https://github.com/mozamimy/nymphia.vim ## Todo - [x] vim syntax - [ ] Test code - [x] CI ## Development 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. ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/mozamimy/nymphia. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).