Skip to content

feat(s3): Custom Properties for AWS #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions src/enums/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import services from './services'

/**
* Properties is an object that contains possible configurable variables
*/
export default {
account: [],
[services.alb]: [],
[services.apiGatewayResource]: [],
[services.apiGatewayRestApi]: [],
[services.apiGatewayStage]: [],
[services.appSync]: [],
[services.asg]: [],
[services.athenaDataCatalog]: [],
[services.billing]: [],
[services.clientVpnEndpoint]: [],
[services.cloud9]: [],
[services.cloudFormationStack]: [],
[services.cloudFormationStackSet]: [],
[services.cloudfront]: [],
[services.cloudtrail]: [],
[services.cloudwatch]: [],
[services.cloudwatchLog]: [],
[services.codebuild]: [],
[services.cognitoIdentityPool]: [],
[services.cognitoUserPool]: [],
[services.configurationRecorder]: [],
[services.customerGateway]: [],
[services.dmsReplicationInstance]: [],
[services.dynamodb]: [],
[services.ebs]: [],
[services.ec2Instance]: [],
[services.ecr]: [],
[services.ecsCluster]: [],
[services.ecsContainer]: [],
[services.ecsService]: [],
[services.ecsTask]: [],
[services.ecsTaskDefinition]: [],
[services.ecsTaskSet]: [],
[services.efs]: [],
[services.efsMountTarget]: [],
[services.eip]: [],
[services.eksCluster]: [],
[services.elastiCacheCluster]: [],
[services.elastiCacheReplicationGroup]: [],
[services.elasticBeanstalkApp]: [],
[services.elasticBeanstalkEnv]: [],
[services.elasticSearchDomain]: [],
[services.elb]: [],
[services.flowLog]: [],
[services.glueJob]: [],
[services.glueRegistry]: [],
[services.guardDutyDetector]: [],
[services.emrCluster]: [],
[services.emrInstance]: [],
[services.emrStep]: [],
[services.iamGroup]: [],
[services.iamOpenIdConnectProvider]: [],
[services.iamPasswordPolicy]: [],
[services.iamUser]: [],
[services.iamRole]: [],
[services.iamPolicy]: [],
[services.iamSamlProvider]: [],
[services.iamServerCertificate]: [],
[services.iamInstanceProfile]: [],
[services.igw]: [],
[services.iot]: [],
[services.kinesisFirehose]: [],
[services.kinesisStream]: [],
[services.kms]: [],
[services.lambda]: [],
[services.managedAirflow]: [],
[services.nacl]: [],
[services.nat]: [],
[services.networkInterface]: [],
[services.sg]: [],
[services.subnet]: [],
[services.vpc]: [],
[services.vpnGateway]: [],
[services.sqs]: [],
[services.rdsCluster]: [],
[services.rdsClusterSnapshot]: [],
[services.rdsDbInstance]: [],
[services.redshiftCluster]: [],
[services.route53HostedZone]: [],
[services.route53Record]: [],
[services.routeTable]: [],
[services.sageMakerExperiment]: [],
[services.sageMakerNotebookInstance]: [],
[services.sageMakerProject]: [],
[services.s3]: [{ field: 'MaxKeys', defaultValue: 1000 }],
[services.secretsManager]: [],
[services.ses]: [],
[services.sns]: [],
[services.systemsManagerInstance]: [],
[services.systemsManagerDocument]: [],
[services.transitGateway]: [],
[services.transitGatewayAttachment]: [],
[services.vpnConnection]: [],
[services.organization]: [],
[services.wafV2WebAcl]: [],
}
14 changes: 12 additions & 2 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import resources from '../enums/resources'
import services from '../enums/services'
import serviceMap from '../enums/serviceMap'
import schemasMap from '../enums/schemasMap'
import serviceProperties from '../enums/properties'
import relations from '../enums/relations'
import { Credentials } from '../types'
import { obfuscateSensitiveString } from '../utils/format'
Expand All @@ -34,6 +35,7 @@ export const enums = {
regions,
resources,
schemasMap,
serviceProperties,
}

export default class Provider extends CloudGraph.Client {
Expand Down Expand Up @@ -552,8 +554,11 @@ export default class Provider extends CloudGraph.Client {
account: Account,
opts?: Opts
): Promise<rawDataInterface[]> {
let { regions: configuredRegions, resources: configuredResources } =
this.config
let {
regions: configuredRegions,
resources: configuredResources,
properties = {},
} = this.config
const result: rawDataInterface[] = []
if (!configuredRegions) {
configuredRegions = this.properties.regions.join(',')
Expand All @@ -579,6 +584,11 @@ export default class Provider extends CloudGraph.Client {
opts,
account: accountId,
rawData: result,
params: properties[resource]
? {
...properties[resource],
}
: undefined,
})
result.push({
className: serviceClass.constructor.name,
Expand Down
17 changes: 12 additions & 5 deletions src/services/s3/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const listBucketsForRegion = async (
s3: S3,
resolveRegion: () => void
): Promise<{ buckets: Bucket[]; ownerId: Owner }> =>
new Promise<{ buckets: Bucket[]; ownerId: Owner }>(resolve => {
new Promise(resolve => {
s3.listBuckets((err: AWSError, data: ListBucketsOutput) => {
/**
* No Data for the region
Expand Down Expand Up @@ -429,17 +429,18 @@ const listBucketsForRegion = async (

const listBucketObjects = async (
s3: S3,
name: BucketName
name: BucketName,
params?: { [field: string]: any }
): Promise<S3Object[]> =>
new Promise<S3Object[]>(resolve => {
new Promise(resolve => {
const contents: S3Object[] = []
/**
* S3 Buckets can get quite large, so we limit the total number
* Of objects returned per bucket to 1000
*/
const opts: any = {
Bucket: name,
MaxKeys: awsBucketItemsLimit,
...(params ?? { MaxKeys: awsBucketItemsLimit }),
}
const listAllObjects = (token?: string): void => {
if (token) {
Expand Down Expand Up @@ -501,9 +502,11 @@ export interface RawAwsS3 {
export default async ({
regions,
config,
params,
}: {
regions: string
config: Config
params: any
}): Promise<{
[region: string]: RawAwsS3[]
}> =>
Expand Down Expand Up @@ -558,7 +561,11 @@ export default async ({
s3ForcePathStyle: true,
})
logger.debug(lt.gettingBucketBasicInfo(Name))
const bucketObjectList: S3Object[] = await listBucketObjects(s3, Name)
const bucketObjectList: S3Object[] = await listBucketObjects(
s3,
Name,
params
)

bucketData[idx].Contents = []
if (!isEmpty(bucketObjectList)) {
Expand Down