Skip to content

Commit b5e362e

Browse files
authored
Merge pull request #45 from cloudgraphdev/feature/CG-901-support-waf
feat(CG-901): add application gateway support
2 parents 28b7a24 + 4acc3ee commit b5e362e

File tree

12 files changed

+3416
-0
lines changed

12 files changed

+3416
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CloudGraph needs read permissions in order to ingest your data. To keep things e
4343
| adServicePrincipal | adApplication, authRoleAssignment |
4444
| adUser | adApplication, authRoleAssignment |
4545
| aksManagedCluster | resourceGroup, virtualMachineScaleSet |
46+
| applicationGateway | resourceGroup |
4647
| appInsights | resourceGroup |
4748
| appServiceEnvironment | resourceGroup, virtualNetwork |
4849
| appServicePlan | resourceGroup, appServiceWebApp |

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
[services.adServicePrincipal]: 'azureADServicePrincipal',
1515
[services.adUser]: 'azureADUser',
1616
[services.aksManagedCluster]: 'azureAksManagedCluster',
17+
[services.applicationGateway]: 'azureApplicationGateway',
1718
[services.appServiceEnvironment]: 'azureAppServiceEnvironment',
1819
// [services.appServiceKubeEnvironment]: 'azureAppServiceKubeEnvironment',
1920
[services.appInsights]: 'azureAppInsights',

src/enums/serviceAliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default {
44
[services.actionGroup]: 'actionGroups',
55
[services.activityLogAlerts]: 'activityLogAlerts',
66
[services.aksManagedCluster]: 'aksManagedClusters',
7+
[services.applicationGateway]: 'applicationGateways',
78
[services.appServiceEnvironment]: 'appServiceEnvironments',
89
[services.appInsights]: 'appInsights',
910
[services.appServicePlan]: 'appServicePlans',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import AzureADServicePrincipal from '../services/adServicePrincipal'
88
import AzureADUser from '../services/adUser'
99
import AzureAksManagedCluster from '../services/aksManagedCluster'
1010
import AzureMetricAlert from '../services/metricAlert'
11+
import AzureApplicationGateway from '../services/applicationGateway'
1112
import AzureAppServiceEnvironment from '../services/appServiceEnvironment'
1213
// import AzureAppServiceKubeEnvironment from '../services/appServiceKubeEnvironment'
1314
import AzureAppServicePlan from '../services/appServicePlan'
@@ -104,6 +105,7 @@ export default {
104105
[services.adUser]: AzureADUser,
105106
[services.aksManagedCluster]: AzureAksManagedCluster,
106107
[services.metricAlert]: AzureMetricAlert,
108+
[services.applicationGateway]: AzureApplicationGateway,
107109
[services.appServiceEnvironment]: AzureAppServiceEnvironment,
108110
// [services.appServiceKubeEnvironment]: AzureAppServiceKubeEnvironment,
109111
[services.appInsights]: AzureAppInsights,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default {
88
adServicePrincipal: 'adServicePrincipal',
99
adUser: 'adUser',
1010
aksManagedCluster: 'aksManagedCluster',
11+
applicationGateway: 'applicationGateway',
1112
appServiceEnvironment: 'appServiceEnvironment',
1213
// appServiceKubeEnvironment: 'appServiceKubeEnvironment',
1314
appInsights: 'appInsights',

src/properties/logger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default {
1919
// AKS Managed Clusters
2020
foundAKSManagedClusters: (num: number): string =>
2121
`Found ${num} AKS managed clusters`,
22+
/* App Gateway */
23+
foundApplicationGateway: (num: number): string => `Found ${num} Application Gateways`,
2224
/* App Service */
2325
foundAppServiceEnvironments: (num: number): string =>
2426
`Found ${num} app service environments`,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { ApplicationGateway, NetworkManagementClient } from '@azure/arm-network'
2+
import { PagedAsyncIterableIterator } from '@azure/core-paging'
3+
import CloudGraph from '@cloudgraph/sdk'
4+
5+
import azureLoggerText from '../../properties/logger'
6+
import { AzureServiceInput, TagMap } from '../../types'
7+
import { tryCatchWrapper } from '../../utils'
8+
import { lowerCaseLocation } from '../../utils/format'
9+
import { getResourceGroupFromEntity } from '../../utils/idParserUtils'
10+
11+
const { logger } = CloudGraph
12+
const lt = { ...azureLoggerText }
13+
const serviceName = 'ApplicationGateway'
14+
15+
export interface RawAzureApplicationGateway
16+
extends Omit<ApplicationGateway, 'tags' | 'location'> {
17+
region: string
18+
resourceGroupId: string
19+
Tags: TagMap
20+
}
21+
22+
export default async ({
23+
regions,
24+
config,
25+
}: AzureServiceInput): Promise<{
26+
[property: string]: RawAzureApplicationGateway[]
27+
}> => {
28+
try {
29+
const { tokenCredentials, subscriptionId } = config
30+
const client = new NetworkManagementClient(tokenCredentials, subscriptionId)
31+
32+
const applicationGatewayData: ApplicationGateway[] = []
33+
await tryCatchWrapper(
34+
async () => {
35+
const applicationGatewayIterable: PagedAsyncIterableIterator<ApplicationGateway> =
36+
client.applicationGateways.listAll()
37+
for await (const applicationGateway of applicationGatewayIterable) {
38+
applicationGateway && applicationGatewayData.push(applicationGateway)
39+
}
40+
},
41+
{
42+
service: serviceName,
43+
client,
44+
scope: 'applicationGateway',
45+
operation: 'listAll'
46+
}
47+
)
48+
49+
const result: {
50+
[property: string]: RawAzureApplicationGateway[]
51+
} = {}
52+
let numOfGroups = 0
53+
applicationGatewayData.map(({ tags, location, ...rest }) => {
54+
const region = lowerCaseLocation(location)
55+
if (regions.includes(region)) {
56+
if (!result[region]) {
57+
result[region] = []
58+
}
59+
const resourceGroupId = getResourceGroupFromEntity(rest)
60+
result[region].push({
61+
...rest,
62+
region,
63+
resourceGroupId,
64+
Tags: tags || {},
65+
})
66+
numOfGroups += 1
67+
}
68+
})
69+
logger.debug(lt.foundApplicationGateway(numOfGroups))
70+
71+
return result
72+
} catch (e) {
73+
logger.error(e)
74+
return {}
75+
}
76+
}

0 commit comments

Comments
 (0)