Class: Inspec::Resources::OpaCli
- Inherits:
-
Opa
show all
- Defined in:
- lib/inspec/resources/opa_cli.rb
Instance Attribute Summary
Attributes inherited from JsonConfig
#params, #raw_content
Instance Method Summary
collapse
Methods inherited from Opa
#result
Methods inherited from JsonConfig
#method_missing, #value
Methods included from FileReader
#read_file_content
#extract_value
Constructor Details
#initialize(opts = {}) ⇒ OpaCli
Returns a new instance of OpaCli.
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/inspec/resources/opa_cli.rb', line 15
def initialize(opts = {})
@opa_executable_path = opts[:opa_executable_path] || "opa" @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
|
Instance Method Details
#allow ⇒ Object
27
28
29
|
# File 'lib/inspec/resources/opa_cli.rb', line 27
def allow
@content["result"][0]["expressions"][0]["value"] if @content["result"][0]["expressions"][0]["text"].include?("allow")
end
|
#resource_id ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/inspec/resources/opa_cli.rb', line 31
def resource_id
if @policy.nil? && @query.nil?
"opa_cli"
else
"#{@policy}:#{@query}"
end
end
|
#to_s ⇒ Object
39
40
41
|
# File 'lib/inspec/resources/opa_cli.rb', line 39
def to_s
"OPA cli"
end
|