Skip to content

Commit f10c387

Browse files
Fix deserialization issues in system events (#26805)
1 parent d970ca1 commit f10c387

10 files changed

+77
-40
lines changed

sdk/eventgrid/Azure.Messaging.EventGrid/CHANGELOG.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# Release History
22

3-
## 4.9.0-beta.1 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
3+
## 4.8.2 (2022-02-08)
84

95
### Bugs Fixed
6+
- Fixed deserialization bugs in `StorageDirectoryDeletedEventData` and `EventHubCaptureFileCreatedEventData` system events.
107

118
### Other Changes
129

sdk/eventgrid/Azure.Messaging.EventGrid/src/Azure.Messaging.EventGrid.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Description>This library can be used to publish events to Azure Event Grid and to consume events delivered by EventGrid. It also defines the event schemas for the events published to EventGrid by various Azure services.</Description>
44
<AssemblyTitle>Microsoft Azure.Messaging.EventGrid client library</AssemblyTitle>
5-
<Version>4.9.0-beta.1</Version>
5+
<Version>4.8.2</Version>
66
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
77
<ApiCompatVersion>4.8.1</ApiCompatVersion>
88
<PackageTags>Microsoft Azure EventGrid;Event Grid;Event Grid Publishing;</PackageTags>

sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/EventGridModelFactory.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,21 @@ public static ResourceHttpRequest ResourceHttpRequest(string clientRequestId = n
490490
{
491491
return new ResourceHttpRequest(clientRequestId, clientIpAddress, method?.Method, url);
492492
}
493+
494+
/// <summary> Initializes a new instance of StorageDirectoryDeletedEventData. </summary>
495+
/// <param name="api"> The name of the API/operation that triggered this event. </param>
496+
/// <param name="clientRequestId"> A request id provided by the client of the storage API operation that triggered this event. </param>
497+
/// <param name="requestId"> The request id generated by the storage service for the storage API operation that triggered this event. </param>
498+
/// <param name="url"> The path to the deleted directory. </param>
499+
/// <param name="recursive"> Is this event for a recursive delete operation. </param>
500+
/// <param name="sequencer"> An opaque string value representing the logical sequence of events for any particular directory name. Users can use standard string comparison to understand the relative sequence of two events on the same directory name. </param>
501+
/// <param name="identity"> The identity of the requester that triggered this event. </param>
502+
/// <param name="storageDiagnostics"> For service use only. Diagnostic data occasionally included by the Azure Storage service. This property should be ignored by event consumers. </param>
503+
/// <returns> A new <see cref="SystemEvents.StorageDirectoryDeletedEventData"/> instance for mocking. </returns>
504+
public static StorageDirectoryDeletedEventData StorageDirectoryDeletedEventData(string api = null, string clientRequestId = null, string requestId = null, string url = null, bool? recursive = null, string sequencer = null, string identity = null, object storageDiagnostics = null)
505+
{
506+
return new StorageDirectoryDeletedEventData(api, clientRequestId, requestId, url, recursive?.ToString(), sequencer, identity, storageDiagnostics);
507+
}
493508
}
494509
#pragma warning restore CA1054 // URI-like parameters should not be strings
495510
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Messaging.EventGrid.SystemEvents
7+
{
8+
/// <summary> Schema of the Data property of an EventGridEvent for a Microsoft.Storage.DirectoryDeleted event. </summary>
9+
public partial class StorageDirectoryDeletedEventData
10+
{
11+
[CodeGenMember("Recursive")]
12+
internal string RecursiveString { get; }
13+
14+
/// <summary>
15+
/// Is this event for a recursive delete operation.
16+
/// </summary>
17+
public bool? Recursive
18+
{
19+
get
20+
{
21+
if (_recursive == null && RecursiveString != null)
22+
{
23+
_recursive = bool.Parse(RecursiveString);
24+
}
25+
26+
return _recursive;
27+
}
28+
}
29+
30+
private bool? _recursive;
31+
}
32+
}

sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/EventGridModelFactory.cs

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/EventHubCaptureFileCreatedEventData.Serialization.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/StorageDirectoryDeletedEventData.Serialization.cs

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/StorageDirectoryDeletedEventData.cs

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/eventgrid/Azure.Messaging.EventGrid/src/autorest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Run `dotnet build /t:GenerateCode` to generate code.
44

55
``` yaml
66
title: EventGridClient
7-
require: https://github.com/Azure/azure-rest-api-specs/blob/409af02e5ca217c7e7ec2acf50f4976c053496f8/specification/eventgrid/data-plane/readme.md
7+
require: https://github.com/Azure/azure-rest-api-specs/blob/03da592cccfa0e52ccd6ecc53d232afda8a38c95/specification/eventgrid/data-plane/readme.md
88
```
99
1010
## Swagger workarounds

sdk/eventgrid/Azure.Messaging.EventGrid/tests/ConsumeEventTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,13 +1287,27 @@ public void ConsumeStorageDirectoryCreatedEvent()
12871287
[Test]
12881288
public void ConsumeStorageDirectoryDeletedEvent()
12891289
{
1290-
string requestContent = "[{ \"topic\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"eventType\": \"Microsoft.Storage.DirectoryDeleted\", \"eventTime\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"api\": \"DeleteDirectory\", \"requestId\": \"4c2359fe-001e-00ba-0e04-585868000000\", \"url\": \"https://example.blob.core.windows.net/testcontainer/testDir\", \"sequencer\": \"0000000000000281000000000002F5CA\", \"storageDiagnostics\": { \"batchId\": \"b68529f3-68cd-4744-baa4-3c0498ec19f0\" } }, \"dataVersion\": \"1\", \"metadataVersion\": \"1\"}]";
1290+
string requestContent = "[{ \"topic\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"eventType\": \"Microsoft.Storage.DirectoryDeleted\", \"eventTime\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"api\": \"DeleteDirectory\", \"requestId\": \"4c2359fe-001e-00ba-0e04-585868000000\", \"url\": \"https://example.blob.core.windows.net/testcontainer/testDir\", \"sequencer\": \"0000000000000281000000000002F5CA\", \"storageDiagnostics\": { \"batchId\": \"b68529f3-68cd-4744-baa4-3c0498ec19f0\" } }, \"dataVersion\": \"1\", \"metadataVersion\": \"1\"}]";
12911291

12921292
EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent));
12931293

