You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by sh...@apache.org on 2021/01/03 17:07:52 UTC
[openwhisk-runtime-dotnet] branch master updated: Export init args
to environment. (#44)
This is an automated email from the ASF dual-hosted git repository.
shawnallen85 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-dotnet.git
The following commit(s) were added to refs/heads/master by this push:
new cf593c6 Export init args to environment. (#44)
cf593c6 is described below
commit cf593c65f558c52dd89fd2f77c910a06284637a9
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Sun Jan 3 12:07:46 2021 -0500
Export init args to environment. (#44)
---
.../proxy/Apache.OpenWhisk.Runtime.Common/Init.cs | 12 ++++++++
tests/dotnetshared/Init.cs | 35 ++++++++++++++++++++++
.../DotNet3_1ActionContainerTests.scala | 4 +++
.../DotNet3_1ActionContainerTests_2_2.scala | 4 +++
4 files changed, 55 insertions(+)
diff --git a/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs b/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
index ab04deb..fd8732f 100644
--- a/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
+++ b/core/dotnet3.1/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs
@@ -20,6 +20,7 @@ using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
+using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json.Linq;
@@ -120,6 +121,17 @@ namespace Apache.OpenWhisk.Runtime.Common
try
{
+ // Export init arguments as environment variables
+ if (message["env"] != null && message["env"].HasValues)
+ {
+ Dictionary<string, string> dictEnv = message["env"].ToObject<Dictionary<string, string>>();
+ foreach (KeyValuePair<string, string> entry in dictEnv) {
+ // See https://docs.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable
+ // If entry.Value is null or the empty string, the variable is not set
+ Environment.SetEnvironmentVariable(entry.Key, entry.Value);
+ }
+ }
+
Assembly assembly = Assembly.LoadFrom(assemblyPath);
Type = assembly.GetType(mainParts[1]);
if (Type == null)
diff --git a/tests/dotnetshared/Init.cs b/tests/dotnetshared/Init.cs
new file mode 100644
index 0000000..1c92aeb
--- /dev/null
+++ b/tests/dotnetshared/Init.cs
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using Newtonsoft.Json.Linq;
+
+namespace Apache.OpenWhisk.Tests.Dotnet
+{
+ public class Init
+ {
+ public static string SOME_VAR = System.Environment.GetEnvironmentVariable("SOME_VAR");
+ public static string ANOTHER_VAR = System.Environment.GetEnvironmentVariable("ANOTHER_VAR");
+
+ public JObject Main(JObject args)
+ {
+ JObject message = new JObject();
+ // an empty env variable is null, convert it to empty string to conform to test invariant
+ message.Add("SOME_VAR", new JValue(SOME_VAR != null ? SOME_VAR : ""));
+ message.Add("ANOTHER_VAR", new JValue(ANOTHER_VAR != null ? ANOTHER_VAR : ""));
+ return (message);
+ }
+ }
+}
diff --git a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala
index a34d20b..8436252 100644
--- a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests.scala
@@ -47,6 +47,10 @@ class DotNet3_1ActionContainerTests extends BasicActionRunnerTests with WskActor
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Environment::Main")
}
+ override val testEnvParameters = {
+ TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Init::Main")
+ }
+
override val testEcho = {
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.AltEcho::Main")
}
diff --git a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala
index 236051e..c3002e7 100644
--- a/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala
+++ b/tests/src/test/scala/actionContainers/DotNet3_1ActionContainerTests_2_2.scala
@@ -47,6 +47,10 @@ class DotNet3_1ActionContainerTests_2_2 extends BasicActionRunnerTests with WskA
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Environment::Main")
}
+ override val testEnvParameters = {
+ TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.Init::Main")
+ }
+
override val testEcho = {
TestConfig(functionb64, main = "Apache.OpenWhisk.Tests.Dotnet::Apache.OpenWhisk.Tests.Dotnet.AltEcho::Main")
}