Skip to content

Commit 2f8582a

Browse files
committed
Merge branch 'alpha' into feature/CG-1266
2 parents c57c3b3 + 18062c3 commit 2f8582a

File tree

17 files changed

+266
-2
lines changed

17 files changed

+266
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [0.63.0-alpha.1](https://github.com/cloudgraphdev/cloudgraph-provider-azure/compare/0.62.0...0.63.0-alpha.1) (2022-06-02)
2+
3+
4+
### Features
5+
6+
* **services:** Update readme file ([c049a36](https://github.com/cloudgraphdev/cloudgraph-provider-azure/commit/c049a3628bc80d3091fbe6e16d7a48152ccb1316))
7+
18
# [0.62.0](https://github.com/cloudgraphdev/cloudgraph-provider-azure/compare/0.61.0...0.62.0) (2022-05-31)
29

310

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ CloudGraph needs read permissions in order to ingest your data. To keep things e
8787
| loadBalancer | loadBalancer, publicIp, resourceGroup, virtualNetwork |
8888
| logAnalyticsSolution | resourceGroup, logAnalyticsWorkspace |
8989
| logAnalyticsWorkspace | resourceGroup, dataCollectionRule, logAnalyticsSolution |
90+
| logProfiles | storageAccount |
9091
| networkInterface | publicIp, resourceGroup, securityGroup, virtualMachine, virtualNetwork |
9192
| policyAssignment | |
9293
| postgreSqlServers | resourceGroup, databasePostgreSql |
@@ -106,7 +107,7 @@ CloudGraph needs read permissions in order to ingest your data. To keep things e
106107
| securitySettings | |
107108
| serviceBus | resourceGroup |
108109
| sqlServers | databaseSql, resourceGroup |
109-
| storageAccount | diagnosticSetting, resourceGroup, storageContainer |
110+
| storageAccount | diagnosticSetting, logProfiles, resourceGroup, storageContainer |
110111
| storageBlob | resourceGroup, storageContainer |
111112
| storageContainer | resourceGroup, storageAccount |
112113
| synapseBigDataPools | resourceGroup, synapseWorkspaces |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudgraph/cg-provider-azure",
3-
"version": "0.62.0",
3+
"version": "0.63.0-alpha.1",
44
"description": "CloudGraph provider plugin for Azure used to fetch Azure cloud data.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default {
5858
[services.loadBalancer]: 'azureLoadBalancer',
5959
[services.logAnalyticsSolution]: 'azureLogAnalyticsSolution',
6060
[services.logAnalyticsWorkspace]: 'azureLogAnalyticsWorkspace',
61+
[services.logProfiles]: 'azureLogProfiles',
6162
[services.machineLearningWorkspaces]: 'azureMachineLearningWorkspace',
6263
[services.metricAlert]:'azureMetricAlert',
6364
[services.mySqlServers]: 'azureMySqlServer',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import AzureBackupVault from '../services/backupVault'
8383
import AzureBackupInstance from '../services/backupInstance'
8484
import AzureBackupPolicy from '../services/backupPolicy'
8585
import AzureBilling from '../services/billing'
86+
import AzureLogProfiles from '../services/logProfiles'
8687

8788
/**
8889
* serviceMap is an object that contains all currently supported services for AWS
@@ -144,6 +145,7 @@ export default {
144145
[services.loadBalancer]: AzureLoadBalancer,
145146
[services.logAnalyticsSolution]: AzureLogAnalyticsSolutions,
146147
[services.logAnalyticsWorkspace]: AzureLogAnalyticsWorkspaces,
148+
[services.logProfiles]: AzureLogProfiles,
147149
[services.machineLearningWorkspaces]: AzureMachineLearningWorkspace,
148150
[services.mySqlServers]: AzureMySqlServer,
149151
[services.networkInterface]: AzureNetworkInterface,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default {
5151
loadBalancer: 'loadBalancer',
5252
logAnalyticsSolution: 'logAnalyticsSolution',
5353
logAnalyticsWorkspace: 'logAnalyticsWorkspace',
54+
logProfiles: 'logProfiles',
5455
machineLearningWorkspaces: 'machineLearningWorkspaces',
5556
metricAlert: 'metricAlert',
5657
mySqlServers: 'mySqlServers',

src/properties/logger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ export default {
127127
`Found ${num} Key Vault secrets`,
128128
// Load balancer
129129
foundLoadBalancers: (num: number): string => `Found ${num} load balancers`,
130+
// Metric Profiles
131+
foundLogProfiles: (num: number): string => `Found ${num} log profiles`,
130132
// Machine Learning Workspaces
131133
foundMachineLearningWorkspaces: (num: number): string =>
132134
`Found ${num} machine learning workspaces`,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
import { isEmpty } from 'lodash'
3+
4+
import services from '../../enums/services'
5+
import { RawAzureStorageAccount } from '../storageAccount/data'
6+
import { RawAzureLogProfileResource } from './data'
7+
8+
export default ({
9+
service,
10+
data,
11+
region,
12+
}: {
13+
service: RawAzureLogProfileResource
14+
data: Array<{ name: string; data: { [property: string]: any[] } }>
15+
region: string
16+
}): {
17+
[property: string]: ServiceConnection[]
18+
} => {
19+
const connections: ServiceConnection[] = []
20+
const { id, storageAccountId } = service
21+
22+
/**
23+
* Find storage account related to this log profile
24+
*/
25+
const storageAccounts: {
26+
name: string
27+
data: { [property: string]: RawAzureStorageAccount[] }
28+
} = data.find(({ name }) => name === services.storageAccount)
29+
30+
if (storageAccounts?.data?.[region]) {
31+
const storageAccountsInRegion: RawAzureStorageAccount[] =
32+
storageAccounts.data[region].filter(
33+
({ id: saId }: RawAzureStorageAccount) => saId === storageAccountId
34+
)
35+
36+
if (!isEmpty(storageAccountsInRegion)) {
37+
for (const rg of storageAccountsInRegion) {
38+
connections.push({
39+
id: rg.id,
40+
resourceType: services.storageAccount,
41+
relation: 'child',
42+
field: 'storageAccount',
43+
})
44+
}
45+
}
46+
}
47+
48+
const rgResult = {
49+
[id]: connections,
50+
}
51+
return rgResult
52+
}

src/services/logProfiles/data.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import CloudGraph from '@cloudgraph/sdk'
2+
import { MonitorClient, LogProfileResource } from '@azure/arm-monitor'
3+
import { PagedAsyncIterableIterator } from '@azure/core-paging'
4+
import azureLoggerText from '../../properties/logger'
5+
import { AzureServiceInput, TagMap } from '../../types'
6+
import { tryCatchWrapper } from '../../utils'
7+
import { regionMap } from '../../enums/regions'
8+
9+
const { logger } = CloudGraph
10+
const lt = { ...azureLoggerText }
11+
const serviceName = 'Log Profiles'
12+
13+
export interface RawAzureLogProfileResource
14+
extends Omit<LogProfileResource, 'location' | 'tags'> {
15+
region: string
16+
Tags: TagMap
17+
}
18+
19+
export default async ({
20+
config,
21+
}: AzureServiceInput): Promise<{
22+
[property: string]: RawAzureLogProfileResource[]
23+
}> => {
24+
try {
25+
const { tokenCredentials, subscriptionId } = config
26+
const client = new MonitorClient(tokenCredentials, subscriptionId)
27+
const logProfiles: RawAzureLogProfileResource[] = []
28+
const result = { global: [] }
29+
await tryCatchWrapper(
30+
async () => {
31+
const logProfilesIterable: PagedAsyncIterableIterator<LogProfileResource> =
32+
client.logProfiles.list()
33+
for await (const logProfile of logProfilesIterable) {
34+
if (logProfile) {
35+
const { tags, ...rest } = logProfile
36+
const region = regionMap.global
37+
logProfiles.push({
38+
...rest,
39+
region,
40+
Tags: tags || {},
41+
})
42+
}
43+
}
44+
},
45+
{
46+
service: serviceName,
47+
client,
48+
scope: 'logProfiles',
49+
operation: 'list',
50+
}
51+
)
52+
logger.debug(lt.foundLogProfiles(logProfiles.length))
53+
54+
logProfiles.map(({ region, ...rest }) => {
55+
result.global.push({
56+
...rest,
57+
region,
58+
})
59+
})
60+
return result
61+
} catch (e) {
62+
logger.error(e)
63+
return {}
64+
}
65+
}

src/services/logProfiles/format.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import cuid from 'cuid'
2+
import { AzureLogProfile } from '../../types/generated'
3+
import { formatTagsFromMap } from '../../utils/format'
4+
import { RawAzureLogProfileResource } from './data'
5+
6+
export default ({
7+
service,
8+
account,
9+
region,
10+
}: {
11+
service: RawAzureLogProfileResource
12+
account: string
13+
region: string
14+
}): AzureLogProfile => {
15+
const {
16+
id,
17+
name,
18+
type,
19+
storageAccountId,
20+
serviceBusRuleId,
21+
locations = [],
22+
categories = [],
23+
retentionPolicy = {},
24+
Tags: tags = {},
25+
} = service
26+
27+
return {
28+
id: id || cuid(),
29+
name,
30+
region,
31+
subscriptionId: account,
32+
type,
33+
storageAccountId,
34+
serviceBusRuleId,
35+
locations,
36+
categories,
37+
retentionPolicy,
38+
tags: formatTagsFromMap(tags),
39+
}
40+
}

0 commit comments

Comments
 (0)