From 208f1f8c12d48ff191290fe88e03a61c8bc91e05 Mon Sep 17 00:00:00 2001 From: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Date: Mon, 10 May 2021 13:44:11 -0700 Subject: [PATCH] Prepare for EG release --- .../Azure.Messaging.EventGrid/CHANGELOG.md | 9 +- .../src/Azure.Messaging.EventGrid.csproj | 2 +- .../tests/ConsumeEventTests.cs | 120 ++++++++++++++++++ 3 files changed, 129 insertions(+), 2 deletions(-) diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/CHANGELOG.md b/sdk/eventgrid/Azure.Messaging.EventGrid/CHANGELOG.md index 041dc4666a72e..3e2eefcc46210 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/CHANGELOG.md +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/CHANGELOG.md @@ -1,7 +1,14 @@ # Release History -## 4.2.0-beta.1 (Unreleased) +## 4.2.0 (2021-05-10) +### New Features +* Added the following new system events: + - PolicyInsightsPolicyStateChangedEventData + - PolicyInsightsPolicyStateCreatedEventData + - PolicyInsightsPolicyStateDeletedEventData + - StorageAsyncOperationInitiatedEventData + - StorageBlobTierChangedEventData ## 4.1.0 (2021-03-23) diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Azure.Messaging.EventGrid.csproj b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Azure.Messaging.EventGrid.csproj index d74a49ac40095..0bf71dcb08460 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Azure.Messaging.EventGrid.csproj +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Azure.Messaging.EventGrid.csproj @@ -2,7 +2,7 @@ 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. Microsoft Azure.Messaging.EventGrid client library - 4.2.0-beta.1 + 4.2.0 4.1.0 Microsoft Azure EventGrid;Event Grid;Event Grid Publishing; diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/ConsumeEventTests.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/ConsumeEventTests.cs index ab4c78192cc32..da535a01dd521 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/tests/ConsumeEventTests.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/tests/ConsumeEventTests.cs @@ -1149,6 +1149,28 @@ public void ConsumeStorageDirectoryRenamedEvent() Assert.True(events[0].TryGetSystemEventData(out object eventData)); Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageDirectoryRenamedEventData).DestinationUrl); } + + [Test] + public void ConsumeStorageAsyncOperationInitiatedEvent() + { + string requestContent = "[{ \"topic\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"eventType\": \"Microsoft.Storage.AsyncOperationInitiated\", \"eventTime\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"api\": \"RenameDirectory\", \"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.0\"}]"; + EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageAsyncOperationInitiatedEventData).Url); + } + + [Test] + public void ConsumeStorageBlobTierChangedEvent() + { + string requestContent = "[{ \"topic\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"eventType\": \"Microsoft.Storage.BlobTierChanged\", \"eventTime\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"api\": \"RenameDirectory\", \"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.0\"}]"; + EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageBlobTierChangedEventData).Url); + } #endregion #region App Service events @@ -1327,6 +1349,44 @@ public void ConsumeWebAppServicePlanUpdatedEvent() Assert.AreEqual(planName, (eventData as WebAppServicePlanUpdatedEventData).Name); } #endregion + + #region Policy Insights + [Test] + public void ConsumePolicyInsightsPolicyStateChangedEvent() + { + string requestContent = "[ { \"source\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"eventType\":\"Microsoft.PolicyInsights.PolicyStateChanged\", \"eventTime\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"timestamp\":\"2017-08-16T03:54:38.2696833Z\", \"policyDefinitionId\":\"4c2359fe-001e-00ba-0e04-585868000000\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"subscriptionId\":\"{subscription-id}\" }, \"dataVersion\": \"1.0\" }]"; + + EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("4c2359fe-001e-00ba-0e04-585868000000", (eventData as PolicyInsightsPolicyStateChangedEventData).PolicyDefinitionId); + } + + [Test] + public void ConsumePolicyInsightsPolicyStateCreatedEvent() + { + string requestContent = "[ { \"source\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"eventType\":\"Microsoft.PolicyInsights.PolicyStateCreated\", \"eventTime\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"timestamp\":\"2017-08-16T03:54:38.2696833Z\", \"policyDefinitionId\":\"4c2359fe-001e-00ba-0e04-585868000000\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"subscriptionId\":\"{subscription-id}\" }, \"dataVersion\": \"1.0\" }]"; + + EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("4c2359fe-001e-00ba-0e04-585868000000", (eventData as PolicyInsightsPolicyStateCreatedEventData).PolicyDefinitionId); + } + + [Test] + public void ConsumePolicyInsightsPolicyStateDeletedEvent() + { + string requestContent = "[ { \"source\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"eventType\":\"Microsoft.PolicyInsights.PolicyStateDeleted\", \"eventTime\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"timestamp\":\"2017-08-16T03:54:38.2696833Z\", \"policyDefinitionId\":\"4c2359fe-001e-00ba-0e04-585868000000\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"subscriptionId\":\"{subscription-id}\" }, \"dataVersion\": \"1.0\" }]"; + + EventGridEvent[] events = EventGridEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("4c2359fe-001e-00ba-0e04-585868000000", (eventData as PolicyInsightsPolicyStateDeletedEventData).PolicyDefinitionId); + } + #endregion #endregion #region CloudEvent tests @@ -2497,6 +2557,28 @@ public void ConsumeCloudEventStorageDirectoryRenamedEvent() Assert.True(events[0].TryGetSystemEventData(out object eventData)); Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageDirectoryRenamedEventData).DestinationUrl); } + + [Test] + public void ConsumeCloudEventStorageAsyncOperationInitiatedEvent() + { + string requestContent = "[{ \"source\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"type\": \"Microsoft.Storage.AsyncOperationInitiated\", \"time\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"api\": \"RenameDirectory\", \"requestId\": \"4c2359fe-001e-00ba-0e04-585868000000\", \"url\": \"https://example.blob.core.windows.net/testcontainer/testDir\", \"sequencer\": \"0000000000000281000000000002F5CA\", \"storageDiagnostics\": { \"batchId\": \"b68529f3-68cd-4744-baa4-3c0498ec19f0\" } }, \"specversion\": \"1.0\"}]"; + CloudEvent[] events = CloudEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageAsyncOperationInitiatedEventData).Url); + } + + [Test] + public void ConsumeCloudEventStorageBlobTierChangedEvent() + { + string requestContent = "[{ \"source\": \"/subscriptions/id/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/xstoretestaccount\", \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testDir\", \"type\": \"Microsoft.Storage.BlobTierChanged\", \"time\": \"2017-11-07T20:09:22.5674003Z\", \"id\": \"4c2359fe-001e-00ba-0e04-58586806d298\", \"data\": { \"api\": \"RenameDirectory\", \"requestId\": \"4c2359fe-001e-00ba-0e04-585868000000\", \"url\": \"https://example.blob.core.windows.net/testcontainer/testDir\", \"sequencer\": \"0000000000000281000000000002F5CA\", \"storageDiagnostics\": { \"batchId\": \"b68529f3-68cd-4744-baa4-3c0498ec19f0\" } }, \"specversion\": \"1.0\"}]"; + CloudEvent[] events = CloudEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("https://example.blob.core.windows.net/testcontainer/testDir", (eventData as StorageBlobTierChangedEventData).Url); + } #endregion #region App Service events @@ -2668,6 +2750,44 @@ public void ConsumeCloudEventWebAppServicePlanUpdatedEvent() Assert.AreEqual(planName, (eventData as WebAppServicePlanUpdatedEventData).Name); } #endregion + + #region Policy Insights + [Test] + public void ConsumeCloudEventPolicyInsightsPolicyStateChangedEvent() + { + string requestContent = "[ { \"source\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"type\":\"Microsoft.PolicyInsights.PolicyStateChanged\", \"time\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"timestamp\":\"2017-08-16T03:54:38.2696833Z\", \"policyDefinitionId\":\"4c2359fe-001e-00ba-0e04-585868000000\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"subscriptionId\":\"{subscription-id}\" }, \"specversion\": \"1.0\" }]"; + + CloudEvent[] events = CloudEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("4c2359fe-001e-00ba-0e04-585868000000", (eventData as PolicyInsightsPolicyStateChangedEventData).PolicyDefinitionId); + } + + [Test] + public void ConsumeCloudEventPolicyInsightsPolicyStateCreatedEvent() + { + string requestContent = "[ { \"source\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"type\":\"Microsoft.PolicyInsights.PolicyStateCreated\", \"time\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"timestamp\":\"2017-08-16T03:54:38.2696833Z\", \"policyDefinitionId\":\"4c2359fe-001e-00ba-0e04-585868000000\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"subscriptionId\":\"{subscription-id}\" }, \"specversion\": \"1.0\" }]"; + + CloudEvent[] events = CloudEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("4c2359fe-001e-00ba-0e04-585868000000", (eventData as PolicyInsightsPolicyStateCreatedEventData).PolicyDefinitionId); + } + + [Test] + public void ConsumeCloudEventPolicyInsightsPolicyStateDeletedEvent() + { + string requestContent = "[ { \"source\":\"/subscriptions/{subscription-id}\", \"subject\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"type\":\"Microsoft.PolicyInsights.PolicyStateDeleted\", \"time\":\"2017-08-16T03:54:38.2696833Z\", \"id\":\"25b3b0d0-d79b-44d5-9963-440d4e6a9bba\", \"data\": { \"timestamp\":\"2017-08-16T03:54:38.2696833Z\", \"policyDefinitionId\":\"4c2359fe-001e-00ba-0e04-585868000000\", \"httpRequest\":\"{request-operation}\", \"resourceProvider\":\"Microsoft.EventGrid\", \"resourceUri\":\"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/eventSubscriptions/LogicAppdd584bdf-8347-49c9-b9a9-d1f980783501\", \"subscriptionId\":\"{subscription-id}\" }, \"specversion\": \"1.0\" }]"; + + CloudEvent[] events = CloudEvent.ParseMany(new BinaryData(requestContent)); + + Assert.NotNull(events); + Assert.True(events[0].TryGetSystemEventData(out object eventData)); + Assert.AreEqual("4c2359fe-001e-00ba-0e04-585868000000", (eventData as PolicyInsightsPolicyStateDeletedEventData).PolicyDefinitionId); + } + #endregion #endregion } }