Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drop point controller #671

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '28 18 * * 4'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
34 changes: 22 additions & 12 deletions .github/workflows/python-dev-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
Expand All @@ -32,16 +31,27 @@ jobs:
run: |
python setup.py sdist bdist_wheel
twine upload --repository-url http://${{ secrets.DEV_PYPI_ADDRESS }}:8080 dist/*
- name: install on server
uses: appleboy/ssh-action@v0.1.2
- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
uses: GuillaumeFalourd/clone-github-repo-action@v2
with:
host: ${{ secrets.DEV_SERVER_ADDRESS }}
key: ${{ secrets.DEV_SERVER_SSH_KEY }}
username: ${{ secrets.DEV_SERVER_USERNAME }}
owner: 'FreeTAKTeam'
repository: 'FreeTAKHub-Installation'

script: |
sudo systemctl stop fts
sudo rm -r /usr/local/lib/python3.8/dist-packages/FreeTAKServer
sudo python3 -m pip uninstall FreeTAKServer -y
sudo python3 -m pip install --index-url http://${{ secrets.DEV_PYPI_USERNAME }}:${{ secrets.DEV_PYPI_PASSWORD }}@${{ secrets.DEV_PYPI_ADDRESS }}:8080 FreeTAKServer --trusted-host ${{ secrets.DEV_PYPI_ADDRESS }}:8080 --pre
sudo systemctl start fts
- name: Run Ansible playbook
# You may pin to the exact commit or the version.
# uses: dawidd6/action-ansible-playbook@671974ed60e946e11964cb0c26e69caaa4b1f559
uses: dawidd6/[email protected]
with:
# Ansible playbook filepath
playbook: FreeTAKHub-Installation/install_all.yml
# SSH private key used to connect to the host
key: ${{secrets.DEV_SERVER_SSH_KEY}}
# Custom content to write into hosts
inventory: |
[all]
${{secrets.DEV_SERVER_ADDRESS}} ansible_sudo_pass=${{secrets.DEV_SERVER_PASSWORD}} ansible_connection=ssh ansible_user=${{secrets.DEV_SERVER_USERNAME}}
# Extra options that should be passed to ansible-playbook command
options: |
--verbose
# Set to "true" if root is required for running your playbook
sudo: true
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
4 changes: 4 additions & 0 deletions FreeTAKServer/components/extended/drop_point/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""This module contains all the supporting components without business logic
it should also be noted that the component action mapper must be exposed as action mapper.
"""
from .drop_point_action_mapper import DropPointActionMapper as ActionMapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from digitalpy.routing.impl.default_action_mapper import DefaultActionMapper


class DropPointActionMapper(DefaultActionMapper):
"""This is the DropPoint component action mapper.

Each component must have its own action mapper to be loaded with the internal
action mapping configuration and to be used by the facade for internal routing.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from FreeTAKServer.components.core.abstract_component.domain import Domain
from ..configuration.drop_point_constants import CONFIGURATION_PATH_TEMPLATE
from .. import domain


class DropPointDomain(Domain):
"""This class is to be used for all interactions with the DropPoint domain model.
This class exposes and handles all domain model functions.
"""

