mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
2857d07151
The opening and closing mechanic varied between all the various resources. This changes them all to use a HEREDOC with a tilde to remove leading whitespace. This removes the need for the special method to trim the `#print_example` method from shell. Signed-off-by: Franklin Webber <franklin.webber@gmail.com>
70 lines
2.4 KiB
Ruby
70 lines
2.4 KiB
Ruby
require 'utils/filter'
|
|
|
|
class AwsBillingReports < Inspec.resource(1)
|
|
name 'aws_billing_reports'
|
|
supports platform: 'aws'
|
|
desc 'Verifies settings for AWS Cost and Billing Reports.'
|
|
example <<~EXAMPLE
|
|
describe aws_billing_reports do
|
|
its('report_names') { should include 'inspec1' }
|
|
its('s3_buckets') { should include 'inspec1-s3-bucket' }
|
|
end
|
|
|
|
describe aws_billing_reports.where { report_name =~ /inspec.*/ } do
|
|
its ('report_names') { should include ['inspec1'] }
|
|
its ('time_units') { should include ['DAILY'] }
|
|
its ('s3_buckets') { should include ['inspec1-s3-bucket'] }
|
|
end
|
|
EXAMPLE
|
|
|
|
include AwsPluralResourceMixin
|
|
|
|
filtertable = FilterTable.create
|
|
filtertable.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
|
.register_column(:report_names, field: :report_name)
|
|
.register_column(:time_units, field: :time_unit, style: :simple)
|
|
.register_column(:formats, field: :format, style: :simple)
|
|
.register_column(:compressions, field: :compression, style: :simple)
|
|
.register_column(:s3_buckets, field: :s3_bucket, style: :simple)
|
|
.register_column(:s3_prefixes, field: :s3_prefix, style: :simple)
|
|
.register_column(:s3_regions, field: :s3_region, style: :simple)
|
|
filtertable.install_filter_methods_on_resource(self, :table)
|
|
|
|
def validate_params(resource_params)
|
|
unless resource_params.empty?
|
|
raise ArgumentError, 'aws_billing_reports does not accept resource parameters.'
|
|
end
|
|
resource_params
|
|
end
|
|
|
|
def to_s
|
|
'AWS Billing Reports'
|
|
end
|
|
|
|
def fetch_from_api
|
|
@table = []
|
|
pagination_opts = {}
|
|
backend = BackendFactory.create(inspec_runner)
|
|
loop do
|
|
api_result = backend.describe_report_definitions(pagination_opts)
|
|
api_result.report_definitions.each do |raw_report|
|
|
report = raw_report.to_h
|
|
%i(time_unit compression).each { |field| report[field].downcase! }
|
|
@table << report
|
|
end
|
|
pagination_opts = { next_token: api_result.next_token }
|
|
break unless api_result.next_token
|
|
end
|
|
end
|
|
|
|
class Backend
|
|
class AwsClientApi < AwsBackendBase
|
|
AwsBillingReports::BackendFactory.set_default_backend(self)
|
|
self.aws_client_class = Aws::CostandUsageReportService::Client
|
|
|
|
def describe_report_definitions(options = {})
|
|
aws_service_client.describe_report_definitions(options)
|
|
end
|
|
end
|
|
end
|
|
end
|