summaryrefslogtreecommitdiffstats
path: root/ms/command-executor
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-04-19 00:09:30 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-19 00:09:30 +0000
commit3a00a565dc29f402d24bb67c63fc7c62e337a27d (patch)
treef3724a11d6daec677e33ebd875a471b4dc100806 /ms/command-executor
parentfbab2613397dc8e3ac66d1b94cd5a2299c2dd861 (diff)
parentee120a54f32d3643eefbef03ca0f4ca9c423e58b (diff)
Merge "Add python CommandExecutor gRPC server w/ auth"
Diffstat (limited to 'ms/command-executor')
-rwxr-xr-xms/command-executor/pom.xml40
-rw-r--r--ms/command-executor/src/main/python/command_executor_server.py69
-rw-r--r--ms/command-executor/src/main/python/request_header_validator_interceptor.py38
3 files changed, 127 insertions, 20 deletions
diff --git a/ms/command-executor/pom.xml b/ms/command-executor/pom.xml
index 903ccdcaf..af1b4f43b 100755
--- a/ms/command-executor/pom.xml
+++ b/ms/command-executor/pom.xml
@@ -66,26 +66,26 @@
</execution>
</executions>
</plugin>
- <!--<plugin>-->
- <!--<artifactId>maven-assembly-plugin</artifactId>-->
- <!--<version>3.1.0</version>-->
- <!--<configuration>-->
- <!--<outputDirectory>${basedir}/target/docker-stage</outputDirectory>-->
- <!--<descriptors>-->
- <!--<descriptor>src/main/docker/distribution.xml</descriptor>-->
- <!--</descriptors>-->
- <!--<tarLongFileMode>posix</tarLongFileMode>-->
- <!--</configuration>-->
- <!--<executions>-->
- <!--<execution>-->
- <!--<id>${assembly.id}</id>-->
- <!--<phase>package</phase>-->
- <!--<goals>-->
- <!--<goal>single</goal>-->
- <!--</goals>-->
- <!--</execution>-->
- <!--</executions>-->
- <!--</plugin>-->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>3.1.0</version>
+ <configuration>
+ <outputDirectory>${basedir}/target/docker-stage</outputDirectory>
+ <descriptors>
+ <descriptor>src/main/docker/distribution.xml</descriptor>
+ </descriptors>
+ <tarLongFileMode>posix</tarLongFileMode>
+ </configuration>
+ <executions>
+ <execution>
+ <id>${assembly.id}</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
diff --git a/ms/command-executor/src/main/python/command_executor_server.py b/ms/command-executor/src/main/python/command_executor_server.py
new file mode 100644
index 000000000..35eed8e57
--- /dev/null
+++ b/ms/command-executor/src/main/python/command_executor_server.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+#
+# Copyright (C) 2019 Bell Canada.
+#
+# Licensed 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.
+#
+from builtins import KeyboardInterrupt
+from concurrent import futures
+import time
+import sys
+
+import grpc
+
+import proto.CommandExecutor_pb2_grpc as CommandExecutor_pb2_grpc
+
+from request_header_validator_interceptor import RequestHeaderValidatorInterceptor
+
+_ONE_DAY_IN_SECONDS = 60 * 60 * 24
+
+
+class CommandExecutorServer(CommandExecutor_pb2_grpc.CommandExecutorServiceServicer):
+
+ def prepareEnv(self, request, context):
+ return
+
+ def executeCommand(self, request, context):
+ return
+
+
+def serve():
+ port = sys.argv[1]
+ basic_auth = sys.argv[2] + ' ' + sys.argv[3]
+
+ header_validator = RequestHeaderValidatorInterceptor(
+ 'authorization', basic_auth, grpc.StatusCode.UNAUTHENTICATED,
+ 'Access denied!')
+
+ server = grpc.server(
+ futures.ThreadPoolExecutor(max_workers=10),
+ interceptors=(header_validator,))
+
+ CommandExecutor_pb2_grpc.add_CommandExecutorServiceServicer_to_server(
+ CommandExecutorServer(), server)
+
+ server.add_insecure_port('[::]:' + port)
+ server.start()
+
+ print("Command Executor Server started on %s" % port)
+
+ try:
+ while True:
+ time.sleep(_ONE_DAY_IN_SECONDS)
+ except KeyboardInterrupt:
+ server.stop(0)
+
+
+if __name__ == '__main__':
+ serve()
diff --git a/ms/command-executor/src/main/python/request_header_validator_interceptor.py b/ms/command-executor/src/main/python/request_header_validator_interceptor.py
new file mode 100644
index 000000000..261357337
--- /dev/null
+++ b/ms/command-executor/src/main/python/request_header_validator_interceptor.py
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2019 Bell Canada.
+#
+# Licensed 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.
+#
+
+import grpc
+
+
+def _unary_unary_rpc_terminator(code, details):
+ def terminate(ignored_request, context):
+ context.abort(code, details)
+
+ return grpc.unary_unary_rpc_method_handler(terminate)
+
+
+class RequestHeaderValidatorInterceptor(grpc.ServerInterceptor):
+
+ def __init__(self, header, value, code, details):
+ self._header = header
+ self._value = value
+ self._terminator = _unary_unary_rpc_terminator(code, details)
+
+ def intercept_service(self, continuation, handler_call_details):
+ if (self._header, self._value) in handler_call_details.invocation_metadata:
+ return continuation(handler_call_details)
+ else:
+ return self._terminator