train-pgsql 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +52 -5
- data/lib/train-pgsql/connection.rb +8 -7
- data/lib/train-pgsql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b350bc75289acf2790bd703acea6fe334651aa0b57408a1efb40026f8728eab
|
4
|
+
data.tar.gz: 6be610b670d7839f092bf7496b62d9281c905e18933df18dc93dc584ca5e88c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a6e6455f31b4a2c254ff4e2165df2572656d26fa1021d96d9bcda302077a97b6c1df7c95ca17dfbb798a2a866f8a24228a87d66a895026f542dc2e8e9d99e1
|
7
|
+
data.tar.gz: 84f7f92b4d39d343e583e9ffbe4794413e149b0631ed10d396466cad439a3b3d204948a8a38c99591192018f5e53a7e07c5ac80d1e28581aa7d73d0be37049a9
|
data/README.md
CHANGED
@@ -5,11 +5,16 @@ This plugin allows applications that rely on Train to communicate via postgres S
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
|
9
|
-
Rubygems.Org. For this there is a rake task which makes this a one-liner:
|
8
|
+
This is published to rubygems.org at https://rubygems.org/gems/train-pgsql.
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
You can install the gem directly:
|
11
|
+
```sh
|
12
|
+
gem install train-pgsql
|
13
|
+
```
|
14
|
+
|
15
|
+
Or you can install it as an `inspec` plugin:
|
16
|
+
```sh
|
17
|
+
inspec plugin install train-pgsql
|
13
18
|
```
|
14
19
|
|
15
20
|
## Transport parameters
|
@@ -35,4 +40,46 @@ train = Train.create("pgsql", {
|
|
35
40
|
conn = train.connection
|
36
41
|
result = conn.run_command("show version\n")
|
37
42
|
conn.close
|
38
|
-
```
|
43
|
+
```
|
44
|
+
|
45
|
+
## Local development
|
46
|
+
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.
|
47
|
+
You can build it and run it in a docker container.
|
48
|
+
|
49
|
+
### Requirements
|
50
|
+
- Postgres running locally
|
51
|
+
- docker
|
52
|
+
|
53
|
+
### Steps
|
54
|
+
1) Build the `train-pgsql` gem
|
55
|
+
```
|
56
|
+
rake build
|
57
|
+
```
|
58
|
+
2) Build the docker image.
|
59
|
+
Be sure to set the appropriate GEM_VERSION arg based upon the value of the [version.rb](./lib/train-pgsql/version.rb)
|
60
|
+
```
|
61
|
+
docker build --build-arg GEM_VERSION=1.0.0 . -t train-pgsql-test
|
62
|
+
```
|
63
|
+
3) Run the test.rb file
|
64
|
+
```
|
65
|
+
docker run -it --rm -v $(pwd)/test:/share -e PG_HOST="host.docker.internal" --entrypoint ruby train-pgsql-test test.rb
|
66
|
+
```
|
67
|
+
_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._
|
68
|
+
|
69
|
+
You should see output resembling the following:
|
70
|
+
```
|
71
|
+
#<struct Train::Extras::CommandResult stdout="1", stderr="", exit_status=0>
|
72
|
+
```
|
73
|
+
|
74
|
+
## Deploy
|
75
|
+
To publish a new version to RubyGems:
|
76
|
+
1) Ensure the [version.rb](./lib/train-pgsql/version.rb) has been bumped with the appropriate semver update.
|
77
|
+
2) Run rake release
|
78
|
+
```
|
79
|
+
rake release
|
80
|
+
```
|
81
|
+
_Note: you may have to authenticate with rubygems to publish. The `deploy@stridehealth.com` group has a rubygems [account](https://rubygems.org/profiles/stridehealth) that is an owner of this gem._
|
82
|
+
|
83
|
+
# Acknowledgements
|
84
|
+
* [train-telnet](https://github.com/tecracer-chef/train-telnet)
|
85
|
+
* [train](https://github.com/inspec/train)
|
@@ -33,16 +33,17 @@ module TrainPlugins
|
|
33
33
|
exit_status = 0
|
34
34
|
|
35
35
|
logger.debug format('[Pgsql] Sending command (%s) to %s:%d', query, @options[:host], @options[:port])
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
begin
|
37
|
+
connection.exec(query) do |result|
|
38
|
+
result.each_row do |values|
|
39
|
+
stdout += values.join(', ') + "\n"
|
40
|
+
end
|
41
|
+
stdout = stdout.strip
|
39
42
|
end
|
40
|
-
|
43
|
+
rescue PG::Error => e
|
44
|
+
stderr = e.message
|
41
45
|
end
|
42
|
-
|
43
46
|
CommandResult.new(stdout, stderr, exit_status)
|
44
|
-
rescue PG::Error => e
|
45
|
-
raise Train::TransportError, "Pgsql exec failed (#{e.message})"
|
46
47
|
end
|
47
48
|
|
48
49
|
def connection
|
data/lib/train-pgsql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: train-pgsql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cris Barbero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|