Skip to content

Commit 0537eb2

Browse files
authored
Merge pull request #51 from cloudgraphdev/fix/generate-unique-ids-using-data
fix: replace cuid usage, remove conditional cuid generation for root ids
2 parents f1d1d08 + 823a0ef commit 0537eb2

File tree

87 files changed

+1703
-1962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1703
-1962
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@azure/identity": "^2.0.4",
7474
"@azure/storage-blob": "^12.8.0",
7575
"@azure/storage-queue": "^12.9.0",
76-
"@cloudgraph/sdk": "0.20.0",
76+
"@cloudgraph/sdk": "0.22.0",
7777
"@graphql-tools/load-files": "^6.5.3",
7878
"@graphql-tools/merge": "^8.2.3",
7979
"@microsoft/microsoft-graph-client": "^3.0.2",

src/services/actionGroup/format.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cuid from 'cuid'
1+
import { generateUniqueId } from '@cloudgraph/sdk'
22
import { RawAzureActionGroup } from './data'
33
import { AzureActionGroup } from '../../types/generated'
44
import { formatTagsFromMap } from '../../utils/format'
@@ -24,17 +24,35 @@ export default ({
2424
Tags = {},
2525
} = service
2626
return {
27-
id: id || cuid(),
27+
id,
2828
name,
2929
type,
3030
region,
3131
subscriptionId,
3232
resourceGroupId,
3333
enabled,
3434
groupShortName,
35-
emailReceivers: emailReceivers.map(e => ({ id: cuid(), ...e })),
36-
smsReceivers: smsReceivers.map(s => ({ id: cuid(), ...s })),
37-
webhookReceivers: webhookReceivers.map(w => ({ id: cuid(), ...w })),
35+
emailReceivers: emailReceivers.map(e => ({
36+
id: generateUniqueId({
37+
id,
38+
...e,
39+
}),
40+
...e,
41+
})),
42+
smsReceivers: smsReceivers.map(s => ({
43+
id: generateUniqueId({
44+
id,
45+
...s,
46+
}),
47+
...s,
48+
})),
49+
webhookReceivers: webhookReceivers.map(w => ({
50+
id: generateUniqueId({
51+
id,
52+
...w,
53+
}),
54+
...w,
55+
})),
3856
tags: formatTagsFromMap(Tags),
3957
}
4058
}

src/services/activityLogAlerts/format.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import cuid from 'cuid'
1+
import { generateUniqueId } from '@cloudgraph/sdk'
22
import { RawAzureActivityLogAlert } from './data'
33
import { AzureActivityLogAlert } from '../../types/generated'
44
import { formatTagsFromMap } from '../../utils/format'
55

