Skip to content
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

DRAFT: add rawData and add arn in s3 raw data #104

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/services/base/enhancers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const enrichInstanceWithBillingData = ({
name,
mutation,
data: natsWithBilling,
rawData: natsWithBilling,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is ok

})
}
}
Expand Down Expand Up @@ -139,6 +140,7 @@ export const enrichInstanceWithBillingData = ({
name,
mutation,
data: ec2WithBilling,
rawData: ec2WithBilling,
})
}
}
Expand Down
26 changes: 22 additions & 4 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ export default class Provider extends CloudGraph.Client {
try {
const serviceClass = this.getService(serviceData.name)
const entities: any[] = []
const rawEntities: any[] = []
for (const region of Object.keys(serviceData.data)) {
await new Promise(resolve => setTimeout(resolve, 10)) // free the main nodejs thread to process other requests
const data = serviceData.data[region]
Expand All @@ -772,6 +773,7 @@ export default class Provider extends CloudGraph.Client {
account: serviceData.accountId,
})
entities.push(formattedData)
rawEntities.push(service)
if (typeof serviceClass.getConnections === 'function') {
// We need to loop through all configured regions here because services can be connected to things in another region
let serviceConnections = {}
Expand Down Expand Up @@ -807,30 +809,46 @@ export default class Provider extends CloudGraph.Client {
if (existingServiceIdx > -1) {
const existingData = result.entities[existingServiceIdx].data
for (const currentEntity of entities) {
const exisingEntityIdx = existingData.findIndex(
const existingEntityIdx = existingData.findIndex(
({ id }) => id === currentEntity.id
)
if (exisingEntityIdx > -1) {
const entityToDelete = existingData[exisingEntityIdx]
existingData.splice(exisingEntityIdx, 1)
if (existingEntityIdx > -1) {
const entityToDelete = existingData[existingEntityIdx]
existingData.splice(existingEntityIdx, 1)
const entityToMergeIdx = entities.findIndex(
({ id }) => id === currentEntity.id
)
entities[entityToMergeIdx] = merge(entityToDelete, currentEntity)
}
}
const existingRawData = result.entities[existingServiceIdx].rawData
for (const currentRawEntity of rawEntities) {
const existingEntityIdx = existingData.findIndex(
({ id }) => id === currentRawEntity.id
)
if (existingEntityIdx > -1) {
const rawEntityToDelete = existingRawData[existingEntityIdx]
existingRawData.splice(existingEntityIdx, 1)
const entityToMergeIdx = rawEntities.findIndex(
({ id }) => id === currentRawEntity.id
)
rawEntities[entityToMergeIdx] = merge(rawEntityToDelete, currentRawEntity)
}
}
result.entities[existingServiceIdx] = {
className: serviceClass.constructor.name,
name: serviceData.name,
mutation: serviceClass.mutation,
data: [...existingData, ...entities],
rawData: [...existingRawData, ...rawEntities],
}
} else {
result.entities.push({
className: serviceClass.constructor.name,
name: serviceData.name,
mutation: serviceClass.mutation,
data: entities,
rawData: rawEntities,
})
}
} catch (error: any) {
Expand Down
3 changes: 3 additions & 0 deletions src/services/s3/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { initTestEndpoint } from '../../utils'
import { gets3BucketId } from '../../utils/ids'
import AwsErrorLog from '../../utils/errorLog'
import { convertAwsTagsToTagMap } from '../../utils/format'
import { s3BucketArn } from '../../utils/generateArns'

const lt = { ...awsLoggerText }
const { logger } = CloudGraph
Expand Down Expand Up @@ -496,6 +497,7 @@ export interface RawAwsS3 {
Id: string
Name: string
region: string
arn: string
}

export default async ({
Expand Down Expand Up @@ -537,6 +539,7 @@ export default async ({
Name: bucket.Name,
region,
CreationDate: bucket.CreationDate,
arn: s3BucketArn({ name: bucket.Name }),
Tags: {},
})
}
Expand Down