Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions DirectConnector/AzureEventGridFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

using System.Net;
using Azure.Connectors.Sdk;
using Azure.Connectors.Sdk.AzureEventGrid;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace DirectConnector;

/// <summary>
/// Azure Functions demonstrating Azure Event Grid operations using the generated
/// <see cref="AzureEventGridClient"/> from the Azure Connectors SDK.
/// </summary>
public class AzureEventGridFunctions
{
private readonly ILogger<AzureEventGridFunctions> _logger;
private readonly AzureEventGridClient _eventGridClient;

public AzureEventGridFunctions(
ILogger<AzureEventGridFunctions> logger,
AzureEventGridClient eventGridClient)
{
this._logger = logger;
this._eventGridClient = eventGridClient;
}

/// <summary>
/// Lists available Event Grid topic types.
/// </summary>
[Function("EventGridListTopicTypes")]
public async Task<HttpResponseData> EventGridListTopicTypesAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "eventgrid/topictypes")] HttpRequestData request,
CancellationToken cancellationToken)
{
this._logger.LogInformation("EventGridListTopicTypes: Using generated AzureEventGridClient from SDK.");

try
{
var topicTypes = await this._eventGridClient
.TopicTypesListAsync(cancellationToken: cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

var response = request.CreateResponse(HttpStatusCode.OK);
await response
.WriteAsJsonAsync(new { success = true, topicTypes }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return response;
}
catch (ConnectorException ex)
{
this._logger.LogError(ex, "EventGridListTopicTypes failed with status '{StatusCode}'.", ex.Status);

var errorResponse = request.CreateResponse(HttpStatusCode.BadGateway);
await errorResponse
.WriteAsJsonAsync(new { success = false, error = ex.Message, statusCode = ex.Status, details = ex.ResponseBody }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return errorResponse;
}
catch (Exception ex) when (!ex.IsFatal())
{
this._logger.LogError(ex, "Error in EventGridListTopicTypes.");

var errorResponse = request.CreateResponse(HttpStatusCode.InternalServerError);
await errorResponse
.WriteAsJsonAsync(new { success = false, error = ex.Message })
.ConfigureAwait(continueOnCapturedContext: false);

return errorResponse;
}
}

/// <summary>
/// Lists Event Grid subscriptions.
/// </summary>
[Function("EventGridListSubscriptions")]
public async Task<HttpResponseData> EventGridListSubscriptionsAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "eventgrid/subscriptions")] HttpRequestData request,
CancellationToken cancellationToken)
{
this._logger.LogInformation("EventGridListSubscriptions: Using generated AzureEventGridClient from SDK.");

try
{
var subscriptions = await this._eventGridClient
.SubscriptionsListAsync(cancellationToken: cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

var response = request.CreateResponse(HttpStatusCode.OK);
await response
.WriteAsJsonAsync(new { success = true, subscriptions }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return response;
}
catch (ConnectorException ex)
{
this._logger.LogError(ex, "EventGridListSubscriptions failed with status '{StatusCode}'.", ex.Status);

var errorResponse = request.CreateResponse(HttpStatusCode.BadGateway);
await errorResponse
.WriteAsJsonAsync(new { success = false, error = ex.Message, statusCode = ex.Status, details = ex.ResponseBody }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return errorResponse;
}
catch (Exception ex) when (!ex.IsFatal())
{
this._logger.LogError(ex, "Error in EventGridListSubscriptions.");

var errorResponse = request.CreateResponse(HttpStatusCode.InternalServerError);
await errorResponse
.WriteAsJsonAsync(new { success = false, error = ex.Message })
.ConfigureAwait(continueOnCapturedContext: false);

return errorResponse;
}
}
}
14 changes: 7 additions & 7 deletions DirectConnector/AzureLogAnalyticsFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

using System.Net;
using Azure.Connectors.Sdk;
using Azure.Connectors.Sdk.Azuremonitorlogs;
using Azure.Connectors.Sdk.Azuremonitorlogs.Models;
using Azure.Connectors.Sdk.AzureMonitorLogs;
using Azure.Connectors.Sdk.AzureMonitorLogs.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
Expand All @@ -14,7 +14,7 @@ namespace DirectConnector;

/// <summary>
/// Azure Functions demonstrating Azure Monitor Logs operations using the generated
/// <see cref="AzuremonitorlogsClient"/> from the Azure Connectors SDK.
/// <see cref="AzureMonitorLogsClient"/> from the Azure Connectors SDK.
/// </summary>
/// <remarks>
/// This connector replaces the deprecated Azure Log Analytics connector.
Expand All @@ -25,11 +25,11 @@ public class AzureLogAnalyticsFunctions
private const string OperationalInsightsWorkspaceResourceType = "Microsoft.OperationalInsights/workspaces";

private readonly ILogger<AzureLogAnalyticsFunctions> _logger;
private readonly AzuremonitorlogsClient _logAnalyticsClient;
private readonly AzureMonitorLogsClient _logAnalyticsClient;

public AzureLogAnalyticsFunctions(
ILogger<AzureLogAnalyticsFunctions> logger,
AzuremonitorlogsClient logAnalyticsClient)
AzureMonitorLogsClient logAnalyticsClient)
{
this._logger = logger;
this._logAnalyticsClient = logAnalyticsClient;
Expand All @@ -44,7 +44,7 @@ public async Task<HttpResponseData> ListSubscriptionsAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "loganalytics/subscriptions")] HttpRequestData request,
CancellationToken cancellationToken)
{
this._logger.LogInformation("ListLogAnalyticsSubscriptions: Using generated AzuremonitorlogsClient from SDK.");
this._logger.LogInformation("ListLogAnalyticsSubscriptions: Using generated AzureMonitorLogsClient from SDK.");

try
{
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task<HttpResponseData> ListWorkspacesAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "loganalytics/workspaces")] HttpRequestData request,
CancellationToken cancellationToken)
{
this._logger.LogInformation("ListLogAnalyticsWorkspaces: Using generated AzuremonitorlogsClient from SDK.");
this._logger.LogInformation("ListLogAnalyticsWorkspaces: Using generated AzureMonitorLogsClient from SDK.");

var subscription = request.Query["subscription"];
var resourceGroup = request.Query["resourceGroup"];
Expand Down
2 changes: 1 addition & 1 deletion DirectConnector/DirectConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="10.0.7" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Connectors.Sdk" Version="0.9.0-preview.1" />
<PackageReference Include="Azure.Connectors.Sdk" Version="0.10.0-preview.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
89 changes: 89 additions & 0 deletions DirectConnector/ExcelOnlineFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

using System.Net;
using Azure.Connectors.Sdk;
using Azure.Connectors.Sdk.ExcelOnline;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace DirectConnector;

/// <summary>
/// Azure Functions demonstrating Excel Online operations using the generated
/// <see cref="ExcelOnlineClient"/> from the Azure Connectors SDK.
/// </summary>
public class ExcelOnlineFunctions
{
private readonly ILogger<ExcelOnlineFunctions> _logger;
private readonly ExcelOnlineClient _excelOnlineClient;

public ExcelOnlineFunctions(
ILogger<ExcelOnlineFunctions> logger,
ExcelOnlineClient excelOnlineClient)
{
this._logger = logger;
this._excelOnlineClient = excelOnlineClient;
}

/// <summary>
/// Gets tables from an Excel workbook in OneDrive for Business.
/// </summary>
[Function("ExcelGetTables")]
public async Task<HttpResponseData> ExcelGetTablesAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "excel/tables")] HttpRequestData request,
CancellationToken cancellationToken)
{
var documentLibrary = request.Query["documentLibrary"] ?? "Documents";
var file = request.Query["file"];

if (string.IsNullOrEmpty(file))
{
var badRequest = request.CreateResponse(HttpStatusCode.BadRequest);
await badRequest
.WriteAsJsonAsync(new { success = false, error = "Missing required query parameter 'file'. Example: ?file=TestWorkbook.xlsx&documentLibrary=Documents." }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
return badRequest;
}

this._logger.LogInformation("ExcelGetTables: Using generated ExcelOnlineClient from SDK.");

try
{
var tables = await this._excelOnlineClient
.GetTablesAsync(documentLibrary: documentLibrary, file: file, cancellationToken: cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);
Comment thread
daviburg marked this conversation as resolved.

var response = request.CreateResponse(HttpStatusCode.OK);
await response
.WriteAsJsonAsync(new { success = true, tables }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return response;
}
catch (ConnectorException ex)
{
this._logger.LogError(ex, "ExcelGetTables failed with status '{StatusCode}'.", ex.Status);

var errorResponse = request.CreateResponse(HttpStatusCode.BadGateway);
await errorResponse
.WriteAsJsonAsync(new { success = false, error = ex.Message, statusCode = ex.Status, details = ex.ResponseBody }, cancellationToken)
.ConfigureAwait(continueOnCapturedContext: false);

return errorResponse;
}
catch (Exception ex) when (!ex.IsFatal())
{
this._logger.LogError(ex, "Error in ExcelGetTables.");

var errorResponse = request.CreateResponse(HttpStatusCode.InternalServerError);
await errorResponse
.WriteAsJsonAsync(new { success = false, error = ex.Message })
.ConfigureAwait(continueOnCapturedContext: false);

return errorResponse;
}
}
}
12 changes: 6 additions & 6 deletions DirectConnector/Office365UsersFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

using System.Net;
using Azure.Connectors.Sdk;
using Azure.Connectors.Sdk.Office365users;
using Azure.Connectors.Sdk.Office365users.Models;
using Azure.Connectors.Sdk.Office365Users;
using Azure.Connectors.Sdk.Office365Users.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
Expand All @@ -14,16 +14,16 @@ namespace DirectConnector;

/// <summary>
/// Azure Functions demonstrating Office 365 Users operations using the generated
/// <see cref="Office365usersClient"/> from the Azure Connectors SDK.
/// <see cref="Office365UsersClient"/> from the Azure Connectors SDK.
/// </summary>
public class Office365UsersFunctions
{
private readonly ILogger<Office365UsersFunctions> _logger;
private readonly Office365usersClient _office365UsersClient;
private readonly Office365UsersClient _office365UsersClient;

public Office365UsersFunctions(
ILogger<Office365UsersFunctions> logger,
Office365usersClient office365UsersClient)
Office365UsersClient office365UsersClient)
{
this._logger = logger;
this._office365UsersClient = office365UsersClient;
Expand All @@ -34,7 +34,7 @@ public async Task<HttpResponseData> GetMyProfileAsync(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "users/me")] HttpRequestData request,
CancellationToken cancellationToken)
{
this._logger.LogInformation("GetMyProfile: Using generated Office365usersClient from SDK.");
this._logger.LogInformation("GetMyProfile: Using generated Office365UsersClient from SDK.");

try
{
Expand Down
9 changes: 7 additions & 2 deletions DirectConnector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
services.AddAzureBlobClient(configuration.GetSection("Connectors:AzureBlob"));
services.AddSmtpClient(configuration.GetSection("Connectors:Smtp"));
services.AddMqClient(configuration.GetSection("Connectors:Mq"));
services.AddOffice365usersClient(configuration.GetSection("Connectors:Office365Users"));
services.AddAzuremonitorlogsClient(configuration.GetSection("Connectors:AzureMonitorLogs"));
services.AddOffice365UsersClient(configuration.GetSection("Connectors:Office365Users"));
services.AddAzureMonitorLogsClient(configuration.GetSection("Connectors:AzureMonitorLogs"));
services.AddArmClient(configuration.GetSection("Connectors:Arm"));
services.AddExcelOnlineClient(configuration.GetSection("Connectors:ExcelOnline"));
services.AddAzureEventGridClient(configuration.GetSection("Connectors:AzureEventGrid"));
services.AddYammerClient(configuration.GetSection("Connectors:Yammer"));
services.AddWdatpClient(configuration.GetSection("Connectors:Wdatp"));
services.AddUniversalPrintClient(configuration.GetSection("Connectors:UniversalPrint"));
})
.Build();

Expand Down
6 changes: 6 additions & 0 deletions DirectConnector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ This sample demonstrates calling Azure managed connectors directly from an Azure
| `GET /api/onedrive/search?query=...` | OneDrive | File search with `FindFilesByPathAsync` |
| `POST /api/onedrive/share` | OneDrive | Create sharing link (`view` or `edit`) |
| `POST /api/onedriveTriggerCallback` | OneDrive | **Trigger callback** — handles both JSON metadata (OnNewFilesV2) and binary file-content (OnNewFileV2) payloads |
| `GET /api/excel/tables` | Excel Online | List tables in a workbook |
| `GET /api/eventgrid/topictypes` | Azure Event Grid | List available topic types |
| `GET /api/eventgrid/subscriptions` | Azure Event Grid | List event subscriptions |
| `GET /api/yammer/networks` | Yammer (Viva Engage) | List networks for the authenticated user |
| `GET /api/wdatp/alerts` | Microsoft Defender ATP | List alerts (paginated via `await foreach`) |
| `GET /api/universalprint/shares` | Universal Print | List recent printer shares |

### Key Patterns

Expand Down
Loading
Loading