Skip to content

Commit 10c5401

Browse files
authored
Merge pull request #19 from cloudgraphdev/fix/CG-1201
fix: Review and fix scan errors (issue reported on github)
2 parents e6e701d + 09770cb commit 10c5401

File tree

3 files changed

+226
-50
lines changed

3 files changed

+226
-50
lines changed

src/services/virtualMachineScaleSet/format.ts

+214-43
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,217 @@
11
import cuid from 'cuid'
22
import { isEmpty } from 'lodash'
3-
import { AzureVirtualMachineScaleSet } from '../../types/generated'
3+
import {
4+
VirtualMachineScaleSetOSProfile,
5+
VirtualMachineScaleSetStorageProfile,
6+
VirtualMachineScaleSetNetworkProfile,
7+
VirtualMachineScaleSetExtensionProfile,
8+
} from '@azure/arm-compute'
9+
import {
10+
AzureVirtualMachineScaleSet,
11+
AzureVirtualMachineScaleSetOsProfile,
12+
AzureVirtualMachineScaleSetStorageProfile,
13+
AzureVirtualMachineScaleSetNetworkProfile,
14+
AzureVirtualMachineScaleSetExtension,
15+
} from '../../types/generated'
416
import { formatTagsFromMap } from '../../utils/format'
517
import { RawAzureVirtualMachineScaleSet } from './data'
618

