<commit_before># 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.

## 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' do
  hostname 'alice.example.com'
  user 'alice'
  port my_server_port
  use_identify_file :private
end
```

Following ssh config file is generated after the code is compiled.

```
#
# This config is generated by Nymphia 0.1.0
#

# 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 `load` method to load other Nymphia file like following example. Absolute path and relative path are acceptable as the file path.

```ruby
identity_file :private, '~/.ssh/id_rsa.1'

host 'alice', 'my server on VPS' do
  hostname 'alice.example.com'
  user 'alice'
  port 4321
  use_identify_file :private
end

load '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' do
  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,
  }
end
```

Following ssh config file is generated after the code is compiled.

```
#
# This config is generated by Nymphia 0.1.0
#

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' do
  hostname 'gw.example.com'
  user 'alice'
  port 19822
end

group 'company.ap-northeast-1' do
  use_gateway 'company.gateway'

  default_params do
    check_host_ip 'no'
    strict_host_key_checking 'no'
    user 'alice'
    port 9822
    use_identify_file :company, :company_gateway
  end

  host '*.apne.aws.example.com'

  host 'alice.apne.aws.example.com' do
    hostname '10.16.16.16'
    user 'white_rabbit'
    port 7777
  end
end
```

Following ssh config file is generated after the code is compiled.

```

#
# This config is generated by Nymphia 0.1.0
#

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<commit_msg>Change 0.1.0 -> 0.1.1 in README<commit_after># 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.

## 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' do
  hostname 'alice.example.com'
  user 'alice'
  port my_server_port
  use_identify_file :private
end
```

Following ssh config file is generated after the code is compiled.

```
#
# This config is generated by Nymphia 0.1.1
#

# 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 `load` method to load other Nymphia file like following example. Absolute path and relative path are acceptable as the file path.

```ruby
identity_file :private, '~/.ssh/id_rsa.1'

host 'alice', 'my server on VPS' do
  hostname 'alice.example.com'
  user 'alice'
  port 4321
  use_identify_file :private
end

load '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' do
  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,
  }
end
```

Following ssh config file is generated after the code is compiled.

```
#
# This config is generated by Nymphia 0.1.1
#

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' do
  hostname 'gw.example.com'
  user 'alice'
  port 19822
end

group 'company.ap-northeast-1' do
  use_gateway 'company.gateway'

  default_params do
    check_host_ip 'no'
    strict_host_key_checking 'no'
    user 'alice'
    port 9822
    use_identify_file :company, :company_gateway
  end

  host '*.apne.aws.example.com'

  host 'alice.apne.aws.example.com' do
    hostname '10.16.16.16'
    user 'white_rabbit'
    port 7777
  end
end
```

Following ssh config file is generated after the code is compiled.

```

#
# This config is generated by Nymphia 0.1.1
#

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
{'fraction_non_alphanumeric': 0.10373542707589817, 'fraction_numerical': 0.030454437306685702, 'mean_word_length': 3.6473189607517966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3412799', 'n_tokens_mistral': 3263, 'n_tokens_neox': 2938, 'n_words': 883}