diff --git a/proto/.gitignore b/proto/.gitignore index 79d17a55d24e501e34b462c9005e8e5429fc43ba..d1dea37b3a85abaa18b5bd65d3ec0e1d3c6fe9b6 100644 --- a/proto/.gitignore +++ b/proto/.gitignore @@ -1,2 +1,7 @@ -src/ +src/*/* + +# used to prevent breaking symbolic links from source code folders +!src/*/.gitignore +!src/python/__init__.py + uml/generated diff --git a/proto/context-policy.proto b/proto/context-policy.proto index 84a5c0edbf08087f3caf00601ffa7826b59f54af..9fe25dec5205b66f6d622df2f9435c1321f7e45e 100644 --- a/proto/context-policy.proto +++ b/proto/context-policy.proto @@ -20,9 +20,9 @@ import "policy.proto"; // created as a separate service to prevent import-loops in context and policy service ContextPolicyService { - rpc ListPolicyRuleIds (context.Empty ) returns ( policy.PolicyRuleIdList) {} - rpc ListPolicyRules (context.Empty ) returns ( policy.PolicyRuleList ) {} - rpc GetPolicyRule (policy.PolicyRuleId) returns ( policy.PolicyRule ) {} - rpc SetPolicyRule (policy.PolicyRule ) returns ( policy.PolicyRuleId ) {} - rpc RemovePolicyRule (policy.PolicyRuleId) returns ( context.Empty ) {} + rpc ListPolicyRuleIds(context.Empty ) returns (policy.PolicyRuleIdList) {} + rpc ListPolicyRules (context.Empty ) returns (policy.PolicyRuleList ) {} + rpc GetPolicyRule (policy.PolicyRuleId ) returns (policy.PolicyRuleBasic ) {} + rpc SetPolicyRule (policy.PolicyRuleBasic) returns (policy.PolicyRuleId ) {} + rpc RemovePolicyRule (policy.PolicyRuleId ) returns (context.Empty ) {} } diff --git a/proto/generate_code_python.sh b/proto/generate_code_python.sh new file mode 100755 index 0000000000000000000000000000000000000000..b0df357eb079fb2721cffca43465588f7013e341 --- /dev/null +++ b/proto/generate_code_python.sh @@ -0,0 +1,42 @@ +#!/bin/bash -eu +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# 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. + +# Make folder containing the script the root folder for its execution +cd $(dirname $0) + +mkdir -p src/python +rm -rf src/python/*.py + +tee src/python/__init__.py << EOF > /dev/null +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# 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. +EOF + +# Generate Python code +python3 -m grpc_tools.protoc -I=./ --python_out=src/python/ --grpc_python_out=src/python/ *.proto + +# Arrange generated code imports to enable imports from arbitrary subpackages +find src/python -type f -iname *.py -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \; diff --git a/proto/compile.sh b/proto/generate_uml.sh similarity index 89% rename from proto/compile.sh rename to proto/generate_uml.sh index 520ead69a95cdfd1a076aee221d672f81810b5f0..6f20b6f4cf695274fe5d6ed27e57671196c44b70 100755 --- a/proto/compile.sh +++ b/proto/generate_uml.sh @@ -13,12 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -python3 -m grpc_tools.protoc -I=./ --python_out=../src/ --grpc_python_out=../src/ *.proto #requires installation of protoc-gen-uml export PATH=${HOME}/protoc-gen-uml/target/universal/stage/bin:$PATH protoc --uml_out=uml/ -I ./ *.proto cd uml java -jar plantuml.7997.jar *.puml rm *.puml - - diff --git a/proto/policy.proto b/proto/policy.proto index dc3f700b4f295b50fdbfa5c1a315563e4969d25b..9e686f180994be988543ebd9a26dfd31dffed007 100644 --- a/proto/policy.proto +++ b/proto/policy.proto @@ -98,7 +98,7 @@ message PolicyRuleDeviceList { repeated PolicyRuleDevice policyRuleDeviceList = 1; } -// A list of policy rule Ids -message PolicyRuleIdList { - repeated PolicyRuleId policyRuleIds = 1; +// A list of policy rules +message PolicyRuleList { + repeated PolicyRuleId policyRules = 1; } diff --git a/proto/src/java/.gitignore b/proto/src/java/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3f93458aca854d3e06f27ca0caa672f3906f1720 --- /dev/null +++ b/proto/src/java/.gitignore @@ -0,0 +1,5 @@ +* + +# used to prevent breaking symbolic links from source code folders +!.gitignore +!__init__.py diff --git a/proto/src/python/.gitignore b/proto/src/python/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3f93458aca854d3e06f27ca0caa672f3906f1720 --- /dev/null +++ b/proto/src/python/.gitignore @@ -0,0 +1,5 @@ +* + +# used to prevent breaking symbolic links from source code folders +!.gitignore +!__init__.py diff --git a/proto/src/python/__init__.py b/proto/src/python/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..9953c820575d42fa88351cc8de022d880ba96e6a --- /dev/null +++ b/proto/src/python/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# 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. diff --git a/src/common/proto b/src/common/proto new file mode 120000 index 0000000000000000000000000000000000000000..0ae252a7824cad03d85fa60224b87d8c779f1588 --- /dev/null +++ b/src/common/proto @@ -0,0 +1 @@ +../../proto/src/python \ No newline at end of file