Commit a9614511 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Proto files:

- fixed issue with messages in policy.proto and context-policy.proto
- modified and unified script to generate Python code from proto files
- segregated script to generate UML code
- added/modified apropriate .gitignore files to prevent uploading generated code. It should be generated locally or during creation of Docker containers
- added symbolic link from common/proto to folder containing python generated code
parent c7ce67d9
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
src/
src/*/*

# used to prevent breaking symbolic links from source code folders
!src/*/.gitignore
!src/python/__init__.py

uml/generated
+5 −5
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import "policy.proto";
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 GetPolicyRule    (policy.PolicyRuleId   ) returns (policy.PolicyRuleBasic ) {}
  rpc SetPolicyRule    (policy.PolicyRuleBasic) returns (policy.PolicyRuleId    ) {}
  rpc RemovePolicyRule (policy.PolicyRuleId   ) returns (context.Empty          ) {}
}
+42 −0
Original line number Diff line number Diff line
#!/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' {} \;
+0 −3
Original line number Diff line number Diff line
@@ -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

+3 −3
Original line number Diff line number Diff line
@@ -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;
}
Loading