19+
const formatOsProfile = (
20+
osProfile?: VirtualMachineScaleSetOSProfile
21+
): AzureVirtualMachineScaleSetOsProfile => {
22+
if (isEmpty(osProfile)) {
23+
return {}
24+
}
25+
26+
const {
27+
computerNamePrefix,
28+
adminUsername,
29+
allowExtensionOperations,
30+
windowsConfiguration,
31+
linuxConfiguration,
32+
secrets,
33+
} = osProfile
34+
35+
return {
36+
computerNamePrefix,
37+
adminUsername,
38+
allowExtensionOperations,
39+
windowsConfiguration: windowsConfiguration
40+
? {
41+
additionalUnattendContent:
42+
windowsConfiguration.additionalUnattendContent?.map(auc => ({
43+
id: cuid(),
44+
...auc,
45+
})) || [],
46+
winRM: windowsConfiguration.winRM
47+
? {
48+
listeners:
49+
windowsConfiguration.winRM.listeners?.map(l => ({
50+
id: cuid(),
51+
...l,
52+
})) || [],
53+
}
54+
: {},
55+
...windowsConfiguration,
56+
}
57+
: {},
58+
linuxConfiguration: linuxConfiguration
59+
? {
60+
ssh: linuxConfiguration.ssh
61+
? {
62+
publicKeys:
63+
linuxConfiguration.ssh.publicKeys?.map(pk => ({
64+
id: cuid(),
65+
...pk,
66+
})) || [],
67+
}
68+
: {},
69+
}
70+
: {},
71+
secrets:
72+
secrets?.map(s => ({
73+
id: cuid(),
74+
sourceVault: {
75+
id: s.sourceVault?.id || cuid(),
76+
},
77+
vaultCertificates:
78+
s.vaultCertificates?.map(vc => ({
79+
id: cuid(),
80+
...vc,
81+
})) || [],
82+
})) || [],
83+
}
84+
}
85+
86+
const formatStorageProfile = (
87+
storageProfile?: VirtualMachineScaleSetStorageProfile
88+
): AzureVirtualMachineScaleSetStorageProfile => {
89+
if (isEmpty(storageProfile)) {
90+
return {}
91+
}
92+
93+
const { imageReference, osDisk } = storageProfile
94+
95+
return {
96+
imageReference: imageReference
97+
? {
98+
id: imageReference.id || cuid(),
99+
publisher: imageReference.publisher,
100+
offer: imageReference.offer,
101+
sku: imageReference.sku,
102+
version: imageReference.version,
103+
}
104+
: {},
105+
osDisk: osDisk
106+
? {
107+
caching: osDisk.caching,
108+
createOption: osDisk.createOption,
109+
osType: osDisk.osType,
110+
diskSizeGB: osDisk.diskSizeGB,
111+
writeAcceleratorEnabled: osDisk.writeAcceleratorEnabled,
112+
managedDisk: osDisk.managedDisk
113+
? {
114+
storageAccountType: osDisk.managedDisk.storageAccountType,
115+
}
116+
: {},
117+
}
118+
: {},
119+
}
120+
}
121+
122+
const formatNetworkProfile = (
123+
networkProfile?: VirtualMachineScaleSetNetworkProfile
124+
): AzureVirtualMachineScaleSetNetworkProfile => {
125+
if (isEmpty(networkProfile)) {
126+
return {}
127+
}
128+
129+
const { networkInterfaceConfigurations = [] } = networkProfile
130+
131+
return {
132+
networkInterfaceConfigurations:
133+
networkInterfaceConfigurations?.map(
134+
({
135+
id,
136+
ipConfigurations = [],
137+
networkSecurityGroup,
138+
...networkInterface
139+
}) => {
140+
return {
141+
id: id || cuid(),
142+
...networkInterface,
143+
networkSecurityGroup: {
144+
id: networkSecurityGroup?.id || cuid(),
145+
},
146+
ipConfigurations:
147+
ipConfigurations?.map(
148+
({
149+
subnet,
150+
publicIPAddressConfiguration,
151+
applicationGatewayBackendAddressPools,
152+
applicationSecurityGroups,
153+
loadBalancerBackendAddressPools,
154+
loadBalancerInboundNatPools,
155+
...ipConfiguration
156+
}) => ({
157+
id: cuid(),
158+
...ipConfiguration,
159+
subnetId: subnet?.id,
160+
applicationGatewayBackendAddressPools:
161+
applicationGatewayBackendAddressPools?.map(agb => ({
162+
id: agb.id || cuid(),
163+
...agb,
164+
})) || [],
165+
applicationSecurityGroups:
166+
applicationSecurityGroups?.map(asg => ({
167+
id: asg.id || cuid(),
168+
...asg,
169+
})) || [],
170+
loadBalancerBackendAddressPools:
171+
loadBalancerBackendAddressPools?.map(lbb => ({
172+
id: lbb.id || cuid(),
173+
...lbb,
174+
})) || [],
175+
loadBalancerInboundNatPools:
176+
loadBalancerInboundNatPools?.map(lbi => ({
177+
id: lbi.id || cuid(),
178+
...lbi,
179+
})) || [],
180+
})
181+
) || [],
182+
}
183+
}
184+
) || [],
185+
}
186+
}
187+
188+
const formatExtensionProfile = (
189+
extensionProfile?: VirtualMachineScaleSetExtensionProfile
190+
): AzureVirtualMachineScaleSetExtension[] => {
191+
if (isEmpty(extensionProfile)) {
192+
return []
193+
}
194+
195+
const { extensions: extensionsList = [] } = extensionProfile
196+
197+
return (
198+
extensionsList?.map(e => ({
199+
id: e.id || cuid(),
200+
name: e.name,
201+
forceUpdateTag: e.forceUpdateTag,
202+
type: e.type,
203+
typeHandlerVersion: e.typeHandlerVersion,
204+
typePropertiesType: e.typePropertiesType,
205+
publisher: e.publisher,
206+
provisioningState: e.provisioningState,
207+
provisionAfterExtensions: e.provisionAfterExtensions,
208+
autoUpgradeMinorVersion: e.autoUpgradeMinorVersion,
209+
enableAutomaticUpgrade: e.enableAutomaticUpgrade,
210+
settings: e.settings ? JSON.stringify(e.settings) : '',
211+
})) || []
212+
)
213+
}
214+
7215
export default ({
8216
service,
9217
account,
@@ -46,64 +254,27 @@ export default ({
46254
}
47255

48256
// Setting Extension Profile
49-
let extensions = []
257+
let extensions: AzureVirtualMachineScaleSetExtension[] = []
50258
if (!isEmpty(extensionProfile)) {
51-
const { extensions: extensionsList = [] } = extensionProfile
52-
extensions = extensionsList.map(({ settings, ...extension }) => ({
53-
id: cuid(),
54-
...extension,
55-
settings: JSON.stringify(settings),
56-
}))
259+
extensions = formatExtensionProfile(extensionProfile)
57260
}
58261

59262
// Setting OS Profile
60263
let os = {}
61264
if (!isEmpty(osProfile)) {
62-
const {
63-
computerNamePrefix,
64-
adminUsername,
65-
linuxConfiguration = {},
66-
windowsConfiguration = {},
67-
secrets = [],
68-
} = osProfile
69-
os = {
70-
computerNamePrefix,
71-
adminUsername,
72-
linuxConfiguration,
73-
windowsConfiguration,
74-
secrets,
75-
}
265+
os = formatOsProfile(osProfile)
76266
}
77267

78268
// Setting Network Profile
79269
let network = {}
80270
if (!isEmpty(networkProfile)) {
81-
const { networkInterfaceConfigurations = [] } = networkProfile
82-
83-
const networkInterfaces = networkInterfaceConfigurations.map(
84-
({ ipConfigurations = [], ...networkInterface }) => {
85-
return {
86-
id: cuid(),
87-
...networkInterface,
88-
ipConfigurations: ipConfigurations.map(
89-
({ subnet, ...ipConfiguration }) => ({
90-
id: cuid(),
91-
...ipConfiguration,
92-
subnetId: subnet?.id,
93-
})
94-
),
95-
}
96-
}
97-
)
98-
99-
network = { networkInterfaceConfigurations: networkInterfaces }
271+
network = formatNetworkProfile(networkProfile)
100272
}
101273

102274
// Setting Storage Profile
103275
let storage = {}
104276
if (!isEmpty(storageProfile)) {
105-
const { imageReference = {}, osDisk = {} } = storageProfile
106-
storage = { imageReference, osDisk }
277+
storage = formatStorageProfile(storageProfile)
107278
}
108279

109280
return {

src/services/virtualMachineScaleSet/schema.graphql

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type azureVirtualMachineScaleSetExtension
1919
name: String @search(by: [hash, regexp])
2020
forceUpdateTag: String @search(by: [hash, regexp])
2121
type: String @search(by: [hash, regexp])
22-
type1: String @search(by: [hash, regexp])
2322
typeHandlerVersion: String @search(by: [hash, regexp])
2423
typePropertiesType: String @search(by: [hash, regexp])
2524
publisher: String @search(by: [hash, regexp])
@@ -197,7 +196,9 @@ type azureSshPublicKey
197196
query: { get: false, query: true, aggregate: false }
198197
mutation: { add: false, delete: false }
199198
subscription: false
200-
) {
199+
)
200+
@key(fields: "id") {
201+
id: String! @id @search(by: [hash, regexp])
201202
path: String @search(by: [hash, regexp])
202203
keyData: String @search(by: [hash, regexp])
203204
}
@@ -239,7 +240,9 @@ type azureVaultCertificate
239240
query: { get: false, query: true, aggregate: false }
240241
mutation: { add: false, delete: false }
241242
subscription: false
242-
) {
243+
)
244+
@key(fields: "id") {
245+
id: String! @id @search(by: [hash, regexp])
243246
certificateUrl: String @search(by: [hash, regexp])
244247
certificateStore: String @search(by: [hash, regexp])
245248
}
@@ -249,7 +252,9 @@ type azureVaultSecretGroup
249252
query: { get: false, query: true, aggregate: false }
250253
mutation: { add: false, delete: false }
251254
subscription: false
252-
) {
255+
)
256+
@key(fields: "id") {
257+
id: String! @id @search(by: [hash, regexp])
253258
sourceVault: azureSubResource
254259
vaultCertificates: [azureVaultCertificate]
255260
}
@@ -263,7 +268,6 @@ type azureVirtualMachineScaleSetOsProfile
263268
computerNamePrefix: String @search(by: [hash, regexp])
264269
adminUsername: String @search(by: [hash, regexp])
265270
allowExtensionOperations: Boolean @search
266-
requireGuestProvisionSignal: Boolean @search
267271
linuxConfiguration: azureVirtualMachineScaleSetOsProfileLinuxConfiguration
268272
windowsConfiguration: azureVirtualMachineScaleSetOsProfileWindowsConfiguration
269273
secrets: [azureVaultSecretGroup]

src/types/generated.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4360,6 +4360,7 @@ export type AzureSshConfiguration = {
43604360
};
43614361

43624362
export type AzureSshPublicKey = {
4363+
id: Scalars['String'];
43634364
keyData?: Maybe<Scalars['String']>;
43644365
path?: Maybe<Scalars['String']>;
43654366
};
@@ -4945,9 +4946,11 @@ export type AzureTrafficManagerProfileMonitorConfigExpectedStatusCodeRangesItem
49454946
export type AzureVaultCertificate = {
49464947
certificateStore?: Maybe<Scalars['String']>;
49474948
certificateUrl?: Maybe<Scalars['String']>;
4949+
id: Scalars['String'];
49484950
};
49494951

49504952
export type AzureVaultSecretGroup = {
4953+
id: Scalars['String'];
49514954
sourceVault?: Maybe<AzureSubResource>;
49524955
vaultCertificates?: Maybe<Array<Maybe<AzureVaultCertificate>>>;
49534956
};
@@ -5016,7 +5019,6 @@ export type AzureVirtualMachineScaleSetExtension = {
50165019
publisher?: Maybe<Scalars['String']>;
50175020
settings?: Maybe<Scalars['String']>;
50185021
type?: Maybe<Scalars['String']>;
5019-
type1?: Maybe<Scalars['String']>;
50205022
typeHandlerVersion?: Maybe<Scalars['String']>;
50215023
typePropertiesType?: Maybe<Scalars['String']>;
50225024
};
@@ -5078,7 +5080,6 @@ export type AzureVirtualMachineScaleSetOsProfile = {
50785080
allowExtensionOperations?: Maybe<Scalars['Boolean']>;
50795081
computerNamePrefix?: Maybe<Scalars['String']>;
50805082
linuxConfiguration?: Maybe<AzureVirtualMachineScaleSetOsProfileLinuxConfiguration>;
5081-
requireGuestProvisionSignal?: Maybe<Scalars['Boolean']>;
50825083
secrets?: Maybe<Array<Maybe<AzureVaultSecretGroup>>>;
50835084
windowsConfiguration?: Maybe<AzureVirtualMachineScaleSetOsProfileWindowsConfiguration>;
50845085
};

0 commit comments

Comments
 (0)