File tree Expand file tree Collapse file tree 6 files changed +102
-2
lines changed Expand file tree Collapse file tree 6 files changed +102
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ internal class RequestProcessor
39
39
40
40
internal RequestProcessor ( MessagingStream msgStream )
41
41
{
42
+ var invalidVersionMessage = FunctionsWorkerRuntimeVersionValidator . GetErrorMessage ( ) ;
43
+ if ( invalidVersionMessage != null )
44
+ {
45
+ _initTerminatingError = new InvalidOperationException ( invalidVersionMessage ) ;
46
+ }
47
+
42
48
_msgStream = msgStream ;
43
49
_powershellPool = new PowerShellManagerPool ( msgStream ) ;
44
50
Original file line number Diff line number Diff line change
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
+ namespace Microsoft . Azure . Functions . PowerShellWorker . Utility
7
+ {
8
+ using System ;
9
+ using System . Text . RegularExpressions ;
10
+
11
+ internal static class FunctionsWorkerRuntimeVersionValidator
12
+ {
13
+ private const string VersionVariableName = "FUNCTIONS_WORKER_RUNTIME_VERSION" ;
14
+
15
+ public static string GetErrorMessage ( )
16
+ {
17
+ var requestedVersion = Environment . GetEnvironmentVariable ( VersionVariableName ) ;
18
+ return GetErrorMessage ( requestedVersion ) ;
19
+ }
20
+
21
+ internal static string GetErrorMessage ( string requestedVersion )
22
+ {
23
+ if ( ! string . IsNullOrWhiteSpace ( requestedVersion )
24
+ // Assuming this code is running on Functions runtime v2, allow
25
+ // PowerShell version 6 only (ignoring leading and trailing spaces, and the optional ~ in front of 6)
26
+ && ! Regex . IsMatch ( requestedVersion , @"^\s*~?6\s*$" ) )
27
+ {
28
+ return string . Format (
29
+ PowerShellWorkerStrings . InvalidFunctionsWorkerRuntimeVersion ,
30
+ VersionVariableName ,
31
+ requestedVersion ) ;
32
+ }
33
+
34
+ return null ;
35
+ }
36
+ }
37
+ }
Original file line number Diff line number Diff line change 4
4
//
5
5
6
6
using System ;
7
+ using System . Text . RegularExpressions ;
7
8
using System . Threading . Tasks ;
8
9
9
10
using CommandLine ;
10
- using Microsoft . Azure . Functions . PowerShellWorker . PowerShell ;
11
11
using Microsoft . Azure . Functions . PowerShellWorker . Messaging ;
12
12
using Microsoft . Azure . Functions . PowerShellWorker . Utility ;
13
13
using Microsoft . Azure . WebJobs . Script . Grpc . Messages ;
@@ -30,6 +30,8 @@ public async static Task Main(string[] args)
30
30
LogLevel . Information ,
31
31
string . Format ( PowerShellWorkerStrings . PowerShellWorkerVersion , typeof ( Worker ) . Assembly . GetName ( ) . Version ) ) ;
32
32
33
+ ValidateFunctionsWorkerRuntimeVersion ( ) ;
34
+
33
35
WorkerArguments arguments = null ;
34
36
Parser . Default . ParseArguments < WorkerArguments > ( args )
35
37
. WithParsed ( ops => arguments = ops )
@@ -47,6 +49,15 @@ public async static Task Main(string[] args)
47
49
msgStream . Write ( startedMessage ) ;
48
50
await requestProcessor . ProcessRequestLoop ( ) ;
49
51
}
52
+
53
+ private static void ValidateFunctionsWorkerRuntimeVersion ( )
54
+ {
55
+ var message = FunctionsWorkerRuntimeVersionValidator . GetErrorMessage ( ) ;
56
+ if ( message != null )
57
+ {
58
+ RpcLogger . WriteSystemLog ( LogLevel . Critical , message ) ;
59
+ }
60
+ }
50
61
}
51
62
52
63
internal class WorkerArguments
Original file line number Diff line number Diff line change 310
310
<data name =" CommandNotFoundException_Exception" xml : space =" preserve" >
311
311
<value >CommandNotFoundException detected (exception).</value >
312
312
</data >
313
+ <data name =" InvalidFunctionsWorkerRuntimeVersion" xml : space =" preserve" >
314
+ <value >Invalid PowerShell version specified in the {0} environment variable: {1}. This version is not supported on Azure Functions Runtime v2.</value >
315
+ </data >
313
316
</root >
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Test.DependencyManagement
9
9
using Xunit ;
10
10
11
11
using PowerShellWorker . DependencyManagement ;
12
- using Utility ;
12
+ using PowerShellWorker . Utility ;
13
13
14
14
public class NewerDependencySnapshotDetectorTests
15
15
{
Original file line number Diff line number Diff line change
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
+ namespace Microsoft . Azure . Functions . PowerShellWorker . Test . Utility
7
+ {
8
+ using Xunit ;
9
+
10
+ using Microsoft . Azure . Functions . PowerShellWorker . Utility ;
11
+
12
+ public class FunctionsWorkerRuntimeVersionValidatorTests
13
+ {
14
+ [ Theory ]
15
+ [ InlineData ( null ) ]
16
+ [ InlineData ( "" ) ]
17
+ [ InlineData ( " " ) ]
18
+ [ InlineData ( "6" ) ]
19
+ [ InlineData ( "~6" ) ]
20
+ [ InlineData ( " 6 " ) ]
21
+ [ InlineData ( " ~6 " ) ]
22
+ public void NoErrorOnValidVersion ( string versionToCheck )
23
+ {
24
+ Assert . Null ( FunctionsWorkerRuntimeVersionValidator . GetErrorMessage ( versionToCheck ) ) ;
25
+ }
26
+
27
+ [ Theory ]
28
+ [ InlineData ( "7" ) ]
29
+ [ InlineData ( "~7" ) ]
30
+ [ InlineData ( " 7 " ) ]
31
+ [ InlineData ( " ~7 " ) ]
32
+ [ InlineData ( "5" ) ]
33
+ [ InlineData ( "8" ) ]
34
+ [ InlineData ( "~" ) ]
35
+ [ InlineData ( "anything else" ) ]
36
+ public void ErrorOnInvalidVersion ( string versionToCheck )
37
+ {
38
+ var error = FunctionsWorkerRuntimeVersionValidator . GetErrorMessage ( versionToCheck ) ;
39
+ Assert . NotNull ( error ) ;
40
+ Assert . Contains ( versionToCheck , error ) ;
41
+ }
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments