Class: Inspec::Resources::OpaCli
- Inherits:
-
Opa
- Object
- JsonConfig
- Opa
- Inspec::Resources::OpaCli
- Defined in:
- lib/inspec/resources/opa_cli.rb
Instance Attribute Summary
Attributes inherited from JsonConfig
Instance Method Summary collapse
- #allow ⇒ Object
-
#initialize(opts = {}) ⇒ OpaCli
constructor
A new instance of OpaCli.
- #to_s ⇒ Object
Methods inherited from Opa
Methods inherited from JsonConfig
Methods included from FileReader
Methods included from ObjectTraverser
Constructor Details
#initialize(opts = {}) ⇒ OpaCli
Returns a new instance of OpaCli.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/inspec/resources/opa_cli.rb', line 9 def initialize(opts = {}) @opa_executable_path = opts[:opa_executable_path] || "opa" # if this path is not provided then we will assume that it's been set in the ENV PATH @policy = opts[:policy] || nil @data = opts[:data] || nil @query = opts[:query] || nil if (@policy.nil? || @policy.empty?) || (@data.nil? || @data.empty?) || (@query.nil? || @query.empty?) fail_resource "OPA policy, data and query are mandatory." end @content = load_result super(@content) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Inspec::Resources::JsonConfig
Instance Method Details
#allow ⇒ Object
21 22 23 |
# File 'lib/inspec/resources/opa_cli.rb', line 21 def allow @content["result"][0]["expressions"][0]["value"] if @content["result"][0]["expressions"][0]["text"].include?("allow") end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/inspec/resources/opa_cli.rb', line 25 def to_s "OPA cli" end |