Skip to content

Commit 90131c8

Browse files
committed
feat(azure): add missing mySQL Server services
1 parent bf93510 commit 90131c8

File tree

4 files changed

+244
-24
lines changed

4 files changed

+244
-24
lines changed

src/services/mySqlServers/data.ts

Lines changed: 129 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { MySQLManagementClient, Server } from '@azure/arm-mysql'
1+
import {
2+
Configuration,
3+
FirewallRule,
4+
MySQLManagementClient,
5+
Server,
6+
VirtualNetworkRule,
7+
} from '@azure/arm-mysql'
28
import { PagedAsyncIterableIterator } from '@azure/core-paging'
39
import CloudGraph from '@cloudgraph/sdk'
410
import azureLoggerText from '../../properties/logger'
@@ -11,11 +17,97 @@ const { logger } = CloudGraph
1117
const lt = { ...azureLoggerText }
1218
const serviceName = 'MySQL Server'
1319

14-
export interface RawAzureMySqlServer
15-
extends Omit<Server, 'tags' | 'location'> {
20+
export interface RawAzureMySqlServer extends Omit<Server, 'tags' | 'location'> {
1621
region: string
1722
resourceGroupId: string
1823
Tags: TagMap
24+
configurations: Configuration[]
25+
firewallRules: FirewallRule[]
26+
virtualNetworkRules: VirtualNetworkRule[]
27+
}
28+
29+
const listConfigurations = async (
30+
client: MySQLManagementClient,
31+
resourceGroup: string,
32+
serverName: string
33+
): Promise<Configuration[]> => {
34+
const configurations: Configuration[] = []
35+
const configurationsIterable = client.configurations.listByServer(
36+
resourceGroup,
37+
serverName
38+
)
39+
await tryCatchWrapper(
40+
async () => {
41+
for await (const configuration of configurationsIterable) {
42+
if (configuration) {
43+
configurations.push(configuration)
44+
}
45+
}
46+
},
47+
{
48+
service: serviceName,
49+
client,
50+
scope: 'configurations',
51+
operation: 'listByServer',
52+
}
53+
)
54+
return configurations
55+
}
56+
57+
const listFirewallRules = async (
58+
client: MySQLManagementClient,
59+
resourceGroup: string,
60+
serverName: string
61+
): Promise<FirewallRule[]> => {
62+
const firewallRules: FirewallRule[] = []
63+
const firewallRuleIterable = client.firewallRules.listByServer(
64+
resourceGroup,
65+
serverName
66+
)
67+
await tryCatchWrapper(
68+
async () => {
69+
for await (const firewallRule of firewallRuleIterable) {
70+
if (firewallRule) {
71+
firewallRules.push(firewallRule)
72+
}
73+
}
74+
},
75+
{
76+
service: serviceName,
77+
client,
78+
scope: 'firewallRules',
79+
operation: 'listByServer',
80+
}
81+
)
82+
return firewallRules
83+
}
84+
85+
const listVirtualNetworkRules = async (
86+
client: MySQLManagementClient,
87+
resourceGroup: string,
88+
serverName: string
89+
): Promise<VirtualNetworkRule[]> => {
90+
const virtualNetworkRules: VirtualNetworkRule[] = []
91+
const virtualNetworkRulesIterable = client.virtualNetworkRules.listByServer(
92+
resourceGroup,
93+
serverName
94+
)
95+
await tryCatchWrapper(
96+
async () => {
97+
for await (const virtualNetworkRule of virtualNetworkRulesIterable) {
98+
if (virtualNetworkRule) {
99+
virtualNetworkRules.push(virtualNetworkRule)
100+
}
101+
}
102+
},
103+
{
104+
service: serviceName,
105+
client,
106+
scope: 'virtualNetworkRules',
107+
operation: 'listByServer',
108+
}
109+
)
110+
return virtualNetworkRules
19111
}
20112

21113
export default async ({
@@ -26,10 +118,7 @@ export default async ({
26118
}> => {
27119
try {
28120
const { tokenCredentials, subscriptionId } = config
29-
const client = new MySQLManagementClient(
30-
tokenCredentials,
31-
subscriptionId
32-
)
121+
const client = new MySQLManagementClient(tokenCredentials, subscriptionId)
33122
const sqlServers: Server[] = []
34123
const sqlServerIterable: PagedAsyncIterableIterator<Server> =
35124
client.servers.list()
@@ -49,21 +138,40 @@ export default async ({
49138
logger.debug(lt.foundMySqlServers(sqlServers.length))
50139

51140
const result: { [property: string]: RawAzureMySqlServer[] } = {}
52-
sqlServers.map(({ location, tags, ...rest }) => {
53-
const region = lowerCaseLocation(location)
54-
if (regions.includes(region)) {
55-
if (!result[region]) {
56-
result[region] = []
141+
await Promise.all(
142+
sqlServers.map(async ({ name, location, tags, ...rest }) => {
143+
const region = lowerCaseLocation(location)
144+
if (regions.includes(region)) {
145+
if (!result[region]) {
146+
result[region] = []
147+
}
148+
const resourceGroupId = getResourceGroupFromEntity(rest)
149+
result[region].push({
150+
name,
151+
region,
152+
...rest,
153+
resourceGroupId,
154+
Tags: tags || {},
155+
configurations: await listConfigurations(
156+
client,
157+
resourceGroupId,
158+
name
159+
),
160+
firewallRules: await listFirewallRules(
161+
client,
162+
resourceGroupId,
163+
name
164+
),
165+
virtualNetworkRules: await listVirtualNetworkRules(
166+
client,
167+
resourceGroupId,
168+
name
169+
),
170+
})
57171
}
58-
const resourceGroupId = getResourceGroupFromEntity(rest)
59-
result[region].push({
60-
region,
61-
...rest,
62-
resourceGroupId,
63-
Tags: tags || {},
64-
})
65-
}
66-
})
172+
})
173+
)
174+
67175
return result
68176
} catch (e) {
69177
logger.error(e)

src/services/mySqlServers/format.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { formatTagsFromMap } from '../../utils/format'
22
import { RawAzureMySqlServer } from './data'
3-
import { AzureMySqlServer } from '../../types/generated'
3+
import {
4+
AzureMySqlServer,
5+
AzureMySqlServerConfiguration,
6+
AzureMySqlServerFirewallRule,
7+
AzureMySqlServerVirtualNetworkRule,
8+
} from '../../types/generated'
49

510
export default ({
611
service,
@@ -33,6 +38,9 @@ export default ({
3338
privateEndpointConnections,
3439
resourceGroupId,
3540
Tags,
41+
configurations = [],
42+
firewallRules = [],
43+
virtualNetworkRules = [],
3644
} = service
3745

3846
return {
@@ -60,7 +68,47 @@ export default ({
6068
privateEndpointConnections: privateEndpointConnections?.map(connection => ({
6169
...connection,
6270
id: connection.id,
63-
})),
71+
})),
6472
tags: formatTagsFromMap(Tags),
73+
configurations:
74+
configurations?.map(
75+
({
76+
id: configurationId,
77+
name: configurationName,
78+
type: configurationType,
79+
}): AzureMySqlServerConfiguration => ({
80+
id: configurationId,
81+
name: configurationName,
82+
type: configurationType,
83+
})
84+
) ?? [],
85+
firewallRules:
86+
firewallRules?.map(
87+
({
88+
id: firewallRuleId,
89+
name: firewallRuleName,
90+
type: firewallRuleType,
91+
startIpAddress,
92+
endIpAddress,
93+
}): AzureMySqlServerFirewallRule => ({
94+
id: firewallRuleId,
95+
name: firewallRuleName,
96+
type: firewallRuleType,
97+
startIpAddress,
98+
endIpAddress,
99+
})
100+
) ?? [],
101+
virtualNetworkRules:
102+
virtualNetworkRules?.map(
103+
({
104+
id: virtualNetworkRuleId,
105+
name: virtualNetworkRuleName,
106+
type: virtualNetworkRuleType,
107+
}): AzureMySqlServerVirtualNetworkRule => ({
108+
id: virtualNetworkRuleId,
109+
name: virtualNetworkRuleName,
110+
type: virtualNetworkRuleType,
111+
})
112+
) ?? [],
65113
}
66-
}
114+
}

src/services/mySqlServers/schema.graphql

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type azureMySqlServer implements azureResource
1919
replicaCapacity: Int @search
2020
publicNetworkAccess: String @search(by: [hash, regexp])
2121
privateEndpointConnections: [azureMySqlServerServerPrivateEndpointConnection]
22+
configurations: [azureMySqlServerConfiguration]
23+
firewallRules: [azureMySqlServerFirewallRule]
24+
virtualNetworkRules: [azureMySqlServerVirtualNetworkRule]
2225
databaseMySql: [azureDatabaseMySql] @hasInverse(field: mySqlServer)
2326
resourceGroup: [azureResourceGroup] @hasInverse(field: mySqlServer)
2427
}
@@ -81,4 +84,42 @@ type azureMySqlServerServerPrivateLinkServiceConnectionStateProperty
8184
status: String @search(by: [hash, regexp])
8285
description: String @search(by: [hash, regexp])
8386
actionsRequired: String @search(by: [hash, regexp])
87+
}
88+
89+
type azureMySqlServerConfiguration
90+
@generate(
91+
query: { get: false, query: true, aggregate: false }
92+
mutation: { add: false, delete: false }
93+
subscription: false
94+
)
95+
@key(fields: "id") {
96+
id: String! @id @search(by: [hash])
97+
name: String @search(by: [hash, regexp])
98+
type: String @search(by: [hash, regexp])
99+
}
100+
101+
type azureMySqlServerFirewallRule
102+
@generate(
103+
query: { get: false, query: true, aggregate: false }
104+
mutation: { add: false, delete: false }
105+
subscription: false
106+
)
107+
@key(fields: "id") {
108+
id: String! @id @search(by: [hash])
109+
name: String @search(by: [hash, regexp])
110+
type: String @search(by: [hash, regexp])
111+
startIpAddress: String @search(by: [hash, regexp])
112+
endIpAddress: String @search(by: [hash, regexp])
113+
}
114+
115+
type azureMySqlServerVirtualNetworkRule
116+
@generate(
117+
query: { get: false, query: true, aggregate: false }
118+
mutation: { add: false, delete: false }
119+
subscription: false
120+
)
121+
@key(fields: "id") {
122+
id: String! @id @search(by: [hash])
123+
name: String @search(by: [hash, regexp])
124+
type: String @search(by: [hash, regexp])
84125
}

src/types/generated.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4078,8 +4078,10 @@ export type AzureMetricAlertMultiMetricCriteria = {
40784078
export type AzureMySqlServer = AzureResource & {
40794079
administratorLogin?: Maybe<Scalars['String']>;
40804080
byokEnforcement?: Maybe<Scalars['String']>;
4081+
configurations?: Maybe<Array<Maybe<AzureMySqlServerConfiguration>>>;
40814082
databaseMySql?: Maybe<Array<Maybe<AzureDatabaseMySql>>>;
40824083
earliestRestoreDate?: Maybe<Scalars['String']>;
4084+
firewallRules?: Maybe<Array<Maybe<AzureMySqlServerFirewallRule>>>;
40834085
fullyQualifiedDomainName?: Maybe<Scalars['String']>;
40844086
identity?: Maybe<AzureMySqlServerResourceIdentity>;
40854087
infrastructureEncryption?: Maybe<Scalars['String']>;
@@ -4094,6 +4096,21 @@ export type AzureMySqlServer = AzureResource & {
40944096
storageProfile?: Maybe<AzureMySqlServerStorageProfile>;
40954097
userVisibleState?: Maybe<Scalars['String']>;
40964098
version?: Maybe<Scalars['String']>;
4099+
virtualNetworkRules?: Maybe<Array<Maybe<AzureMySqlServerVirtualNetworkRule>>>;
4100+
};
4101+
4102+
export type AzureMySqlServerConfiguration = {
4103+
id: Scalars['String'];
4104+
name?: Maybe<Scalars['String']>;
4105+
type?: Maybe<Scalars['String']>;
4106+
};
4107+
4108+
export type AzureMySqlServerFirewallRule = {
4109+
endIpAddress?: Maybe<Scalars['String']>;
4110+
id: Scalars['String'];
4111+
name?: Maybe<Scalars['String']>;
4112+
startIpAddress?: Maybe<Scalars['String']>;
4113+
type?: Maybe<Scalars['String']>;
40974114
};
40984115

40994116
export type AzureMySqlServerPrivateEndpointProperty = {
@@ -4130,6 +4147,12 @@ export type AzureMySqlServerStorageProfile = {
41304147
storageMB?: Maybe<Scalars['Int']>;
41314148
};
41324149

4150+
export type AzureMySqlServerVirtualNetworkRule = {
4151+
id: Scalars['String'];
4152+
name?: Maybe<Scalars['String']>;
4153+
type?: Maybe<Scalars['String']>;
4154+
};
4155+
41334156
export type AzureNameValueProperty = {
41344157
id: Scalars['String'];
41354158
name?: Maybe<Scalars['String']>;

0 commit comments

Comments
 (0)