Skip to content

Commit

Permalink
[@azure/eventgrid-namespaces][@Azure/eventgrid]Migrate EventGrid Pack…
Browse files Browse the repository at this point in the history
…ages away from Local Authentication (#30309)

### Packages impacted by this PR

1. @azure/eventgrid-namespaces 
2. @Azure/eventgrid

### Issues associated with this PR
#29699

### Describe the problem that is addressed by this PR
This PR has been created to move the eventgrid packages away from Local
Authentication. The migration guide has been used for reference.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?

No special design consideration.

### Are there test cases added in this PR? _(If not, why?)_
NA. Existing test cases are sufficient.

### Provide a list of related PRs _(if any)_
1. #29699
2. #30209

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [X] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
sarangan12 authored Jul 10, 2024
1 parent 1cd9184 commit f9e4e1f
Show file tree
Hide file tree
Showing 15 changed files with 1,540 additions and 1,478 deletions.
2,877 changes: 1,442 additions & 1,435 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions sdk/eventgrid/eventgrid-namespaces/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ module.exports = function (config) {
envPreprocessor: [
"TEST_MODE",
"RECORDINGS_RELATIVE_PATH",
"AZURE_TENANT_ID",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"EVENT_GRID_NAMESPACES_ENDPOINT",
"EVENT_GRID_NAMESPACES_KEY",
"EVENT_SUBSCRIPTION_NAME",
"TOPIC_NAME",
"MAX_DELIVERY_COUNT",
Expand Down
1 change: 1 addition & 0 deletions sdk/eventgrid/eventgrid-namespaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@azure/service-bus": "^7.0.0",
"@azure-tools/test-utils": "^1.0.1",
"@azure-tools/test-recorder": "^3.0.0",
"@azure-tools/test-credential": "^1.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe("Event Grid Namespace Client", function (this: Suite) {
({ senderClient, receiverClient, recorder } = await createRecordedClient(
this.currentTest,
"EVENT_GRID_NAMESPACES_ENDPOINT",
"EVENT_GRID_NAMESPACES_KEY",
topicName,
eventSubscriptionName,
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@azure-tools/test-recorder";

import { EventGridSenderClient, EventGridReceiverClient } from "../../../src";
import { AzureKeyCredential } from "@azure/core-auth";
import { createTestCredential } from "@azure-tools/test-credential";
import { AdditionalPolicyConfig } from "@azure/core-client";

export interface RecordedV2Client {
Expand All @@ -21,7 +21,6 @@ export interface RecordedV2Client {

const envSetupForPlayback: { [k: string]: string } = {
EVENT_GRID_NAMESPACES_ENDPOINT: "https://Sanitized",
EVENT_GRID_NAMESPACES_KEY: "api_key",
EVENT_SUBSCRIPTION_NAME: "testsubscription1",
TOPIC_NAME: "testtopic1",
MAX_DELIVERY_COUNT: "10",
Expand All @@ -37,7 +36,6 @@ export const recorderOptions: RecorderStartOptions = {
export async function createRecordedClient(
currentTest: Test | undefined,
endpointEnv: string,
apiKeyEnv: string,
topicName: string,
subscriptionName: string,
options: {
Expand All @@ -50,15 +48,15 @@ export async function createRecordedClient(
return {
senderClient: new EventGridSenderClient(
assertEnvironmentVariable(endpointEnv),
new AzureKeyCredential(assertEnvironmentVariable(apiKeyEnv)),
createTestCredential(),
topicName,
recorder.configureClientOptions({
additionalPolicies: options.additionalPolicies,
}),
),
receiverClient: new EventGridReceiverClient(
assertEnvironmentVariable(endpointEnv),
new AzureKeyCredential(assertEnvironmentVariable(apiKeyEnv)),
createTestCredential(),
topicName,
subscriptionName,
recorder.configureClientOptions({
Expand Down
1 change: 1 addition & 0 deletions sdk/eventgrid/eventgrid-namespaces/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ extends:
parameters:
PackageName: "@azure/eventgrid-namespaces"
ServiceDirectory: eventgrid
UseFederatedAuth: true
2 changes: 1 addition & 1 deletion sdk/eventgrid/eventgrid-system-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run extract-api",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf --glob dist dist-browser dist-esm dist-test temp types *.tgz *.log",
"execute:samples": "dev-tool samples run samples-dev",
"execute:samples": "echo skipped",
"extract-api": "tsc -p . && dev-tool run extract-api",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "dev-tool run test:browser",
Expand Down
5 changes: 3 additions & 2 deletions sdk/eventgrid/eventgrid-system-events/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
trigger: none

stages:
- template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
extends:
template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
parameters:
PackageName: "@azure/eventgrid-system-events"
ServiceDirectory: eventgrid
UseFederatedAuth: true
2 changes: 1 addition & 1 deletion sdk/eventgrid/eventgrid/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/eventgrid/eventgrid",
"Tag": "js/eventgrid/eventgrid_a3bc4076e9"
"Tag": "js/eventgrid/eventgrid_c5ca915df3"
}
3 changes: 0 additions & 3 deletions sdk/eventgrid/eventgrid/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ module.exports = function (config) {
envPreprocessor: [
"TEST_MODE",
"EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT",
"EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY",
"EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT",
"EVENT_GRID_CUSTOM_SCHEMA_API_KEY",
"EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT",
"EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY",
"RECORDINGS_RELATIVE_PATH",
],

Expand Down
1 change: 1 addition & 0 deletions sdk/eventgrid/eventgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"@azure/core-util": "^1.9.0",
"@azure-tools/test-utils": "^1.0.1",
"@azure-tools/test-recorder": "^3.0.0",
"@azure-tools/test-credential": "^1.0.0",
"@microsoft/api-extractor": "^7.31.1",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
Expand Down
7 changes: 0 additions & 7 deletions sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT",
"EventGrid",
"EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY",
));
});

Expand Down Expand Up @@ -102,7 +101,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT",
"EventGrid",
"EVENT_GRID_CUSTOM_SCHEMA_API_KEY",
{
removeApiEventsSuffixBool: true,
},
Expand Down Expand Up @@ -147,7 +145,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT",
"CloudEvent",
"EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY",
));
await recorder.setMatcher("HeaderlessMatcher");
});
Expand Down Expand Up @@ -230,7 +227,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT",
"CloudEvent",
"EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY",
{
additionalPolicies: [setHeadersPolicy],
},
Expand Down Expand Up @@ -284,7 +280,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT",
"CloudEvent",
"EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY",
{
removeApiEventsSuffixBool: true,
},
Expand Down Expand Up @@ -327,7 +322,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT",
"Custom",
"EVENT_GRID_CUSTOM_SCHEMA_API_KEY",
));
});

Expand Down Expand Up @@ -392,7 +386,6 @@ describe("EventGridPublisherClient", function (this: Suite) {
this.currentTest,
"EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT",
"Custom",
"EVENT_GRID_CUSTOM_SCHEMA_API_KEY",
{
removeApiEventsSuffixBool: true,
},
Expand Down
13 changes: 7 additions & 6 deletions sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@azure-tools/test-recorder";

import { EventGridPublisherClient, InputSchema } from "../../../src";
import { AzureKeyCredential } from "@azure/core-auth";
import { createTestCredential } from "@azure-tools/test-credential";
import { AdditionalPolicyConfig } from "@azure/core-client";
import { FindReplaceSanitizer } from "@azure-tools/test-recorder/types/src/utils/utils";

Expand All @@ -20,11 +20,8 @@ export interface RecordedClient<T extends InputSchema> {
}

const envSetupForPlayback: { [k: string]: string } = {
EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY: "api_key",
EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT: "https://endpoint/api/events",
EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY: "api_key",
EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT: "https://endpoint/api/events",
EVENT_GRID_CUSTOM_SCHEMA_API_KEY: "api_key",
EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT: "https://endpoint/api/events",
};

Expand All @@ -40,13 +37,17 @@ const suffixlessEndpointSanitizer = (endpointEnv: string): FindReplaceSanitizer

export const recorderOptions: RecorderStartOptions = {
envSetupForPlayback,
removeCentralSanitizers: [
"AZSDK3493", // .name in the body is not a secret and is listed below in the beforeEach section
"AZSDK3430", // .id in the body is not a secret and is listed below in the beforeEach section
"AZSDK4001",
],
};

export async function createRecordedClient<T extends InputSchema>(
currentTest: Test | undefined,
endpointEnv: string,
eventSchema: T,
apiKeyEnv: string,
options: {
removeApiEventsSuffixBool?: boolean;
additionalPolicies?: AdditionalPolicyConfig[];
Expand All @@ -68,7 +69,7 @@ export async function createRecordedClient<T extends InputSchema>(
? removeApiEventsSuffix(assertEnvironmentVariable(endpointEnv))
: assertEnvironmentVariable(endpointEnv),
eventSchema,
new AzureKeyCredential(assertEnvironmentVariable(apiKeyEnv)),
createTestCredential(),
recorder.configureClientOptions({
additionalPolicies: options.additionalPolicies,
}),
Expand Down
1 change: 1 addition & 0 deletions sdk/eventgrid/eventgrid/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ extends:
parameters:
PackageName: "@azure/eventgrid"
ServiceDirectory: eventgrid
UseFederatedAuth: true
92 changes: 79 additions & 13 deletions sdk/eventgrid/test-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@
"metadata": {
"description": "The location of the resource. By default, this is the same as the resource group."
}
},
"testApplicationOid": {
"type": "string",
"metadata": {
"description": "The client OID to grant access to test resources."
}
}
},
"variables": {
"eventGridTopicName": "[concat(parameters('baseName'), '-eg')]",
"cloudEventTopicName": "[concat(parameters('baseName'), '-ce')]",
"customEventTopicName": "[concat(parameters('baseName'), '-cus')]",
"serviceBusNamespaceName": "[concat(parameters('baseName'), '-ns')]",
"serviceBusQueueName": "[concat(parameters('baseName'), '-queue')]"
"egNamespaceName": "[concat(parameters('baseName'), '-egns')]",
"serviceBusQueueName": "[concat(parameters('baseName'), '-queue')]",
"dataSenderRoleDefinitionId": "d5a91429-5739-47e2-a06b-3470a27159e7",
"dataContributorRoleDefinitionId": "1d8c3fe3-8864-474b-8749-01e3783e8157"
},
"resources": [
{
Expand Down Expand Up @@ -92,40 +101,97 @@
"properties": {}
}
]
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[guid(resourceGroup().id, parameters('baseName'), variables('eventGridTopicName'), 'DataSender')]",
"properties": {
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', variables('dataSenderRoleDefinitionId'))]",
"principalId": "[parameters('testApplicationOid')]"
}
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[guid(resourceGroup().id, parameters('baseName'), variables('eventGridTopicName'), 'DataContributor')]",
"properties": {
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', variables('dataContributorRoleDefinitionId'))]",
"principalId": "[parameters('testApplicationOid')]"
}
},
{
"type": "Microsoft.EventGrid/namespaces",
"apiVersion": "2024-06-01-preview",
"name": "[variables('egNamespaceName')]",
"location": "eastus",
"sku": {
"name": "Standard",
"capacity": 1
},
"properties": {}
},
{
"type": "Microsoft.EventGrid/namespaces/topics",
"apiVersion": "2024-06-01-preview",
"name": "[concat(variables('egNamespaceName'), '/testtopic1')]",
"dependsOn": [
"[resourceId('Microsoft.EventGrid/namespaces', variables('egNamespaceName'))]"
],
"properties": {
"publisherType": "Custom",
"inputSchema": "CloudEventSchemaV1_0",
"eventRetentionInDays": 1
}
},
{
"type": "Microsoft.EventGrid/namespaces/topics/eventSubscriptions",
"apiVersion": "2024-06-01-preview",
"name": "[concat(variables('egNamespaceName'), '/testtopic1/testsubscription1')]",
"dependsOn": [
"[resourceId('Microsoft.EventGrid/namespaces/topics', variables('egNamespaceName'), 'testtopic1')]",
"[resourceId('Microsoft.EventGrid/namespaces', variables('egNamespaceName'))]"
],
"properties": {
"deliveryConfiguration": {
"deliveryMode": "Queue",
"queue": {
"receiveLockDurationInSeconds": 60,
"maxDeliveryCount": 10,
"eventTimeToLive": "P1D"
}
},
"eventDeliverySchema": "CloudEventSchemaV1_0",
"filtersConfiguration": {
"includedEventTypes": []
}
}
}
],
"outputs": {
"EVENT_GRID_EVENT_GRID_SCHEMA_ENDPOINT": {
"type": "string",
"value": "[reference(variables('eventGridTopicName')).endpoint]"
},
"EVENT_GRID_EVENT_GRID_SCHEMA_API_KEY": {
"type": "string",
"value": "[listKeys(variables('eventGridTopicName'), '2020-06-01').key1]"
},
"EVENT_GRID_CLOUD_EVENT_SCHEMA_ENDPOINT": {
"type": "string",
"value": "[reference(variables('cloudEventTopicName')).endpoint]"
},
"EVENT_GRID_CLOUD_EVENT_SCHEMA_API_KEY": {
"type": "string",
"value": "[listKeys(variables('cloudEventTopicName'), '2020-06-01').key1]"
},
"EVENT_GRID_CUSTOM_SCHEMA_ENDPOINT": {
"type": "string",
"value": "[reference(variables('customEventTopicName')).endpoint]"
},
"EVENT_GRID_CUSTOM_SCHEMA_API_KEY": {
"type": "string",
"value": "[listKeys(variables('customEventTopicName'), '2020-06-01').key1]"
},
"SERVICE_BUS_CONNECTION_STRING": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/AuthorizationRules',variables('serviceBusNamespaceName'),'RootManageSharedAccessKey'),'2017-04-01').primaryConnectionString]"
},
"SERVICE_BUS_QUEUE_NAME": {
"type": "string",
"value": "[variables('serviceBusQueueName')]"
},
"EVENT_GRID_NAMESPACES_ENDPOINT": {
"type": "string",
"value": "[concat('https://', reference(variables('egNamespaceName')).topicsConfiguration.hostname)]"
}
}
}

0 comments on commit f9e4e1f

Please sign in to comment.