mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Fix aws-iam-users pagination (#2761)
* Fix aws-iam-users pagination PROBLEM: aws-iam-users resource only retrieves 100 records due to pagination in the AWS IAM list_users function. FIX: Iterate over all the pages using the AWS pagination variables `marker` and `is_truncated` Signed-off-by: Richard Nixon <richard.nixon@btinternet.com>
This commit is contained in:
parent
c2dcb11f52
commit
47e4c578e0
2 changed files with 15 additions and 3 deletions
|
@ -37,9 +37,21 @@ class AwsIamUsers < Inspec.resource(1)
|
|||
raw_params
|
||||
end
|
||||
|
||||
def fetch_from_api_paginated(backend)
|
||||
table = []
|
||||
page_marker = nil
|
||||
loop do
|
||||
api_result = backend.list_users(marker: page_marker)
|
||||
table += api_result.users.map(&:to_h)
|
||||
page_marker = api_result.marker
|
||||
break unless api_result.is_truncated
|
||||
end
|
||||
table
|
||||
end
|
||||
|
||||
def fetch_from_api
|
||||
backend = BackendFactory.create(inspec_runner)
|
||||
@table = backend.list_users.users.map(&:to_h)
|
||||
@table = fetch_from_api_paginated(backend)
|
||||
|
||||
# TODO: lazy columns - https://github.com/chef/inspec-aws/issues/100
|
||||
@table.each do |user|
|
||||
|
|
|
@ -103,7 +103,7 @@ module Maiusb
|
|||
# Empty - No users
|
||||
# --------------------------------
|
||||
class Empty < AwsBackendBase
|
||||
def list_users
|
||||
def list_users(criteria = {})
|
||||
OpenStruct.new({
|
||||
users: []
|
||||
})
|
||||
|
@ -128,7 +128,7 @@ module Maiusb
|
|||
# Carol has a password and MFA device
|
||||
class Basic < AwsBackendBase
|
||||
# arn, path, user_id omitted
|
||||
def list_users
|
||||
def list_users(criteria = {})
|
||||
OpenStruct.new({
|
||||
users: [
|
||||
OpenStruct.new({
|
||||
|
|
Loading…
Reference in a new issue