Skip to content

Commit e167a7f

Browse files
author
Rakshith Bhyravabhotla
authored
generate names from swagger (Azure#21946)
* generate names from swagger * backward compat * backward compat * Update sdk/eventgrid/azure-eventgrid/swagger/postprocess_eventnames.py * comments * warning
1 parent dc00071 commit e167a7f

File tree

3 files changed

+93
-49
lines changed

3 files changed

+93
-49
lines changed

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_event_mappings.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# --------------------------------------------------------------------------------------------
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
5+
# THE VALUES IN THE ENUM ARE AUTO-GENERATED. DO NOT EDIT THIS MANUALLY.
46
# --------------------------------------------------------------------------------------------
57
from enum import Enum
68

@@ -51,6 +53,16 @@ class SystemEventNames(str, Enum):
5153

5254
IoTHubDeviceCreatedEventName = 'Microsoft.Devices.DeviceCreated'
5355

56+
ContainerRegistryArtifactEventName = 'Microsoft.AppConfiguration.KeyValueModified'
57+
58+
KeyVaultAccessPolicyChangedEventName = 'Microsoft.KeyVault.VaultAccessPolicyChanged'
59+
60+
ContainerRegistryEventName = 'Microsoft.ContainerRegistry.ChartPushed'
61+
62+
SubscriptionDeletedEventName = 'Microsoft.EventGrid.SubscriptionDeletedEvent'
63+
64+
SubscriptionValidationEventName = 'Microsoft.EventGrid.SubscriptionValidationEvent'
65+
5466
# backward compat names end here.
5567
AcsChatMessageDeletedEventName = 'Microsoft.Communication.ChatMessageDeleted'
5668

@@ -126,14 +138,10 @@ class SystemEventNames(str, Enum):
126138

127139
AppConfigurationKeyValueModifiedEventName = 'Microsoft.AppConfiguration.KeyValueModified'
128140

129-
ContainerRegistryArtifactEventName = 'Microsoft.AppConfiguration.KeyValueModified'
130-
131141
ContainerRegistryChartDeletedEventName = 'Microsoft.ContainerRegistry.ChartDeleted'
132142

133143
ContainerRegistryChartPushedEventName = 'Microsoft.ContainerRegistry.ChartPushed'
134144

135-
ContainerRegistryEventName = 'Microsoft.ContainerRegistry.ChartPushed'
136-
137145
ContainerRegistryImageDeletedEventName = 'Microsoft.ContainerRegistry.ImageDeleted'
138146

139147
ContainerRegistryImagePushedEventName = 'Microsoft.ContainerRegistry.ImagePushed'
@@ -152,8 +160,6 @@ class SystemEventNames(str, Enum):
152160

153161
IotHubDeviceTelemetryEventName = 'Microsoft.Devices.DeviceTelemetry'
154162

155-
KeyVaultAccessPolicyChangedEventName = 'Microsoft.KeyVault.VaultAccessPolicyChanged'
156-
157163
KeyVaultCertificateExpiredEventName = 'Microsoft.KeyVault.CertificateExpired'
158164

159165
KeyVaultCertificateNearExpiryEventName = 'Microsoft.KeyVault.CertificateNearExpiry'
@@ -172,6 +178,8 @@ class SystemEventNames(str, Enum):
172178

173179
KeyVaultSecretNewVersionCreatedEventName = 'Microsoft.KeyVault.SecretNewVersionCreated'
174180

181+
KeyVaultVaultAccessPolicyChangedEventName = 'Microsoft.KeyVault.VaultAccessPolicyChanged'
182+
175183
MachineLearningServicesDatasetDriftDetectedEventName = 'Microsoft.MachineLearningServices.DatasetDriftDetected'
176184

177185
MachineLearningServicesModelDeployedEventName = 'Microsoft.MachineLearningServices.ModelDeployed'
@@ -302,10 +310,6 @@ class SystemEventNames(str, Enum):
302310

303311
StorageLifecyclePolicyCompletedEventName = 'Microsoft.Storage.LifecyclePolicyCompleted'
304312

305-
SubscriptionDeletedEventName = 'Microsoft.EventGrid.SubscriptionDeletedEvent'
306-
307-
SubscriptionValidationEventName = 'Microsoft.EventGrid.SubscriptionValidationEvent'
308-
309313
WebAppServicePlanUpdatedEventName = 'Microsoft.Web.AppServicePlanUpdated'
310314

311315
WebAppUpdatedEventName = 'Microsoft.Web.AppUpdated'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#############################################################################
2+
####These files are used to extract the enums - update this list as necessary
3+
#############################################################################
4+
files = [
5+
6+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Communication/stable/2018-01-01/AzureCommunicationServices.json",
7+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.ApiManagement/stable/2018-01-01/APIManagement.json",
8+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.AppConfiguration/stable/2018-01-01/AppConfiguration.json",
9+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.ContainerRegistry/stable/2018-01-01/ContainerRegistry.json",
10+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.ContainerService/stable/2018-01-01/ContainerService.json",
11+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.EventHub/stable/2018-01-01/EventHub.json",
12+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Devices/stable/2018-01-01/IotHub.json",
13+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.KeyVault/stable/2018-01-01/KeyVault.json",
14+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.MachineLearningServices/stable/2018-01-01/MachineLearningServices.json",
15+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Media/stable/2018-01-01/MediaServices.json",
16+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Maps/stable/2018-01-01/Maps.json",
17+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.PolicyInsights/stable/2018-01-01/PolicyInsights.json",
18+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Cache/stable/2018-01-01/RedisCache.json",
19+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Resources/stable/2018-01-01/Resources.json",
20+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.ServiceBus/stable/2018-01-01/ServiceBus.json",
21+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.SignalRService/stable/2018-01-01/SignalRService.json",
22+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Storage/stable/2018-01-01/Storage.json",
23+
"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/eventgrid/data-plane/Microsoft.Web/stable/2018-01-01/Web.json",
24+
]
25+
26+
27+
#######################################################
28+
### Used for backward compatibility. Don't change this
29+
#######################################################
30+
backward_compat = {
31+
'AcsChatMemberAddedToThreadWithUserEventName': "Microsoft.Communication.ChatMemberAddedToThreadWithUser",
32+
'ResourceWriteFailureEventName': "Microsoft.Resources.ResourceWriteFailure",
33+
'IoTHubDeviceDeletedEventName': "Microsoft.Devices.DeviceDeleted",
34+
'IoTHubDeviceDisconnectedEventName': "Microsoft.Devices.DeviceDisconnected",
35+
'ResourceDeleteFailureEventName': "Microsoft.Resources.ResourceDeleteFailure",
36+
'ResourceDeleteCancelEventName': "Microsoft.Resources.ResourceDeleteCancel",
37+
'AcsChatThreadParticipantAddedEventName': "Microsoft.Communication.ChatThreadParticipantAdded",
38+
'ResourceDeleteSuccessEventName': "Microsoft.Resources.ResourceDeleteSuccess",
39+
'EventGridSubscriptionValidationEventName': "Microsoft.EventGrid.SubscriptionValidationEvent",
40+
'ResourceWriteSuccessEventName': "Microsoft.Resources.ResourceWriteSuccess",
41+
'ResourceActionSuccessEventName': "Microsoft.Resources.ResourceActionSuccess",
42+
'ResourceWriteCancelEventName': "Microsoft.Resources.ResourceWriteCancel",
43+
'ResourceActionFailureEventName': "Microsoft.Resources.ResourceActionFailure",
44+
'AcsChatMemberRemovedFromThreadWithUserEventName': "Microsoft.Communication.ChatMemberRemovedFromThreadWithUser",
45+
'IoTHubDeviceConnectedEventName': "Microsoft.Devices.DeviceConnected",
46+
'EventGridSubscriptionDeletedEventName': "Microsoft.EventGrid.SubscriptionDeletedEvent",
47+
'AcsChatThreadParticipantRemovedEventName': "Microsoft.Communication.ChatThreadParticipantRemoved",
48+
'ResourceActionCancelEventName': "Microsoft.Resources.ResourceActionCancel",
49+
'IoTHubDeviceCreatedEventName': "Microsoft.Devices.DeviceCreated",
50+
'ContainerRegistryArtifactEventName': 'Microsoft.AppConfiguration.KeyValueModified',
51+
'KeyVaultAccessPolicyChangedEventName': 'Microsoft.KeyVault.VaultAccessPolicyChanged',
52+
'ContainerRegistryEventName': 'Microsoft.ContainerRegistry.ChartPushed',
53+
'SubscriptionDeletedEventName': 'Microsoft.EventGrid.SubscriptionDeletedEvent',
54+
'SubscriptionValidationEventName': 'Microsoft.EventGrid.SubscriptionValidationEvent',
55+
'ServiceBusDeadletterMessagesAvailableWithNoListenerEventName': 'Microsoft.ServiceBus.DeadletterMessagesAvailableWithNoListeners'
56+
}
57+
58+
EXCEPTIONS = ['ContainerRegistryArtifactEventData', 'ContainerRegistryEventData']
Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,25 @@
1-
import inspect
1+
import json
22
import re
33
import warnings
44
import sys
5+
from urllib.request import urlopen
56
from azure.eventgrid._generated import models
7+
from _constants import files, backward_compat, EXCEPTIONS
68

7-
backward_compat = {
8-
'AcsChatMemberAddedToThreadWithUserEventName': "Microsoft.Communication.ChatMemberAddedToThreadWithUser",
9-
'ResourceWriteFailureEventName': "Microsoft.Resources.ResourceWriteFailure",
10-
'IoTHubDeviceDeletedEventName': "Microsoft.Devices.DeviceDeleted",
11-
'IoTHubDeviceDisconnectedEventName': "Microsoft.Devices.DeviceDisconnected",
12-
'ResourceDeleteFailureEventName': "Microsoft.Resources.ResourceDeleteFailure",
13-
'ResourceDeleteCancelEventName': "Microsoft.Resources.ResourceDeleteCancel",
14-
'AcsChatThreadParticipantAddedEventName': "Microsoft.Communication.ChatThreadParticipantAdded",
15-
'ResourceDeleteSuccessEventName': "Microsoft.Resources.ResourceDeleteSuccess",
16-
'EventGridSubscriptionValidationEventName': "Microsoft.EventGrid.SubscriptionValidationEvent",
17-
'ResourceWriteSuccessEventName': "Microsoft.Resources.ResourceWriteSuccess",
18-
'ResourceActionSuccessEventName': "Microsoft.Resources.ResourceActionSuccess",
19-
'ResourceWriteCancelEventName': "Microsoft.Resources.ResourceWriteCancel",
20-
'ResourceActionFailureEventName': "Microsoft.Resources.ResourceActionFailure",
21-
'AcsChatMemberRemovedFromThreadWithUserEventName': "Microsoft.Communication.ChatMemberRemovedFromThreadWithUser",
22-
'IoTHubDeviceConnectedEventName': "Microsoft.Devices.DeviceConnected",
23-
'EventGridSubscriptionDeletedEventName': "Microsoft.EventGrid.SubscriptionDeletedEvent",
24-
'AcsChatThreadParticipantRemovedEventName': "Microsoft.Communication.ChatThreadParticipantRemoved",
25-
'ResourceActionCancelEventName': "Microsoft.Resources.ResourceActionCancel",
26-
'IoTHubDeviceCreatedEventName': "Microsoft.Devices.DeviceCreated"
27-
}
28-
29-
def event_tuples(system_events):
30-
tup_list = []
31-
for event in system_events:
32-
class_name = "Name".join(event[0].rsplit('Data', 1))
33-
try:
34-
event_name = re.findall("Microsoft.[a-zA-Z]+.[a-zA-Z]+", event[1].__doc__)[0]
35-
except:
36-
# these two are just superclasses and are known exceptions.
37-
if event[0] not in ('ContainerRegistryArtifactEventData', 'ContainerRegistryEventData'):
9+
def extract(definitions):
10+
if not definitions:
11+
return
12+
tups = []
13+
for event in definitions:
14+
if event.endswith('Data') and event not in EXCEPTIONS:
15+
try:
16+
key, txt = "Name".join(event.rsplit('Data', 1)), definitions[event]['description']
17+
val = re.findall("Microsoft.[a-zA-Z]+.[a-zA-Z]+", txt)
18+
tups.append((key, val[0]))
19+
except:
3820
warnings.warn("Unable to generate the event mapping for {}".format(event[0]))
3921
sys.exit(1)
40-
tup_list.append((class_name, event_name))
41-
return tup_list
22+
return tups
4223

4324
def generate_enum_content(tuples):
4425
print("# these names below are for backward compat only - refrain from using them.")
@@ -47,10 +28,11 @@ def generate_enum_content(tuples):
4728
print("# backward compat names end here.")
4829
for tup in tup_list:
4930
print(tup[0] + " = '" + tup[1].replace('API', 'Api') + "'\n")
50-
print("# servicebus alias")
51-
print("ServiceBusDeadletterMessagesAvailableWithNoListenerEventName = 'Microsoft.ServiceBus.DeadletterMessagesAvailableWithNoListeners'")
52-
53-
system_events = [m for m in inspect.getmembers(models) if m[0].endswith('Data')]
54-
tup_list = event_tuples(system_events)
5531

32+
definitions = {}
33+
for fp in files:
34+
data = json.loads(urlopen(fp).read())
35+
definitions.update(data.get('definitions'))
36+
tup_list = extract(definitions)
37+
tup_list.sort(key=lambda tup: tup[0])
5638
generate_enum_content(tup_list)

0 commit comments

Comments
 (0)