Skip to content

Commit 70b7a47

Browse files
Tyler LeonhardtTyler Leonhardt
authored andcommitted
Merge branch 'dev' of github.com:Azure/azure-functions-powershell-worker into update-configs
2 parents 71c3317 + 274e079 commit 70b7a47

15 files changed

+257
-307
lines changed

src/Azure.Functions.PowerShell.Worker.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
2019
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.1.0-rc.1" />
2120
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
2221
<PackageReference Include="CommandLineParser" Version="2.3.0" />

src/Function/FunctionInfo.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/Function/FunctionLoader.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/FunctionLoader.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System;
7+
using Google.Protobuf.Collections;
8+
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
9+
10+
namespace Microsoft.Azure.Functions.PowerShellWorker
11+
{
12+
internal class FunctionLoader
13+
{
14+
private readonly MapField<string, FunctionInfo> _loadedFunctions = new MapField<string, FunctionInfo>();
15+
16+
internal FunctionInfo GetFunctionInfo(string functionId)
17+
{
18+
if (_loadedFunctions.TryGetValue(functionId, out FunctionInfo funcInfo))
19+
{
20+
return funcInfo;
21+
}
22+
23+
throw new InvalidOperationException($"Function with the ID '{functionId}' was not loaded.");
24+
}
25+
26+
internal void Load(FunctionLoadRequest request)
27+
{
28+
// TODO: catch "load" issues at "func start" time.
29+
// ex. Script doesn't exist, entry point doesn't exist
30+
_loadedFunctions.Add(request.FunctionId, new FunctionInfo(request.Metadata));
31+
}
32+
}
33+
34+
internal class FunctionInfo
35+
{
36+
internal readonly string Directory;
37+
internal readonly string EntryPoint;
38+
internal readonly string FunctionName;
39+
internal readonly string ScriptPath;
40+
internal readonly MapField<string, BindingInfo> AllBindings;
41+
internal readonly MapField<string, BindingInfo> OutputBindings;
42+
43+
public FunctionInfo(RpcFunctionMetadata metadata)
44+
{
45+
FunctionName = metadata.Name;
46+
Directory = metadata.Directory;
47+
EntryPoint = metadata.EntryPoint;
48+
ScriptPath = metadata.ScriptFile;
49+
50+
AllBindings = new MapField<string, BindingInfo>();
51+
OutputBindings = new MapField<string, BindingInfo>();
52+
53+
foreach (var binding in metadata.Bindings)
54+
{
55+
AllBindings.Add(binding.Key, binding.Value);
56+
57+
// PowerShell doesn't support the 'InOut' type binding
58+
if (binding.Value.Direction == BindingInfo.Types.Direction.Out)
59+
{
60+
OutputBindings.Add(binding.Key, binding.Value);
61+
}
62+
}
63+
}
64+
}
65+
}

src/Http/HttpRequestContext.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
//
55

66
using System;
7-
using Google.Protobuf.Collections;
7+
using System.Collections.Generic;
88

