Class: Inspec::Resources::PostgresSession
- Inherits:
-
Object
- Object
- Inspec::Resources::PostgresSession
- Defined in:
- lib/inspec/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.
42 43 44 45 46 |
# File 'lib/inspec/resources/postgres_session.rb', line 42 def initialize(user, pass, host = nil) @user = user || "postgres" @pass = pass @host = host || "localhost" end |
Instance Method Details
#query(query, db = []) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/inspec/resources/postgres_session.rb', line 48 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 |