Class: Inspec::Resources::OpaApi

Inherits:
Opa show all
Defined in:
lib/inspec/resources/opa_api.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

Methods included from ObjectTraverser

#extract_value

Constructor Details

#initialize(opts = {}) ⇒ OpaApi

Returns a new instance of OpaApi.



15
16
17
18
19
20
21
# File 'lib/inspec/resources/opa_api.rb', line 15

def initialize(opts = {})
  @url = opts[:url] || nil
  @data = opts[:data] || nil
  fail_resource "OPA url and data are mandatory." if @url.nil? || @url.empty? || @data.nil? || @data.empty?
  @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

#allowObject



23
24
25
# File 'lib/inspec/resources/opa_api.rb', line 23

def allow
  @content["result"]
end

#resource_idObject



27
28
29
# File 'lib/inspec/resources/opa_api.rb', line 27

def resource_id
  @url || "opa_api"
end

#to_sObject



31
32
33
# File 'lib/inspec/resources/opa_api.rb', line 31

def to_s
  "OPA api"
end