99
namespace Microsoft.Azure.Functions.PowerShellWorker
1010
{
1111
/// <summary>
1212
/// Custom type represent the context of the in-coming Http request.
1313
/// </summary>
14-
public class HttpRequestContext : IEquatable<HttpRequestContext>
14+
public class HttpRequestContext
1515
{
16+
/// <summary>
17+
/// Constructor for HttpRequestContext.
18+
/// </summary>
19+
public HttpRequestContext()
20+
{
21+
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
22+
Params = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
23+
Query = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
24+
}
25+
1626
/// <summary>
1727
/// Gets the Body of the Http request.
1828
/// </summary>
@@ -21,7 +31,7 @@ public class HttpRequestContext : IEquatable<HttpRequestContext>
2131
/// <summary>
2232
/// Gets the Headers of the Http request.
2333
/// </summary>
24-
public MapField<string, string> Headers { get; internal set; }
34+
public Dictionary<string, string> Headers { get; private set; }
2535

2636
/// <summary>
2737
/// Gets the Method of the Http request.
@@ -36,30 +46,16 @@ public class HttpRequestContext : IEquatable<HttpRequestContext>
3646
/// <summary>
3747
/// Gets the Params of the Http request.
3848
/// </summary>
39-
public MapField<string, string> Params { get; internal set; }
49+
public Dictionary<string, string> Params { get; private set; }
4050

4151
/// <summary>
4252
/// Gets the Query of the Http request.
4353
/// </summary>
44-
public MapField<string, string> Query { get; internal set; }
54+
public Dictionary<string, string> Query { get; private set; }
4555

4656
/// <summary>
4757
/// Gets the RawBody of the Http request.
4858
/// </summary>
4959
public object RawBody { get; internal set; }
50-
51-
/// <summary>
52-
/// Compare with another HttpRequestContext object.
53-
/// </summary>
54-
public bool Equals(HttpRequestContext other)
55-
{
56-
return Method == other.Method
57-
&& Url == other.Url
58-
&& Headers.Equals(other.Headers)
59-
&& Params.Equals(other.Params)
60-
&& Query.Equals(other.Query)
61-
&& (Body == other.Body || Body.Equals(other.Body))
62-
&& (RawBody == other.RawBody || RawBody.Equals(other.RawBody));
63-
}
6460
}
6561
}

src/Http/HttpResponseContext.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
//
55

66
using System;
7-
using System.Collections;
7+
using System.Collections.Generic;
88

99
namespace Microsoft.Azure.Functions.PowerShellWorker
1010
{
1111
/// <summary>
1212
/// Custom type represent the context of the Http response.
1313
/// </summary>
14-
public class HttpResponseContext : IEquatable<HttpResponseContext>
14+
public class HttpResponseContext
1515
{
1616
/// <summary>
1717
/// Gets or sets the Body of the Http response.
@@ -31,34 +31,11 @@ public class HttpResponseContext : IEquatable<HttpResponseContext>
3131
/// <summary>
3232
/// Gets or sets the Headers of the Http response.
3333
/// </summary>
34-
public Hashtable Headers { get; set; } = new Hashtable();
34+
public Dictionary<string, string> Headers { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
3535

3636
/// <summary>
3737
/// Gets or sets the StatusCode of the Http response.
3838
/// </summary>
3939
public string StatusCode { get; set; } = "200";
40-
41-
/// <summary>
42-
/// Compare with another HttpResponseContext object.
43-
/// </summary>
44-
public bool Equals(HttpResponseContext other)
45-
{
46-
bool sameHeaders = true;
47-
foreach (DictionaryEntry dictionaryEntry in Headers)
48-
{
49-
if (!other.Headers.ContainsKey(dictionaryEntry.Key)
50-
|| dictionaryEntry.Value != other.Headers[dictionaryEntry.Key])
51-
{
52-
sameHeaders = false;
53-
break;
54-
}
55-
}
56-
57-
return ContentType == other.ContentType
58-
&& EnableContentNegotiation == other.EnableContentNegotiation
59-
&& StatusCode == other.StatusCode
60-
&& sameHeaders
61-
&& (Body == other.Body || Body.Equals(other.Body));
62-
}
6340
}
6441
}

src/Messaging/MessagingStream.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Messaging
1414
{
1515
internal class MessagingStream : IDisposable
1616
{
17-
private SemaphoreSlim _writeStreamHandle = new SemaphoreSlim(1, 1);
17+
private SemaphoreSlim _writeSemaphore = new SemaphoreSlim(1, 1);
1818
private AsyncDuplexStreamingCall<StreamingMessage, StreamingMessage> _call;
1919
private bool isDisposed;
2020

@@ -45,14 +45,14 @@ public async Task WriteAsync(StreamingMessage message)
4545

4646
// Wait for the handle to be released because we can't have
4747
// more than one message being sent at the same time
48-
await _writeStreamHandle.WaitAsync();
48+
await _writeSemaphore.WaitAsync();
4949
try
5050
{
5151
await _call.RequestStream.WriteAsync(message);
5252
}
5353
finally
5454
{
55-
_writeStreamHandle.Release();
55+
_writeSemaphore.Release();
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)