train-pgsql - Train Plugin for connecting via pgsql
This plugin allows applications that rely on Train to communicate via postgres SQL.
Installation
This is published to rubygems.org at https://rubygems.org/gems/train-pgsql.
You can install the gem directly:
gem install train-pgsql
Or you can install it as an inspec plugin:
inspec plugin install train-pgsql
Transport parameters
| Option | Explanation | Default | 
|---|---|---|
| host | Hostname | (required) | 
| user | Username to connect | (required) | 
| password | Password to connect | (required) | 
| database | Database to connect | postgres | 
| port | Remote port | 5432 | 
Example use
This will work for a Cisco IOS XE device with Telnet enabled:
require "train"
train  = Train.create("pgsql", {
            host:     "localhost",
            user:     "username",
            password: "password",
         })
conn   = train.connection
result = conn.run_command("show version\n")
conn.close
Local development
If you are building this on a Mac you may run into an issue trying to install this locally due to the PG gem not installing due to code signing issues.
You can build it and run it in a docker container.
Requirements
- Postgres running locally
- docker
Steps
1) Build the train-pgsql gem
   rake build
2) Build the docker image. Be sure to set the appropriate GEM_VERSION arg based upon the value of the version.rb
   docker build --build-arg GEM_VERSION=1.0.0 . -t train-pgsql-test 
3) Run the test.rb file
   docker run -it --rm -v $(pwd)/test:/share -e PG_HOST="host.docker.internal" --entrypoint ruby train-pgsql-test test.rb
Note: This test assumes you are running postgres locally on a mac. If you are running postgres in some other location, update the PG_HOST environment variable appropriately. You may have to set the username/password in the pgsql train instantiation.
You should see output resembling the following:
   #<struct Train::Extras::CommandResult stdout="1", stderr="", exit_status=0>
Deploy
To publish a new version to RubyGems: 1) Ensure the version.rb has been bumped with the appropriate semver update. 2) Run rake release
   rake release
Note: you may have to authenticate with rubygems to publish. The [email protected] group has a rubygems account that is an owner of this gem.