Skip to content

Commit 8048a2c

Browse files
author
Marco Franceschi
committed
fix: Fixed billing schema fields
1 parent 3b3ff27 commit 8048a2c

7 files changed

Lines changed: 41 additions & 29 deletions

File tree

src/services/account/connections.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export default ({
77
service,
88
data,
99
}: {
10-
service: any
10+
service: { id: string; accountId: string; regions: string[] }
1111
data: Entity[]
1212
}): {
1313
[property: string]: ServiceConnection[]
1414
} => {
15-
const { id } = service
15+
const { id, accountId } = service
1616
const connections: ServiceConnection[] = []
1717
const connectTo = Object.values(services)
1818

@@ -25,7 +25,9 @@ export default ({
2525
})
2626

2727
if (instances?.data) {
28-
const filtered = flatMap(instances.data).filter(i => i.accountId === id)
28+
const filtered = flatMap(instances.data).filter(
29+
i => i.accountId === accountId
30+
)
2931

3032
for (const instance of filtered) {
3133
if (instance) {

src/services/account/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
type awsAccount @key(fields: "id") {
22
id: String! @id @search(by: [hash])
3+
accountId: String! @search(by: [hash])
34
regions: [String] @search(by: [hash])
45
albs: [awsAlb]
56
apiGatewayResources: [awsApiGatewayResource]

src/services/base/enhancers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import isEmpty from 'lodash/isEmpty'
44
import { rawDataInterface } from '.'
55
import { regionMap } from '../../enums/regions'
66
import services from '../../enums/services'
7+
import { checkAndMergeConnections } from '../../utils'
78
import addAccountConnections from '../account/connections'
89

910
/**
1011
* Data Enhancers
1112
*/
1213
export interface EnhancerConfig {
1314
rawData: rawDataInterface[]
14-
accounts: { id: string; regions: string[] }[]
15+
accounts: { id: string; accountId: string; regions: string[] }[]
1516
configuredRegions: string
1617
data: ProviderData
1718
}
@@ -37,13 +38,12 @@ export const connectAWSServicesToAccount = ({
3738
...connections,
3839
}
3940
}
40-
4141
return {
4242
entities: data.entities,
43-
connections: {
44-
...data.connections,
45-
...accountsConnections,
46-
},
43+
connections: checkAndMergeConnections(
44+
data.connections,
45+
accountsConnections
46+
),
4747
}
4848
}
4949

src/services/billing/format.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import { AwsBilling } from '../../types/generated'
33

44
const formatCostData = (costData: {
55
[key: string]: costInterface
6-
}): { name: string; cost?: number, currency?: string, formattedCost?: string }[] =>
6+
}): {
7+
name: string
8+
cost?: number
9+
currency?: string
10+
formattedCost?: string
11+
}[] =>
712
Object.keys(costData).map(name => ({
813
name,
9-
...costData[name]
14+
...costData[name],
1015
}))
1116
/**
1217
* CloudWatch
@@ -29,15 +34,17 @@ export default ({
2934
const formattedMonthToDate = formatCostData(monthToDate)
3035
const formattedLast30Days = formatCostData(last30Days)
3136
const formattedLast30DailyAverage = formatCostData(last30DaysDailyAverage)
32-
const formattedMonthToDateDailyAverage = formatCostData(monthToDateDailyAverage)
37+
const formattedMonthToDateDailyAverage = formatCostData(
38+
monthToDateDailyAverage
39+
)
3340
return {
34-
id: account,
35-
account,
41+
id: `billing:${account}`,
42+
accountId: account,
3643
totalCostMonthToDate,
3744
totalCostLast30Days,
3845
monthToDate: formattedMonthToDate,
3946
last30Days: formattedLast30Days,
4047
monthToDateDailyAverage: formattedMonthToDateDailyAverage,
41-
last30DaysDailyAverage: formattedLast30DailyAverage
48+
last30DaysDailyAverage: formattedLast30DailyAverage,
4249
}
4350
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# TODO: change to accountId
21
type awsBilling {
32
id: String! @id @search(by: [hash])
4-
account: String! @id @search(by: [hash])
3+
accountId: String! @id @search(by: [hash])
54
totalCostMonthToDate: awsTotalBillingInfo
65
totalCostLast30Days: awsTotalBillingInfo
76
monthToDateDailyAverage: [awsServiceBillingInfo]
@@ -10,25 +9,25 @@ type awsBilling {
109
last30Days: [awsServiceBillingInfo]
1110
}
1211

13-
type awsServiceBillingInfo
12+
type awsServiceBillingInfo
1413
@generate(
1514
query: { get: false, query: false, aggregate: false }
1615
mutation: { add: false, delete: false }
1716
subscription: false
1817
) {
19-
name: String! @search(by: [hash])
20-
cost: Float @search
21-
currency: String @search(by: [hash, regexp])
22-
formattedCost: String @search(by: [hash, regexp])
23-
}
18+
name: String! @search(by: [hash])
19+
cost: Float @search
20+
currency: String @search(by: [hash, regexp])
21+
formattedCost: String @search(by: [hash, regexp])
22+
}
2423

2524
type awsTotalBillingInfo
2625
@generate(
2726
query: { get: false, query: false, aggregate: false }
2827
mutation: { add: false, delete: false }
2928
subscription: false
3029
) {
31-
cost: Float @search
32-
currency: String @search(by: [hash, regexp])
33-
formattedCost: String @search(by: [hash, regexp])
34-
}
30+
cost: Float @search
31+
currency: String @search(by: [hash, regexp])
32+
formattedCost: String @search(by: [hash, regexp])
33+
}

src/services/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ export default class Provider extends CloudGraph.Client {
614614
`There was an error enriching AWS data with ${name} data`
615615
)
616616
this.logger.debug(error)
617+
return data
617618
}
618619
}
619620

@@ -697,7 +698,8 @@ export default class Provider extends CloudGraph.Client {
697698
}
698699
const { accountId } = await this.getIdentity(account)
699700
accounts.data[globalRegion].push({
700-
id: accountId,
701+
id: `account:${accountId}`,
702+
accountId,
701703
regions: configuredRegions.split(','),
702704
})
703705
if (!crawledAccounts.find(val => val === accountId)) {

src/types/generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export type AwsAccessLogSettings = {
129129
};
130130

131131
export type AwsAccount = {
132+
accountId: Scalars['String'];
132133
albs?: Maybe<Array<Maybe<AwsAlb>>>;
133134
apiGatewayResources?: Maybe<Array<Maybe<AwsApiGatewayResource>>>;
134135
apiGatewayRestApis?: Maybe<Array<Maybe<AwsApiGatewayRestApi>>>;
@@ -556,7 +557,7 @@ export type AwsAthenaMetadataColumn = {
556557
};
557558

558559
export type AwsBilling = {
559-
account: Scalars['String'];
560+
accountId: Scalars['String'];
560561
id: Scalars['String'];
561562
last30Days?: Maybe<Array<Maybe<AwsServiceBillingInfo>>>;
562563
last30DaysDailyAverage?: Maybe<Array<Maybe<AwsServiceBillingInfo>>>;

0 commit comments

Comments
 (0)