def __init__(self, request, response, configuration, action_mapper):
super().__init__(
# the template of the path to the model configurations
CONFIGURATION_PATH_TEMPLATE,
# the module containing all the domain objects
domain,
# the request object (passed by constructor)
request=request,
# the response object (passed by constructor)
response=response,
# the configuration object (passed by constructor)
configuration=configuration,
# the action mapper (passed by constructor)
action_mapper=action_mapper,
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"actions": [
"ParseDropPoint"
],
"matchable": "model_object",
"rules": {
"type == 'Unknown'": {
"actions": [
"BroadcastDropPoint"
]
},
"type == 'Neutral'": {
"actions": [
"BroadcastDropPoint"
]
},
"type == 'Friendly'": {
"actions": [
"BroadcastDropPoint"
]
},
"type == 'Hostile'": {
"actions": [
"BroadcastDropPoint"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import json
import pathlib
from string import Template

COMPONENT_NAME = "DropPoint"

CONFIGURATION_FORMAT = "json"

CURRENT_COMPONENT_PATH = pathlib.Path(__file__).parent.parent.absolute()

CONFIGURATION_PATH_TEMPLATE = Template(
str(
pathlib.PurePath(
CURRENT_COMPONENT_PATH, "configuration/model_definitions/$message_type"
)
)
+ f".{CONFIGURATION_FORMAT}"
)

LOGGING_CONFIGURATION_PATH = str(
pathlib.PurePath(CURRENT_COMPONENT_PATH, "configuration/logging.conf")
)

ACTION_MAPPING_PATH = str(
pathlib.PurePath(
CURRENT_COMPONENT_PATH, "configuration/external_action_mapping.ini"
)
)

INTERNAL_ACTION_MAPPING_PATH = str(
pathlib.PurePath(
CURRENT_COMPONENT_PATH, "configuration/internal_action_mapping.ini"
)
)

TYPE_MAPPINGS = json.load(
open(
str(
pathlib.PurePath(CURRENT_COMPONENT_PATH, "configuration/type_mapping.json")
),
"r",
encoding="utf-8",
)
)


# TODO delete this?
BUSINESS_RULES_PATH = str(
pathlib.PurePath(CURRENT_COMPONENT_PATH, "configuration/business_rules.json")
)

DROP_POINT_BUSINESS_RULES_PATH = str(
pathlib.PurePath(
CURRENT_COMPONENT_PATH,
"configuration/business_rules/drop_point_business_rules.json",
)
)

BASE_OBJECT_NAME = "Event"

DROP_POINT = "drop_point"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[actionmapping]
??Unkown = FreeTAKServer.components.extended.drop_point.drop_point_facade.DropPoint.Received
??Neutral = FreeTAKServer.components.extended.drop_point.drop_point_facade.DropPoint.Received
??Friendly = FreeTAKServer.components.extended.drop_point.drop_point_facade.DropPoint.Received
??Hostile = FreeTAKServer.components.extended.drop_point.drop_point_facade.DropPoint.Received

??BroadcastDropPoint = FreeTAKServer.components.extended.controllers.drop_point.drop_point_controller.DropPointController.broadcast_drop_point

?Unkown?GetNodeParent = FreeTAKServer.components.extended.drop_point.base.drop_point_domain.DropPointDomain.get_parent
?Neutral?GetNodeParent = FreeTAKServer.components.extended.drop_point.base.drop_point_domain.DropPointDomain.get_parent
?Friendly?GetNodeParent = FreeTAKServer.components.extended.drop_point.base.drop_point_domain.DropPointDomain.get_parent
?Hostile?GetNodeParent = FreeTAKServer.components.extended.drop_point.base.drop_point_domain.DropPointDomain.get_parent

?ParseDropPoint?CreateNode = FreeTAKServer.components.extended.drop_point.base.drop_point_domain.DropPointDomain.create_node

[DropPoint]
__class = FreeTAKServer.components.extended.drop_point.drop_point_facade.DropPoint

[Request]
__class = digitalpy.routing.impl.default_request.DefaultRequest

[ActionMapper]
__class = digitalpy.routing.impl.default_action_mapper.DefaultActionMapper

[event_manager]
__class = digitalpy.core.impl.default_event_manager.DefaultEventManager

[Response]
__class = digitalpy.routing.impl.default_response.DefaultResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[actionmapping]
DropPoint??Unkown = FreeTAKServer.components.extended.drop_point.controllers.drop_point_controller.DropPointController.evaluate_request
DropPoint??Neutral = FreeTAKServer.components.extended.drop_point.controllers.drop_point_controller.DropPointController.evaluate_request
DropPoint??Friendly = FreeTAKServer.components.extended.drop_point.controllers.drop_point_controller.DropPointController.evaluate_request
DropPoint??Hostile = FreeTAKServer.components.extended.drop_point.controllers.drop_point_controller.DropPointController.evaluate_request

??BroadcastDropPoint = FreeTAKServer.components.extended.drop_point.controllers.drop_point_sender_controller.DropPointSenderController.broadcast_drop_point

??ParseDropPoint = FreeTAKServer.components.extended.drop_point.controllers.drop_point_controller.DropPointController.parse_drop_point

??SerializeDropPoint = FreeTAKServer.components.extended.drop_point.controllers.drop_point_general_controller.DropPointGeneralController.serialize_drop_point

[Request]
__class = digitalpy.routing.impl.default_request.DefaultRequest

[ActionMapper]
__class = digitalpy.routing.impl.default_action_mapper.DefaultActionMapper

[event_manager]
__class = digitalpy.core.impl.default_event_manager.DefaultEventManager

[Response]
__class = digitalpy.routing.impl.default_response.DefaultResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[loggers]
keys=root,drop_point

[handlers]
keys=stream_handler,fileHandler

[formatters]
keys=formatter

[logger_root]
level=DEBUG
handlers=fileHandler

[logger_drop_point]
level=DEBUG
qualname=drop_point
handlers=fileHandler

[handler_stream_handler]
class=StreamHandler
level=DEBUG
formatter=formatter
args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=formatter
args=('%(logfilename)s',)

[formatter_formatter]
format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"a-u-G": "Unknown",
"a-n-G": "Neutral",
"a-f-G": "Friendly",
"a-h-G": "Hostile"
}
Empty file.
Loading