Skip to content

Commit

Permalink
4.16.3 Hotfix (#9138)
Browse files Browse the repository at this point in the history
* Temporarily pushing System.Private.Uri dependency (#9133)

* Add InstanceName for Mesh Requests (#9009)

* test logs

* request body

* request body

* adding request body to all mesh client calls

* adding header instead of as body

* cleaning up

* deleting old request body class

* test to validate header

Co-authored-by: Tony Choi <[email protected]>

* Bumping minor version

---------

Co-authored-by: Fabio Cavalcante <[email protected]>
Co-authored-by: Tony Choi <[email protected]>
Co-authored-by: Tony Choi <[email protected]>
Co-authored-by: azfuncgh <[email protected]>
  • Loading branch information
5 people authored Mar 7, 2023
1 parent e8aed05 commit afd2544
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<MajorVersion>4</MajorVersion>
<MinorVersion>16</MinorVersion>
<PatchVersion>2</PatchVersion>
<PatchVersion>3</PatchVersion>
<BuildNumber Condition="'$(BuildNumber)' == '' ">0</BuildNumber>
<PreviewVersion></PreviewVersion>

Expand Down
14 changes: 12 additions & 2 deletions src/WebJobs.Script.WebHost/Management/MeshServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public async Task<bool> MountCifs(string connectionString, string contentShare,
{
var sa = CloudStorageAccount.Parse(connectionString);
var key = Convert.ToBase64String(sa.Credentials.ExportKey());

HttpResponseMessage responseMessage = await SendAsync(new[]
{
new KeyValuePair<string, string>(Operation, "cifs"),
Expand Down Expand Up @@ -142,9 +143,18 @@ private async Task<HttpResponseMessage> SendAsync(IEnumerable<KeyValuePair<strin
{
var operationName = formData.FirstOrDefault(f => string.Equals(f.Key, Operation)).Value;
_logger.LogDebug($"Sending mesh request {operationName}");
var res = await _client.PostAsync(_environment.GetEnvironmentVariable(EnvironmentSettingNames.MeshInitURI),
new FormUrlEncodedContent(formData));

var request = new HttpRequestMessage(HttpMethod.Post, _environment.GetEnvironmentVariable(EnvironmentSettingNames.MeshInitURI))
{
Content = new FormUrlEncodedContent(formData)
};

request.Headers.Add(ScriptConstants.ContainerInstanceHeader, _environment.GetEnvironmentVariable(EnvironmentSettingNames.ContainerName));

var res = await _client.SendAsync(request);

_logger.LogDebug($"Mesh response {res.StatusCode}");

return res;
}

Expand Down
1 change: 1 addition & 0 deletions src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.7.1" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/WebJobs.Script/ScriptConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static class ScriptConstants
public const string AntaresPlatformInternal = "x-ms-platform-internal";
public const string AzureVersionHeader = "x-ms-version";
public const string XIdentityHeader = "X-IDENTITY-HEADER";
public const string ContainerInstanceHeader = "fx-current-instance";
public const string DynamicSku = "Dynamic";
public const string ElasticPremiumSku = "ElasticPremium";
public const string DefaultProductionSlotName = "production";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Microsoft.Azure.WebJobs.Script.Tests.Integration.Management
public class MeshServiceClientTests
{
private const string MeshInitUri = "http://localhost:8954/";
private const string ContainerName = "MockContainerName";
private readonly IMeshServiceClient _meshServiceClient;
private readonly Mock<HttpMessageHandler> _handlerMock;
private readonly TestEnvironment _environment;
Expand All @@ -30,6 +31,7 @@ public MeshServiceClientTests()
_handlerMock = new Mock<HttpMessageHandler>(MockBehavior.Strict);
_environment = new TestEnvironment();
_environment.SetEnvironmentVariable(EnvironmentSettingNames.MeshInitURI, MeshInitUri);
_environment.SetEnvironmentVariable(EnvironmentSettingNames.ContainerName, ContainerName);
_meshServiceClient = new MeshServiceClient(TestHelpers.CreateHttpClientFactory(_handlerMock.Object), _environment,
NullLogger<MeshServiceClient>.Instance);
}
Expand All @@ -39,7 +41,8 @@ private static bool IsMountCifsRequest(HttpRequestMessage request, string target
var formData = request.Content.ReadAsFormDataAsync().Result;
return string.Equals(MeshInitUri, request.RequestUri.AbsoluteUri) &&
string.Equals("cifs", formData["operation"]) &&
string.Equals(targetPath, formData["targetPath"]);
string.Equals(targetPath, formData["targetPath"]) &&
string.Equals(ContainerName, request.Headers.GetValues(ScriptConstants.ContainerInstanceHeader).FirstOrDefault());
}

private static bool IsMountFuseRequest(HttpRequestMessage request, string filePath, string targetPath)
Expand All @@ -48,14 +51,16 @@ private static bool IsMountFuseRequest(HttpRequestMessage request, string filePa
return string.Equals(MeshInitUri, request.RequestUri.AbsoluteUri) &&
string.Equals("squashfs", formData["operation"]) &&
string.Equals(filePath, formData["filePath"]) &&
string.Equals(targetPath, formData["targetPath"]);
string.Equals(targetPath, formData["targetPath"]) &&
string.Equals(ContainerName, request.Headers.GetValues(ScriptConstants.ContainerInstanceHeader).FirstOrDefault());
}

private static bool IsPublishExecutionStatusRequest(HttpRequestMessage request, params ContainerFunctionExecutionActivity[] expectedActivities)
{
var formData = request.Content.ReadAsFormDataAsync().Result;
if (string.Equals(MeshInitUri, request.RequestUri.AbsoluteUri) &&
string.Equals(MeshServiceClient.AddFES, formData["operation"]))
string.Equals(MeshServiceClient.AddFES, formData["operation"]) &&
string.Equals(ContainerName, request.Headers.GetValues(ScriptConstants.ContainerInstanceHeader).FirstOrDefault()))
{
var activityContent = formData["content"];
var activities = JsonConvert.DeserializeObject<IEnumerable<ContainerFunctionExecutionActivity>>(activityContent);
Expand Down

0 comments on commit afd2544

Please sign in to comment.