Class: Pgsqlarbiter::Verdict

Inherits:
Data
  • Object
show all
Defined in:
lib/pgsqlarbiter/verdict.rb

Overview

Immutable result of judging a SQL query against an Arbiter's rules.

A Verdict tells you whether a query is allowed and, if not, exactly which checks failed. Use #allowed? for a quick boolean, #reasons for human-readable denial strings, or the individual fields for programmatic branching.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allowed ⇒ Boolean (readonly) Also known as: allowed?

Returns true when the query passes all checks.

Returns:

  • (Boolean) —

    true when the query passes all checks



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pgsqlarbiter/verdict.rb', line 21

Verdict = Data.define(:allowed, :statement_type_allowed, :statement_type,
                      :disallowed_tables, :disallowed_functions) do
  alias_method :allowed?, :allowed
  alias_method :statement_type_allowed?, :statement_type_allowed

  # Human-readable denial reasons. Empty when the query is allowed.
  #
  # @return [Array<String>] frozen list of reason strings
  def reasons
    r = []
    r << "statement type :#{statement_type} is not allowed" unless statement_type_allowed
    disallowed_tables.each { |t| r << "table #{t.inspect} is not allowed" }
    disallowed_functions.each { |f| r << "function #{f.inspect} is not allowed" }
    r.freeze
  end
end

#disallowed_functions ⇒ Array<String> (readonly)

Returns functions called by the query that are not whitelisted.

Returns:

  • (Array<String>) —

    functions called by the query that are not whitelisted



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pgsqlarbiter/verdict.rb', line 21

Verdict = Data.define(:allowed, :statement_type_allowed, :statement_type,
                      :disallowed_tables, :disallowed_functions) do
  alias_method :allowed?, :allowed
  alias_method :statement_type_allowed?, :statement_type_allowed

  # Human-readable denial reasons. Empty when the query is allowed.
  #
  # @return [Array<String>] frozen list of reason strings
  def reasons
    r = []
    r << "statement type :#{statement_type} is not allowed" unless statement_type_allowed
    disallowed_tables.each { |t| r << "table #{t.inspect} is not allowed" }
    disallowed_functions.each { |f| r << "function #{f.inspect} is not allowed" }
    r.freeze
  end
end

#disallowed_tables ⇒ Array<String> (readonly)

Returns tables referenced by the query that are not whitelisted.

Returns:

  • (Array<String>) —

    tables referenced by the query that are not whitelisted



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pgsqlarbiter/verdict.rb', line 21

Verdict = Data.define(:allowed, :statement_type_allowed, :statement_type,
                      :disallowed_tables, :disallowed_functions) do
  alias_method :allowed?, :allowed
  alias_method :statement_type_allowed?, :statement_type_allowed

  # Human-readable denial reasons. Empty when the query is allowed.
  #
  # @return [Array<String>] frozen list of reason strings
  def reasons
    r = []
    r << "statement type :#{statement_type} is not allowed" unless statement_type_allowed
    disallowed_tables.each { |t| r << "table #{t.inspect} is not allowed" }
    disallowed_functions.each { |f| r << "function #{f.inspect} is not allowed" }
    r.freeze
  end
end

#statement_type ⇒ Symbol (readonly)

Returns the query's actual statement type.

Returns:

  • (Symbol) —

    the query's actual statement type



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pgsqlarbiter/verdict.rb', line 21

Verdict = Data.define(:allowed, :statement_type_allowed, :statement_type,
                      :disallowed_tables, :disallowed_functions) do
  alias_method :allowed?, :allowed
  alias_method :statement_type_allowed?, :statement_type_allowed

  # Human-readable denial reasons. Empty when the query is allowed.
  #
  # @return [Array<String>] frozen list of reason strings
  def reasons
    r = []
    r << "statement type :#{statement_type} is not allowed" unless statement_type_allowed
    disallowed_tables.each { |t| r << "table #{t.inspect} is not allowed" }
    disallowed_functions.each { |f| r << "function #{f.inspect} is not allowed" }
    r.freeze
  end
end

#statement_type_allowed ⇒ Boolean (readonly) Also known as: statement_type_allowed?

Returns true when the statement type is in the whitelist.

Returns:

  • (Boolean) —

    true when the statement type is in the whitelist



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pgsqlarbiter/verdict.rb', line 21

Verdict = Data.define(:allowed, :statement_type_allowed, :statement_type,
                      :disallowed_tables, :disallowed_functions) do
  alias_method :allowed?, :allowed
  alias_method :statement_type_allowed?, :statement_type_allowed

  # Human-readable denial reasons. Empty when the query is allowed.
  #
  # @return [Array<String>] frozen list of reason strings
  def reasons
    r = []
    r << "statement type :#{statement_type} is not allowed" unless statement_type_allowed
    disallowed_tables.each { |t| r << "table #{t.inspect} is not allowed" }
    disallowed_functions.each { |f| r << "function #{f.inspect} is not allowed" }
    r.freeze
  end
end

Instance Method Details

#reasons ⇒ Array<String>

Human-readable denial reasons. Empty when the query is allowed.

Returns:

  • (Array<String>) —

    frozen list of reason strings



29
30
31
32
33
34
35
# File 'lib/pgsqlarbiter/verdict.rb', line 29

def reasons
  r = []
  r << "statement type :#{statement_type} is not allowed" unless statement_type_allowed
  disallowed_tables.each { |t| r << "table #{t.inspect} is not allowed" }
  disallowed_functions.each { |f| r << "function #{f.inspect} is not allowed" }
  r.freeze
end