66
export default ({
77
service,
8-
account: subscriptionId
8+
account: subscriptionId,
99
}: {
1010
service: RawAzureActivityLogAlert
1111
account: string
12-
}) : AzureActivityLogAlert => {
12+
}): AzureActivityLogAlert => {
1313
const {
1414
id,
1515
name,
@@ -23,7 +23,7 @@ export default ({
2323
Tags = {},
2424
} = service
2525
return {
26-
id: id || cuid(),
26+
id,
2727
name,
2828
type,
2929
region,
@@ -32,7 +32,7 @@ export default ({
3232
enabled,
3333
condition: {
3434
allOf: condition?.allOf?.map(leaf => ({
35-
id: cuid(),
35+
id: generateUniqueId({ id, ...leaf }),
3636
field: leaf?.field,
3737
equals: leaf?.equals,
3838
})),
@@ -41,11 +41,17 @@ export default ({
4141
actionGroups: actions?.actionGroups?.map(group => ({
4242
id: group.actionGroupId,
4343
actionGroupId: group.actionGroupId,
44-
webhookProperties: Object.entries(group?.webhookProperties || {}).map(([key, value]) => ({
45-
id: cuid(),
46-
key,
47-
value
48-
})),
44+
webhookProperties: Object.entries(group?.webhookProperties || {}).map(
45+
([key, value]) => ({
46+
id: generateUniqueId({
47+
id,
48+
actionGroupId: group.actionGroupId,
49+
key
50+
}),
51+
key,
52+
value,
53+
})
54+
),
4955
})),
5056
},
5157
description,

src/services/adApplication/format.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cuid from 'cuid'
21
import { AzureAdApplication } from '../../types/generated'
32
import { formatTagsFromMap } from '../../utils/format'
43
import { RawAzureADApplication } from './data'
@@ -42,7 +41,7 @@ export default ({
4241
} = {},
4342
} = service
4443
return {
45-
id: id || cuid(),
44+
id,
4645
region,
4746
appId,
4847
applicationTemplateId,
@@ -52,7 +51,7 @@ export default ({
5251
({ appId: preAuthAppId }) => preAuthAppId
5352
),
5453
appRoles: appRoles.map(({ id: appRoleId, ...restOfAppRole }) => ({
55-
id: appRoleId || cuid(),
54+
id: appRoleId,
5655
...restOfAppRole,
5756
})),
5857
createdDateTime,

src/services/adGroup/format.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cuid from 'cuid'
1+
import { generateUniqueId } from '@cloudgraph/sdk'
22
import { AzureAdGroup } from '../../types/generated'
33
import { RawAzureADGroup } from './data'
44

@@ -38,7 +38,7 @@ export default ({ service }: { service: RawAzureADGroup }): AzureAdGroup => {
3838
settings = [],
3939
} = service
4040
return {
41-
id: id || cuid(),
41+
id,
4242
deletedDateTime,
4343
classification,
4444
createdDateTime,
@@ -67,11 +67,20 @@ export default ({ service }: { service: RawAzureADGroup }): AzureAdGroup => {
6767
allowExternalSenders,
6868
isSubscribedByMail,
6969
isArchived,
70-
appRoleAssignments: appRoleAssignments.map(aRA => ({ id: cuid(), ...aRA })),
71-
permissionGrants: permissionGrants.map(pG => ({ id: cuid(), ...pG })),
70+
appRoleAssignments: appRoleAssignments.map(aRA => ({
71+
id: aRA.id,
72+
...aRA,
73+
})),
74+
permissionGrants: permissionGrants.map(pG => ({
75+
id: pG.id,
76+
...pG,
77+
})),
7278
settings: settings.map(({ id: sId, values: sValues = [], ...s }) => ({
73-
id: sId || cuid(),
74-
values: sValues.map(sValue => ({ id: cuid(), ...sValue })),
79+
id: sId,
80+
values: sValues.map(sValue => ({
81+
id: generateUniqueId({ id, ...sValue }),
82+
...sValue,
83+
})),
7584
...s,
7685
})),
7786
}

src/services/adIdentitySecurityDefaultsEnforcementPolicy/format.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cuid from 'cuid'
21
import { AzureAdIdentitySecurityDefaultsEnforcementPolicy } from '../../types/generated'
32
import { RawAzureADIdentitySecurityDefaultsEnforcementPolicyClient } from './data'
43

@@ -8,15 +7,9 @@ export default ({
87
service: RawAzureADIdentitySecurityDefaultsEnforcementPolicyClient
98
account: string
109
}): AzureAdIdentitySecurityDefaultsEnforcementPolicy => {
11-
const {
12-
id,
13-
region,
14-
description,
15-
displayName,
16-
isEnabled,
17-
} = service
10+
const { id, region, description, displayName, isEnabled } = service
1811
return {
19-
id: id || cuid(),
12+
id,
2013
region,
2114
description,
2215
displayName,

src/services/adServicePrincipal/format.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cuid from 'cuid'
21
import { AzureAdServicePrincipal } from '../../types/generated'
32
import { formatTagsFromMap } from '../../utils/format'
43
import { RawAzureADServicePrincipal } from './data'
@@ -42,7 +41,7 @@ export default ({
4241
endpoints = [],
4342
} = service
4443
return {
45-
id: id || cuid(),
44+
id,
4645
region,
4746
deletedDateTime,
4847
accountEnabled,
@@ -54,7 +53,7 @@ export default ({
5453
appOwnerOrganizationId,
5554
appRoleAssignmentRequired,
5655
appRoles: appRoles.map(({ id: aRId, ...aR }) => ({
57-
id: aRId || cuid(),
56+
id: aRId,
5857
...aR,
5958
})),
6059
description,
@@ -73,15 +72,15 @@ export default ({
7372
tags: formatTagsFromMap(Tags),
7473
tokenEncryptionKeyId,
7574
appRoleAssignedTo: appRoleAssignedTo.map(({ id: aRaTId, ...aRaT }) => ({
76-
id: aRaTId || cuid(),
75+
id: aRaTId,
7776
...aRaT,
7877
})),
7978
appRoleAssignments: appRoleAssignments.map(({ id: aRAId, ...aRA }) => ({
80-
id: aRAId || cuid(),
79+
id: aRAId,
8180
...aRA,
8281
})),
8382
endpoints: endpoints.map(({ id: eId, ...e }) => ({
84-
id: eId || cuid(),
83+
id: eId,
8584
...e,
8685
})),
8786
}

src/services/adUser/format.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cuid from 'cuid'
21
import { AzureAdUser } from '../../types/generated'
32
import { RawAzureADUser } from './data'
43

@@ -52,7 +51,7 @@ export default ({
5251
appRoleAssignments = [],
5352
} = service
5453
return {
55-
id: id || cuid(),
54+
id,
5655
deletedDateTime,
5756
accountEnabled,
5857
ageGroup,
@@ -91,6 +90,9 @@ export default ({
9190
userType,
9291
preferredName,
9392
responsibilities,
94-
appRoleAssignments: appRoleAssignments.map(aRA => ({ id: cuid(), ...aRA })),
93+
appRoleAssignments: appRoleAssignments.map(aRA => ({
94+
id: aRA.id,
95+
...aRA,
96+
})),
9597
}
9698
}

src/services/aksManagedCluster/format.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ManagedClusterAADProfile,
44
ManagedClusterAgentPoolProfile,
55
} from '@azure/arm-containerservice'
6-
import cuid from 'cuid'
6+
import { generateUniqueId } from '@cloudgraph/sdk'
77
import {
88
AzureAksManagedCluster,
99
AzureAksManagedClusterAadProfile,
@@ -26,7 +26,7 @@ const formatAgentPoolProfiles = (
2626
tags,
2727
...rest
2828
}) => ({
29-
id: cuid(),
29+
id: generateUniqueId({ powerStateCode, upgradeMaxSurge, ...rest }),
3030
powerStateCode,
3131
upgradeMaxSurge,
3232
...rest,
@@ -113,7 +113,7 @@ export default ({
113113
{}
114114

115115
return {
116-
id: id || cuid(),
116+
id,
117117
subscriptionId: account,
118118
name,
119119
type,

src/services/appInsights/format.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import cuid from 'cuid'
2-
31
import { AzureAppInsights } from '../../types/generated'
42
import { formatTagsFromMap } from '../../utils/format'
53
import { RawAzureAppInsight } from './data'
@@ -36,7 +34,7 @@ export default ({
3634
} = service
3735

3836
return {
39-
id: id || cuid(),
37+
id,
4038
type,
4139
etag,
4240
resourceGroupId,

0 commit comments

Comments
 (0)