inspec-core 7.0.38.beta → 7.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/etc/deprecations.json +29 -0
- data/inspec-core.gemspec +14 -7
- data/lib/inspec/archive/tar.rb +1 -0
- data/lib/inspec/backend.rb +2 -0
- data/lib/inspec/base_cli.rb +12 -2
- data/lib/inspec/cached_fetcher.rb +2 -1
- data/lib/inspec/cli.rb +2 -0
- data/lib/inspec/dependencies/cache.rb +9 -13
- data/lib/inspec/dsl.rb +6 -1
- data/lib/inspec/fetcher/gem.rb +41 -23
- data/lib/inspec/fetcher/git.rb +21 -1
- data/lib/inspec/file_provider.rb +1 -0
- data/lib/inspec/input_registry.rb +1 -1
- data/lib/inspec/metadata.rb +2 -0
- data/lib/inspec/plugin/v2/gem_source_manager.rb +8 -1
- data/lib/inspec/plugin/v2/installer.rb +23 -2
- data/lib/inspec/plugin/v2/loader.rb +3 -1
- data/lib/inspec/profile.rb +12 -3
- data/lib/inspec/reporters/automate.rb +2 -2
- data/lib/inspec/resources/audit_policy.rb +8 -2
- data/lib/inspec/resources/auditd.rb +1 -1
- data/lib/inspec/resources/port.rb +2 -2
- data/lib/inspec/resources/postgres_session.rb +9 -5
- data/lib/inspec/resources/ssh_config.rb +215 -0
- data/lib/inspec/resources/ssh_key.rb +124 -0
- data/lib/inspec/resources/sshd_active_config.rb +2 -0
- data/lib/inspec/resources/sshd_config.rb +2 -0
- data/lib/inspec/resources/yum.rb +1 -1
- data/lib/inspec/resources.rb +2 -2
- data/lib/inspec/rule.rb +2 -0
- data/lib/inspec/runner.rb +16 -2
- data/lib/inspec/utils/deprecated_core_resources_list.rb +25 -0
- data/lib/inspec/utils/licensing_config.rb +15 -1
- data/lib/inspec/utils/parser.rb +19 -9
- data/lib/inspec/utils/simpleconfig.rb +2 -0
- data/lib/inspec/utils/telemetry/run_context_probe.rb +5 -2
- data/lib/inspec/utils/telemetry.rb +3 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/inspec/waiver_file_reader.rb +35 -18
- data/lib/inspec.rb +2 -0
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +4 -2
- data/lib/plugins/shared/core_plugin_test_helper.rb +1 -1
- data/lib/source_readers/inspec.rb +1 -1
- metadata +84 -22
- data/lib/inspec/resources/opa.rb +0 -26
- data/lib/inspec/resources/opa_api.rb +0 -49
- data/lib/inspec/resources/opa_cli.rb +0 -57
@@ -5,6 +5,8 @@ require "inspec/utils/waivers/json_file_reader"
|
|
5
5
|
module Inspec
|
6
6
|
class WaiverFileReader
|
7
7
|
|
8
|
+
SUPPORTED_FILE_EXTENSION = %w{.yaml .yml .csv .json}.freeze
|
9
|
+
|
8
10
|
def self.fetch_waivers_by_profile(profile_id, files)
|
9
11
|
read_waivers_from_file(profile_id, files) if @waivers_data.nil? || @waivers_data[profile_id].nil?
|
10
12
|
@waivers_data[profile_id]
|
@@ -15,14 +17,10 @@ module Inspec
|
|
15
17
|
output = {}
|
16
18
|
|
17
19
|
files.each do |file_path|
|
18
|
-
|
19
|
-
output.merge!(data) if !data.nil? && data.is_a?(Hash)
|
20
|
+
next unless valid_waiver_file?(file_path)
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
"Cannot find parser for waivers file." \
|
24
|
-
"Check to make sure file has the appropriate extension."
|
25
|
-
end
|
22
|
+
data = parse_waiver_file(file_path)
|
23
|
+
output.merge!(data) if data.is_a?(Hash)
|
26
24
|
rescue Inspec::Exceptions::WaiversFileNotReadable, Inspec::Exceptions::WaiversFileInvalidFormatting => e
|
27
25
|
Inspec::Log.error "Error reading waivers file #{file_path}. #{e.message}"
|
28
26
|
Inspec::UI.new.exit(:usage_error)
|
@@ -31,21 +29,38 @@ module Inspec
|
|
31
29
|
@waivers_data[profile_id] = output
|
32
30
|
end
|
33
31
|
|
34
|
-
def self.
|
35
|
-
|
36
|
-
file_extension = File.extname(file_path)
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
def self.valid_waiver_file?(file_path)
|
33
|
+
# Check if the file is readable
|
34
|
+
file_extension = File.extname(file_path).downcase
|
35
|
+
unless SUPPORTED_FILE_EXTENSION.include?(file_extension)
|
36
|
+
raise Inspec::Exceptions::WaiversFileNotReadable,
|
37
|
+
"Unsupported file extension for '#{file_path}'. Allowed waiver file extensions: #{SUPPORTED_FILE_EXTENSION.join(", ")}"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Check if the file is empty
|
41
|
+
if File.zero?(file_path)
|
42
|
+
Inspec::Log.warn "Waivers file '#{file_path}' is empty. Skipping waivers."
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.parse_waiver_file(file_path)
|
50
|
+
file_extension = File.extname(file_path).downcase
|
51
|
+
|
52
|
+
case file_extension
|
53
|
+
when ".yaml", ".yml"
|
54
|
+
data = Secrets::YAML.resolve(file_path)&.inputs
|
40
55
|
validate_json_yaml(data)
|
41
|
-
|
56
|
+
when ".csv"
|
42
57
|
data = Waivers::CSVFileReader.resolve(file_path)
|
43
|
-
|
44
|
-
|
45
|
-
elsif file_extension == ".json"
|
58
|
+
validate_csv_headers(Waivers::CSVFileReader.headers)
|
59
|
+
when ".json"
|
46
60
|
data = Waivers::JSONFileReader.resolve(file_path)
|
47
|
-
validate_json_yaml(data)
|
61
|
+
validate_json_yaml(data)
|
48
62
|
end
|
63
|
+
|
49
64
|
data
|
50
65
|
end
|
51
66
|
|
@@ -81,6 +96,8 @@ module Inspec
|
|
81
96
|
end
|
82
97
|
|
83
98
|
def self.validate_json_yaml(data)
|
99
|
+
return if data.nil?
|
100
|
+
|
84
101
|
missing_required_field = false
|
85
102
|
data.each do |key, value|
|
86
103
|
# In case of yaml or json we need to validate headers/parametes for each value
|
data/lib/inspec.rb
CHANGED
@@ -425,8 +425,10 @@ module InspecPlugins
|
|
425
425
|
"our apologies for the misunderstanding, and open an issue " \
|
426
426
|
"at https://github.com/inspec/inspec/issues/new")
|
427
427
|
ui.exit Inspec::UI::EXIT_PLUGIN_ERROR
|
428
|
-
rescue Inspec::Plugin::V2::InstallError
|
429
|
-
|
428
|
+
rescue Inspec::Plugin::V2::InstallError => e
|
429
|
+
# This change is required for Ruby 3.3 upgrade
|
430
|
+
# Using Inspec::Log::level breaks with error `undefined method nil` in Ruby log library
|
431
|
+
Inspec::Log.debug e.backtrace
|
430
432
|
|
431
433
|
results = installer.search(plugin_name, exact: true)
|
432
434
|
source_host = URI(options[:source] || "https://rubygems.org/").host
|
@@ -12,7 +12,7 @@ require "tmpdir" unless defined?(Dir.mktmpdir)
|
|
12
12
|
require "pathname" unless defined?(Pathname)
|
13
13
|
require "forwardable" unless defined?(Forwardable)
|
14
14
|
|
15
|
-
|
15
|
+
require_relative "../../../test/functional/helper"
|
16
16
|
require "inspec/plugin/v2"
|
17
17
|
|
18
18
|
# Configure Minitest to expose things like `let`
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.
|
4
|
+
version: 7.0.95
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef InSpec Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-telemetry
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
version: '0.20'
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 1.
|
62
|
+
version: 1.5.0
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -69,7 +69,7 @@ dependencies:
|
|
69
69
|
version: '0.20'
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: 1.
|
72
|
+
version: 1.5.0
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: method_source
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
version: 1.2.2
|
100
100
|
- - "<"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '4.0'
|
103
103
|
type: :runtime
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 1.2.2
|
110
110
|
- - "<"
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: '
|
112
|
+
version: '4.0'
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rspec
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,16 +134,22 @@ dependencies:
|
|
134
134
|
name: rspec-its
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- - "
|
137
|
+
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '1.2'
|
140
|
+
- - "<"
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '3.0'
|
140
143
|
type: :runtime
|
141
144
|
prerelease: false
|
142
145
|
version_requirements: !ruby/object:Gem::Requirement
|
143
146
|
requirements:
|
144
|
-
- - "
|
147
|
+
- - ">="
|
145
148
|
- !ruby/object:Gem::Version
|
146
149
|
version: '1.2'
|
150
|
+
- - "<"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.0'
|
147
153
|
- !ruby/object:Gem::Dependency
|
148
154
|
name: pry
|
149
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -288,7 +294,7 @@ dependencies:
|
|
288
294
|
requirements:
|
289
295
|
- - ">="
|
290
296
|
- !ruby/object:Gem::Version
|
291
|
-
version: '1.
|
297
|
+
version: '1.3'
|
292
298
|
- - "<"
|
293
299
|
- !ruby/object:Gem::Version
|
294
300
|
version: '2.1'
|
@@ -298,7 +304,7 @@ dependencies:
|
|
298
304
|
requirements:
|
299
305
|
- - ">="
|
300
306
|
- !ruby/object:Gem::Version
|
301
|
-
version: '1.
|
307
|
+
version: '1.3'
|
302
308
|
- - "<"
|
303
309
|
- !ruby/object:Gem::Version
|
304
310
|
version: '2.1'
|
@@ -325,7 +331,7 @@ dependencies:
|
|
325
331
|
version: '1.5'
|
326
332
|
- - "<"
|
327
333
|
- !ruby/object:Gem::Version
|
328
|
-
version: '
|
334
|
+
version: '3.0'
|
329
335
|
type: :runtime
|
330
336
|
prerelease: false
|
331
337
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -335,7 +341,7 @@ dependencies:
|
|
335
341
|
version: '1.5'
|
336
342
|
- - "<"
|
337
343
|
- !ruby/object:Gem::Version
|
338
|
-
version: '
|
344
|
+
version: '3.0'
|
339
345
|
- !ruby/object:Gem::Dependency
|
340
346
|
name: semverse
|
341
347
|
requirement: !ruby/object:Gem::Requirement
|
@@ -364,6 +370,54 @@ dependencies:
|
|
364
370
|
- - "~>"
|
365
371
|
- !ruby/object:Gem::Version
|
366
372
|
version: '2.0'
|
373
|
+
- !ruby/object:Gem::Dependency
|
374
|
+
name: syslog
|
375
|
+
requirement: !ruby/object:Gem::Requirement
|
376
|
+
requirements:
|
377
|
+
- - "~>"
|
378
|
+
- !ruby/object:Gem::Version
|
379
|
+
version: '0.1'
|
380
|
+
type: :runtime
|
381
|
+
prerelease: false
|
382
|
+
version_requirements: !ruby/object:Gem::Requirement
|
383
|
+
requirements:
|
384
|
+
- - "~>"
|
385
|
+
- !ruby/object:Gem::Version
|
386
|
+
version: '0.1'
|
387
|
+
- !ruby/object:Gem::Dependency
|
388
|
+
name: csv
|
389
|
+
requirement: !ruby/object:Gem::Requirement
|
390
|
+
requirements:
|
391
|
+
- - "~>"
|
392
|
+
- !ruby/object:Gem::Version
|
393
|
+
version: '3.0'
|
394
|
+
type: :runtime
|
395
|
+
prerelease: false
|
396
|
+
version_requirements: !ruby/object:Gem::Requirement
|
397
|
+
requirements:
|
398
|
+
- - "~>"
|
399
|
+
- !ruby/object:Gem::Version
|
400
|
+
version: '3.0'
|
401
|
+
- !ruby/object:Gem::Dependency
|
402
|
+
name: ostruct
|
403
|
+
requirement: !ruby/object:Gem::Requirement
|
404
|
+
requirements:
|
405
|
+
- - ">="
|
406
|
+
- !ruby/object:Gem::Version
|
407
|
+
version: '0.1'
|
408
|
+
- - "<"
|
409
|
+
- !ruby/object:Gem::Version
|
410
|
+
version: '0.7'
|
411
|
+
type: :runtime
|
412
|
+
prerelease: false
|
413
|
+
version_requirements: !ruby/object:Gem::Requirement
|
414
|
+
requirements:
|
415
|
+
- - ">="
|
416
|
+
- !ruby/object:Gem::Version
|
417
|
+
version: '0.1'
|
418
|
+
- - "<"
|
419
|
+
- !ruby/object:Gem::Version
|
420
|
+
version: '0.7'
|
367
421
|
- !ruby/object:Gem::Dependency
|
368
422
|
name: cookstyle
|
369
423
|
requirement: !ruby/object:Gem::Requirement
|
@@ -382,30 +436,36 @@ dependencies:
|
|
382
436
|
name: train-core
|
383
437
|
requirement: !ruby/object:Gem::Requirement
|
384
438
|
requirements:
|
439
|
+
- - "~>"
|
440
|
+
- !ruby/object:Gem::Version
|
441
|
+
version: '3.13'
|
385
442
|
- - ">="
|
386
443
|
- !ruby/object:Gem::Version
|
387
|
-
version: 3.
|
444
|
+
version: 3.13.4
|
388
445
|
type: :runtime
|
389
446
|
prerelease: false
|
390
447
|
version_requirements: !ruby/object:Gem::Requirement
|
391
448
|
requirements:
|
449
|
+
- - "~>"
|
450
|
+
- !ruby/object:Gem::Version
|
451
|
+
version: '3.13'
|
392
452
|
- - ">="
|
393
453
|
- !ruby/object:Gem::Version
|
394
|
-
version: 3.
|
454
|
+
version: 3.13.4
|
395
455
|
- !ruby/object:Gem::Dependency
|
396
456
|
name: chef-licensing
|
397
457
|
requirement: !ruby/object:Gem::Requirement
|
398
458
|
requirements:
|
399
459
|
- - ">="
|
400
460
|
- !ruby/object:Gem::Version
|
401
|
-
version: 1.0
|
461
|
+
version: 1.2.0
|
402
462
|
type: :runtime
|
403
463
|
prerelease: false
|
404
464
|
version_requirements: !ruby/object:Gem::Requirement
|
405
465
|
requirements:
|
406
466
|
- - ">="
|
407
467
|
- !ruby/object:Gem::Version
|
408
|
-
version: 1.0
|
468
|
+
version: 1.2.0
|
409
469
|
description: |+
|
410
470
|
InSpec provides a framework for creating end-to-end infrastructure tests. You can use it for integration or even compliance testing. Create fully portable test profiles and use them in your workflow to ensure stability and security. Integrate InSpec in your change lifecycle for local testing, CI/CD, and deployment verification.
|
411
471
|
This has local support only. See the `inspec` gem for full support.
|
@@ -620,9 +680,6 @@ files:
|
|
620
680
|
- lib/inspec/resources/npm.rb
|
621
681
|
- lib/inspec/resources/ntp_conf.rb
|
622
682
|
- lib/inspec/resources/oneget.rb
|
623
|
-
- lib/inspec/resources/opa.rb
|
624
|
-
- lib/inspec/resources/opa_api.rb
|
625
|
-
- lib/inspec/resources/opa_cli.rb
|
626
683
|
- lib/inspec/resources/oracle.rb
|
627
684
|
- lib/inspec/resources/oracledb_conf.rb
|
628
685
|
- lib/inspec/resources/oracledb_listener_conf.rb
|
@@ -656,6 +713,10 @@ files:
|
|
656
713
|
- lib/inspec/resources/selinux.rb
|
657
714
|
- lib/inspec/resources/service.rb
|
658
715
|
- lib/inspec/resources/shadow.rb
|
716
|
+
- lib/inspec/resources/ssh_config.rb
|
717
|
+
- lib/inspec/resources/ssh_key.rb
|
718
|
+
- lib/inspec/resources/sshd_active_config.rb
|
719
|
+
- lib/inspec/resources/sshd_config.rb
|
659
720
|
- lib/inspec/resources/ssl.rb
|
660
721
|
- lib/inspec/resources/sys_info.rb
|
661
722
|
- lib/inspec/resources/systemd_service.rb
|
@@ -712,6 +773,7 @@ files:
|
|
712
773
|
- lib/inspec/utils/convert.rb
|
713
774
|
- lib/inspec/utils/database_helpers.rb
|
714
775
|
- lib/inspec/utils/deprecated_cloud_resources_list.rb
|
776
|
+
- lib/inspec/utils/deprecated_core_resources_list.rb
|
715
777
|
- lib/inspec/utils/deprecation.rb
|
716
778
|
- lib/inspec/utils/deprecation/config_file.rb
|
717
779
|
- lib/inspec/utils/deprecation/deprecator.rb
|
@@ -884,11 +946,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
884
946
|
version: 3.1.0
|
885
947
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
886
948
|
requirements:
|
887
|
-
- - "
|
949
|
+
- - ">="
|
888
950
|
- !ruby/object:Gem::Version
|
889
|
-
version:
|
951
|
+
version: '0'
|
890
952
|
requirements: []
|
891
|
-
rubygems_version: 3.
|
953
|
+
rubygems_version: 3.3.27
|
892
954
|
signing_key:
|
893
955
|
specification_version: 4
|
894
956
|
summary: Infrastructure and compliance testing. Core library.
|
data/lib/inspec/resources/opa.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "inspec/resources/json"
|
2
|
-
|
3
|
-
module Inspec::Resources
|
4
|
-
class Opa < JsonConfig
|
5
|
-
name "opa"
|
6
|
-
supports platform: "unix"
|
7
|
-
supports platform: "windows"
|
8
|
-
|
9
|
-
def initialize(content)
|
10
|
-
@content = content
|
11
|
-
super({ content: @content })
|
12
|
-
end
|
13
|
-
|
14
|
-
def result
|
15
|
-
@content == {} || @content["result"].empty? ? nil : @content
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def parse(content)
|
21
|
-
@content = YAML.load(content)
|
22
|
-
rescue => e
|
23
|
-
raise Inspec::Exceptions::ResourceFailed, "Unable to parse OPA query output: #{e.message}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require "inspec/resources/opa"
|
2
|
-
|
3
|
-
module Inspec::Resources
|
4
|
-
class OpaApi < Opa
|
5
|
-
name "opa_api"
|
6
|
-
supports platform: "unix"
|
7
|
-
supports platform: "windows"
|
8
|
-
|
9
|
-
example <<~EXAMPLE
|
10
|
-
describe opa_api(url: "localhost:8181/v1/data/example/violation", data: "input.json") do
|
11
|
-
its(["result"]) { should eq 'value' }
|
12
|
-
end
|
13
|
-
EXAMPLE
|
14
|
-
|
15
|
-
def initialize(opts = {})
|
16
|
-
@url = opts[:url] || nil
|
17
|
-
@data = opts[:data] || nil
|
18
|
-
fail_resource "OPA url and data are mandatory." if @url.nil? || @url.empty? || @data.nil? || @data.empty?
|
19
|
-
@content = load_result
|
20
|
-
super(@content)
|
21
|
-
end
|
22
|
-
|
23
|
-
def allow
|
24
|
-
@content["result"]
|
25
|
-
end
|
26
|
-
|
27
|
-
def resource_id
|
28
|
-
@url || "opa_api"
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"OPA api"
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def load_result
|
38
|
-
raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
|
39
|
-
|
40
|
-
result = inspec.command("curl -X POST #{@url} -d @#{@data} -H 'Content-Type: application/json'")
|
41
|
-
if result.exit_status == 0
|
42
|
-
result.stdout.gsub("\n", "")
|
43
|
-
else
|
44
|
-
error = result.stdout + "\n" + result.stderr
|
45
|
-
raise Inspec::Exceptions::ResourceFailed, "Error while executing OPA query: #{error}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require "inspec/resources/opa"
|
2
|
-
|
3
|
-
module Inspec::Resources
|
4
|
-
class OpaCli < Opa
|
5
|
-
name "opa_cli"
|
6
|
-
supports platform: "unix"
|
7
|
-
supports platform: "windows"
|
8
|
-
|
9
|
-
example <<~EXAMPLE
|
10
|
-
describe opa_cli(policy: "example.rego", data: "input.json", query: "data.example.allow") do
|
11
|
-
its(["result"]) { should eq "value" }
|
12
|
-
end
|
13
|
-
EXAMPLE
|
14
|
-
|
15
|
-
def initialize(opts = {})
|
16
|
-
@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
|
17
|
-
@policy = opts[:policy] || nil
|
18
|
-
@data = opts[:data] || nil
|
19
|
-
@query = opts[:query] || nil
|
20
|
-
if (@policy.nil? || @policy.empty?) || (@data.nil? || @data.empty?) || (@query.nil? || @query.empty?)
|
21
|
-
fail_resource "OPA policy, data and query are mandatory."
|
22
|
-
end
|
23
|
-
@content = load_result
|
24
|
-
super(@content)
|
25
|
-
end
|
26
|
-
|
27
|
-
def allow
|
28
|
-
@content["result"][0]["expressions"][0]["value"] if @content["result"][0]["expressions"][0]["text"].include?("allow")
|
29
|
-
end
|
30
|
-
|
31
|
-
def resource_id
|
32
|
-
if @policy.nil? && @query.nil?
|
33
|
-
"opa_cli"
|
34
|
-
else
|
35
|
-
"#{@policy}:#{@query}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_s
|
40
|
-
"OPA cli"
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def load_result
|
46
|
-
raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
|
47
|
-
|
48
|
-
result = inspec.command("#{@opa_executable_path} eval -i '#{@data}' -d '#{@policy}' '#{@query}'")
|
49
|
-
if result.exit_status == 0
|
50
|
-
result.stdout.gsub("\n", "")
|
51
|
-
else
|
52
|
-
error = result.stdout + "\n" + result.stderr
|
53
|
-
raise Inspec::Exceptions::ResourceFailed, "Error while executing OPA query: #{error}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|