12941294
Assert.NotNull(events);
12951295
Assert.True(events[0].TryGetSystemEventData(out object eventData));
12961296
Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageDirectoryDeletedEventData).Url);
1297+
Assert.IsNull((eventData as StorageDirectoryDeletedEventData).Recursive);
1298+
}
1299+
1300+
[Test]
1301+
public void ConsumeStorageDirectoryDeletedEvent_Recursive()
1302+
{
1303+
string requestContent = "[{ \"topic\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"eventType\": \"Microsoft.Storage.DirectoryDeleted\", \"eventTime\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"recursive\":\"true\", \"api\": \"DeleteDirectory\", \"requestId\": \"4c2359fe-001e-00ba-0e04-585868000000\", \"url\": \"https://example.blob.core.windows.net/testcontainer/testDir\", \"sequencer\": \"0000000000000281000000000002F5CA\", \"storageDiagnostics\": { \"batchId\": \"b68529f3-68cd-4744-baa4-3c0498ec19f0\" } }, \"dataVersion\": \"1\", \"metadataVersion\": \"1\"}]";
1304+
1305+
EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent));
1306+
1307+
Assert.NotNull(events);
1308+
Assert.True(events[0].TryGetSystemEventData(out object eventData));
1309+
Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageDirectoryDeletedEventData).Url);
1310+
Assert.IsTrue((eventData as StorageDirectoryDeletedEventData).Recursive);
12971311
}
12981312

12991313
[Test]
@@ -1964,6 +1978,7 @@ public void ConsumeCloudEventEventHubCaptureFileCreatedEvent()
19641978
Assert.NotNull(events);
19651979
Assert.True(events[0].TryGetSystemEventData(out object eventData));
19661980
Assert.AreEqual("AzureBlockBlob", (eventData as EventHubCaptureFileCreatedEventData).FileType);
1981+
Assert.AreEqual("https://tf0831datamigrate.blob.core.windows.net/windturbinecapture/tfdatamigratens/hubdatamigration/1/2017/08/31/19/11/45.avro", (eventData as EventHubCaptureFileCreatedEventData).Fileurl);
19671982
}
19681983
#endregion
19691984

0 commit comments

Comments
 (0)