diff --git a/src/services/iamUser/data.ts b/src/services/iamUser/data.ts index b63386c2..0493943d 100644 --- a/src/services/iamUser/data.ts +++ b/src/services/iamUser/data.ts @@ -303,7 +303,7 @@ export const listVirtualMFADevices = async ( try { iam.listVirtualMFADevices( args, - async (err: AWSError, data: ListVirtualMFADevicesResponse) => { + (err: AWSError, data: ListVirtualMFADevicesResponse) => { if (err) { errorLog.generateAwsErrorLog({ functionName: 'iam:listVirtualMFADevices', @@ -311,12 +311,14 @@ export const listVirtualMFADevices = async ( }) } - const { VirtualMFADevices = [], IsTruncated, Marker } = data + if (!isEmpty(data)) { + const { VirtualMFADevices = [], IsTruncated, Marker } = data - virtualMFADeviceList.push(...VirtualMFADevices) + virtualMFADeviceList.push(...VirtualMFADevices) - if (IsTruncated) { - listAllVirtualMFADevices(Marker) + if (IsTruncated) { + listAllVirtualMFADevices(Marker) + } } resolve(virtualMFADeviceList) @@ -345,14 +347,6 @@ export const listIamUsers = async ( iam.listUsers( { Marker: marker }, async (err: AWSError, data: ListUsersResponse) => { - /** - * No data - */ - - if (isEmpty(data)) { - return resolve(result) - } - if (err) { errorLog.generateAwsErrorLog({ functionName: 'iam:listUsers', @@ -360,6 +354,11 @@ export const listIamUsers = async ( }) } + // No data + if (isEmpty(data)) { + return resolve(result) + } + const { Users: users = [], IsTruncated, Marker } = data users.map(user => { diff --git a/src/services/index.ts b/src/services/index.ts index aa4442aa..b5e24e48 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -569,10 +569,10 @@ export default class Provider extends CloudGraph.Client { const config = await this.getAwsConfig(account) const { accountId } = await this.getIdentity(account) - try { - for (const resource of resourceNames) { - const serviceClass = this.getService(resource) - if (serviceClass && serviceClass.getData) { + for (const resource of resourceNames) { + const serviceClass = this.getService(resource) + if (serviceClass && serviceClass.getData) { + try { const data = await serviceClass.getData({ regions: configuredRegions, config, @@ -587,17 +587,19 @@ export default class Provider extends CloudGraph.Client { data, }) this.logger.success(`${resource} scan completed`) - } else { - this.logger.warn( - `Skipping service ${resource} as there was an issue getting data for it. Is it currently supported?` + } catch (error: any) { + this.logger.error( + `There was an error scanning AWS sdk data for ${resource} resource` ) + this.logger.debug(error) } + } else { + this.logger.warn( + `Skipping service ${resource} as there was an issue getting data for it. Is it currently supported?` + ) } - this.logger.success(`Account: ${accountId} scan completed`) - } catch (error: any) { - this.logger.error('There was an error scanning AWS sdk data') - this.logger.debug(error) } + this.logger.success(`Account: ${accountId} scan completed`) return result }