2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2019-01-10 00:06:48 +00:00
|
|
|
module MockAwsBillingReports
|
|
|
|
class Empty < AwsBackendBase
|
|
|
|
def describe_report_definitions(_query)
|
|
|
|
Aws::CostandUsageReportService::Types::DescribeReportDefinitionsResponse.new(report_definitions: [])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Basic < AwsBackendBase
|
|
|
|
def describe_report_definitions(_query)
|
|
|
|
Aws::CostandUsageReportService::Types::DescribeReportDefinitionsResponse
|
|
|
|
.new(report_definitions:
|
|
|
|
[
|
|
|
|
Aws::CostandUsageReportService::Types::ReportDefinition.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
report_name: "inspec1",
|
|
|
|
time_unit: "HOURLY",
|
|
|
|
format: "textORcsv",
|
|
|
|
compression: "ZIP",
|
|
|
|
s3_bucket: "inspec1-s3-bucket",
|
|
|
|
s3_prefix: "inspec1/accounting",
|
|
|
|
s3_region: "us-east-1"
|
2019-01-10 00:06:48 +00:00
|
|
|
),
|
|
|
|
Aws::CostandUsageReportService::Types::ReportDefinition.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
report_name: "inspec2",
|
|
|
|
time_unit: "DAILY",
|
|
|
|
format: "textORcsv",
|
|
|
|
compression: "GZIP",
|
|
|
|
s3_bucket: "inspec2-s3-bucket",
|
|
|
|
s3_prefix: "inspec2/accounting",
|
|
|
|
s3_region: "us-west-1"
|
2019-01-10 00:06:48 +00:00
|
|
|
),
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This backend will always repond with 5 reports, as if the `max_results` option was passed to
|
|
|
|
# `#describe_report_definitions`. I chose 5 because when using `max_results` in the real world
|
|
|
|
# it seems to only accept a value of 5.
|
|
|
|
#
|
|
|
|
# == Returns:
|
|
|
|
# A Aws::CostandUsageReportService::Types::DescribeReportDefinitionsRespons object with two instance
|
2019-02-12 23:02:54 +00:00
|
|
|
# properties:
|
2019-01-10 00:06:48 +00:00
|
|
|
# `report_definitions` An Array that includes a single page of 5 Reports.
|
|
|
|
# `next_token` A String set to the start of the next page. When `next_token` is nil, there are no more pages.
|
|
|
|
#
|
|
|
|
class Paginated < AwsBackendBase
|
|
|
|
|
|
|
|
# Generate a set of report data, and shuffle their order.
|
|
|
|
def generate_definitions
|
|
|
|
definitions = []
|
|
|
|
|
|
|
|
definitions << Aws::CostandUsageReportService::Types::ReportDefinition.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
report_name: "inspec1",
|
|
|
|
time_unit: "HOURLY",
|
|
|
|
format: "textORcsv",
|
|
|
|
compression: "ZIP",
|
|
|
|
s3_bucket: "inspec1-s3-bucket",
|
|
|
|
s3_prefix: "inspec1/accounting",
|
2019-07-09 00:20:30 +00:00
|
|
|
s3_region: "us-east-1"
|
|
|
|
)
|
2019-01-10 00:06:48 +00:00
|
|
|
definitions << Aws::CostandUsageReportService::Types::ReportDefinition.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
report_name: "inspec2",
|
|
|
|
time_unit: "DAILY",
|
|
|
|
format: "textORcsv",
|
|
|
|
compression: "GZIP",
|
|
|
|
s3_bucket: "inspec2-s3-bucket",
|
|
|
|
s3_prefix: "inspec2/accounting",
|
2019-07-09 00:20:30 +00:00
|
|
|
s3_region: "us-west-1"
|
|
|
|
)
|
2019-01-10 00:06:48 +00:00
|
|
|
|
|
|
|
(3..12).each do |i|
|
|
|
|
definitions <<
|
2019-06-11 22:24:35 +00:00
|
|
|
Aws::CostandUsageReportService::Types::ReportDefinition.new(
|
|
|
|
report_name: "inspec#{i}",
|
|
|
|
time_unit: %w{HOURLY DAILY}.sample,
|
|
|
|
format: "textORcsv",
|
|
|
|
compression: %w{ZIP GZIP}.sample,
|
|
|
|
s3_bucket: "inspec#{i}-s3-bucket",
|
|
|
|
s3_prefix: "inspec#{i}",
|
|
|
|
s3_region: "us-east-1"
|
|
|
|
)
|
2019-01-10 00:06:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
definitions.shuffle
|
|
|
|
end
|
|
|
|
|
|
|
|
def describe_report_definitions(options = {})
|
|
|
|
@definitions ||= generate_definitions
|
|
|
|
|
|
|
|
starting_position = options.fetch(:next_token, 0)
|
|
|
|
selected_definitions = @definitions.slice(starting_position, 5).compact
|
|
|
|
next_token = starting_position + 5
|
|
|
|
next_token = @definitions.count < next_token ? nil : next_token
|
|
|
|
|
|
|
|
response = Aws::CostandUsageReportService::Types::DescribeReportDefinitionsResponse
|
2019-07-09 00:20:30 +00:00
|
|
|
.new(report_definitions: selected_definitions)
|
2019-01-10 00:06:48 +00:00
|
|
|
response.next_token = next_token
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|