forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate Managed Identity manual tests - Azure Functions (Azure#38393)
- Loading branch information
1 parent
a8b0f64
commit f657914
Showing
16 changed files
with
256 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...Azure.Identity/integration/Integration.Identity.Common/Integration.Identity.Common.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Azure.Identity.csproj" /> | ||
</ItemGroup> | ||
</Project> |
22 changes: 22 additions & 0 deletions
22
sdk/identity/Azure.Identity/integration/Integration.Identity.Common/ManagedIdentityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Azure.Identity; | ||
using Azure.Storage.Blobs; | ||
using Azure.Core; | ||
|
||
namespace Integration.Identity.Common; | ||
|
||
public static class ManagedIdentityTests | ||
{ | ||
public static void AuthToStorage() | ||
{ | ||
string resourceId = Environment.GetEnvironmentVariable("IDENTITY_WEBAPP_USER_DEFINED_IDENTITY")!; | ||
string account1 = Environment.GetEnvironmentVariable("IDENTITY_STORAGE_NAME_1")!; | ||
string account2 = Environment.GetEnvironmentVariable("IDENTITY_STORAGE_NAME_2")!; | ||
|
||
var credential1 = new ManagedIdentityCredential(); | ||
var credential2 = new ManagedIdentityCredential(new ResourceIdentifier(resourceId)); | ||
var client1 = new BlobServiceClient(new Uri($"https://{account1}.blob.core.windows.net/"), credential1); | ||
var client2 = new BlobServiceClient(new Uri($"https://{account2}.blob.core.windows.net/"), credential2); | ||
client1.GetBlobContainers().ToList(); | ||
client2.GetBlobContainers().ToList(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
sdk/identity/Azure.Identity/integration/Integration.Identity.Func/Function1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Integration.Identity.Common; | ||
|
||
namespace Integration.Identity.Func | ||
{ | ||
public static class Function1 | ||
{ | ||
[FunctionName("Function1")] | ||
public static async Task<IActionResult> Run( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, | ||
ILogger log) | ||
{ | ||
log.LogInformation("C# HTTP trigger function processed a request."); | ||
|
||
try | ||
{ | ||
ManagedIdentityTests.AuthToStorage(); | ||
return new OkObjectResult("Successfully acquired a token from ManagedIdentityCredential"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new BadRequestObjectResult(ex.ToString()); | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ity/Azure.Identity/integration/Integration.Identity.Func/Integration.Identity.Func.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Integration.Identity.Common\Integration.Identity.Common.csproj" /> | ||
</ItemGroup> | ||
</Project> |
7 changes: 7 additions & 0 deletions
7
.../Azure.Identity/integration/Integration.Identity.Func/Properties/serviceDependencies.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"appInsights1": { | ||
"type": "appInsights" | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
....Identity/integration/Integration.Identity.Func/Properties/serviceDependencies.local.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"appInsights1": { | ||
"type": "appInsights.sdk" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
sdk/identity/Azure.Identity/integration/Integration.Identity.Func/host.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"fileLoggingMode": "always", | ||
"logLevel": { | ||
"Function.MyFunction": "Information", | ||
"default": "None" | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
sdk/identity/Azure.Identity/integration/Integration.Identity.Func/local.settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.