Class: Inspec::Resources::PostgresSession
- Inherits:
-
Object
- Object
- Inspec::Resources::PostgresSession
- Defined in:
- lib/resources/postgres_session.rb
Instance Method Summary collapse
-
#initialize(user, pass, host = nil) ⇒ PostgresSession
constructor
A new instance of PostgresSession.
- #query(query, db = []) ⇒ Object
Constructor Details
#initialize(user, pass, host = nil) ⇒ PostgresSession
Returns a new instance of PostgresSession.
43 44 45 46 47 |
# File 'lib/resources/postgres_session.rb', line 43 def initialize(user, pass, host = nil) @user = user || 'postgres' @pass = pass @host = host || 'localhost' end |
Instance Method Details
#query(query, db = []) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/resources/postgres_session.rb', line 49 def query(query, db = []) psql_cmd = create_psql_cmd(query, db) cmd = inspec.command(psql_cmd) out = cmd.stdout + "\n" + cmd.stderr if cmd.exit_status != 0 || out =~ /could not connect to .*/ || out.downcase =~ /^error:.*/ Lines.new(out, "PostgreSQL query with errors: #{query}") else Lines.new(cmd.stdout.strip, "PostgreSQL query: #{query}") end end |