Skip to content

Commit

Permalink
New version of the AWS HA script.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommi-linnakangas committed Oct 14, 2024
0 parents commit de660df
Show file tree
Hide file tree
Showing 43 changed files with 5,755 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
run-at-boot
aws_ha_script_min.py
__pycache__
user_guide.pdf
.envrc
mypy_results.xml
.coverage
dist
unit_test_results.log
.idea
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7
69 changes: 69 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ruff configuration - https://beta.ruff.rs/docs/configuration/

# Python target version
target-version = "py310"

# Match black
line-length = 88

# Show number of potential fixes
show-fixes = true

# pycodestyle (`E`) and Pyflakes (`F`) are included by default
extend-select = [
"A", # flake8-builtins
"ANN", # flake8-annotations
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # mccabe complexity
"D", # pydocstyle
"N", # pep8-naming
"PTH", # flake8-use-pathlib
"RUF", # ruff-specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"TRY", # tryceratops - try/except
"UP", # pyupgrade
"W", # pycodestyle warnings
]

extend-ignore = [
"UP035", # python 3.7/typing.Dict` is deprecated, use `dict` instead"
"UP007", # python 3.7/[*] Use `X | Y` for type annotations
"UP006", # python 3.7/[*] Use `dict` instead of `Dict` for type annotations

"TRY003", # Avoid specifying long messages outside the exception class
"TRY300", # Consider moving this statement to an `else` block
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"D203", # one-blank-line-before-class - Clashes with D211/no-blank-line-before-class
"D213", # multi-line-summary-second-line - Clashes with D212/multi-line-summary-first-line
"E501", # line-too-long - Let black do the best it can
"ANN101", # Missing type annotation for `self` in method

"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package

"D403", # First word of the first line should be properly capitalized
"D400", # First line should end with a period
"D415", # First line should end with a period, question mark, or exclamation point
"D401" # First line of docstring should be in imperative mood: "Creates an empty config by default because the config file is optional."
]

[per-file-ignores]
# Rules to ignore in tests
"**/test/*.py" = [
"ANN001", # Missing type annotation for function argument
"ANN201", # Missing return type annotation for public function
"S101", # Use of `assert` detected
]
# Rules to ignore in component tests
"*.py" = [
"ANN001", # Missing type annotation for function argument
"ANN201", # Missing return type annotation for public function
"S101", # Use of `assert` detected
]
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changelog

All notable changes to this project will be documented in this file.

## [1.1.0] - 2024-01-17

- python 3.7
- now using pipenv to manage dependencies
- code cleanup, refactoring, modularization, ruff/flake8 linting
- added typing
- added ut with 'moto' library
- fix script incorrectly changing all the routes
- new mandatory property 'secondary_instance_id'
- code for vpnbroker removed
- deprecated properties (now ignored):
- vpn_broker_url
- vpn_broker_password
- primary_engine_name
- secondary_engine_name
- request_timeout_sec
- change_metrics_enabled
- new properties:
- probe_ip
- remote_probe_enabled
- remote_probe_ip
- remote_probe_port
89 changes: 89 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
include Makefile.env

PIPENV=PIPENV_VENV_IN_PROJECT=yes pipenv
BROWSER?=firefox # to view ut coverage result
PYTHON=python3
ZIPAPP=$(PYTHON) -mzipapp --compress
GEN_INSTALL_SCRIPT=./utils/generate-script-installer.py


ZIP_SCRIPT=$(BUILD_PATH)/aws_ha_script.pyz


# Standard targets

.PHONY: help
help: ## Print this help message
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

.PHONY: all
all: init lint unit-test build-doc build-dist ## lint, unit-test and build
@printf "\n\033[36m%-25s\033[0m %s\n" "- The script to deploy is available: $(SCRIPT_INSTALLER_TARGET)"
@printf "\033[36m%-25s\033[0m %s\n" "- The user doc is available: doc/user_guide.pdf"

.PHONY: unit-test
unit-test: $(VIRTUAL_ENV_PATH) ## Run unit tests
$(PIPENV) run pytest

.PHONY: unit-test-cov
unit-test-cov: unit-test ## Run unit tests and show coverage html report
$(BROWSER) htmlcov/index.html

# Python #
.PHONY: init
init: $(VIRTUAL_ENV_PATH) ## Initialise main Python virtual environment
$(VIRTUAL_ENV_PATH):
$(PIPENV) sync --dev

.PHONY: format
format: $(VIRTUAL_ENV_PATH) ## Format Python
$(PIPENV) run isort $(SRC_PATH)
$(PIPENV) run black $(SRC_PATH)

.PHONY: lint ## Lint Python
lint: lint-flake8
# temporary removing lint-ruff

.PHONY: lint-flake8
lint-flake8: $(VIRTUAL_ENV_PATH)
# echo "Entering directory '$(SRC_PATH)'"
cd $(SRC_PATH) && $(PIPENV) run flake8 --extend-ignore=E501,E305,F841
# echo "Leaving directory '$(SRC_PATH)'"

.PHONY: lint-ruff
lint-ruff: $(VIRTUAL_ENV_PATH)
$(PIPENV) run ruff check $(SRC_PATH)

.PHONY: typing
typing: $(VIRTUAL_ENV_PATH) ## Type check Python
echo "Entering directory '$(SRC_PATH)'"
cd $(SRC_PATH) && $(PIPENV) run mypy --show-error-codes .
echo "Leaving directory '$(SRC_PATH)'"

.PHONY: lock
lock: ## Create/Update the Pipfile lock file
$(PIPENV) lock --dev

.PHONY: sync
sync: ## Update environments
$(PIPENV) sync --dev


.PHONY: build-doc
build-doc: ## Build ha-script doc
$(MAKE) -C doc pdf

.PHONY: build-dist
build-dist: ## Build installation script
- rm -rf $(SRC_PATH)/*/*.pyc $(SRC_PATH)/*/__pycache__ $(SRC_PATH)/.*cache*
test -d $(BUILD_PATH) || mkdir $(BUILD_PATH)
$(ZIPAPP) -c $(SRC_PATH) -p "/usr/bin/env python3" -o $(ZIP_SCRIPT)
$(GEN_INSTALL_SCRIPT) $(ZIP_SCRIPT) >$(SCRIPT_INSTALLER_TARGET)

.PHONY: clean
clean:
- rm -rf $(BUILD_PATH) $(ZIPSCRIPT)
- rm -rf $(VIRTUAL_ENV_PATH)
- rm -rf $(SRC_PATH)/*/*.pyc $(SRC_PATH)/*/__pycache__
- rm -rf .pytest_cache __pycache__ htmlcov .coverage unit_test_results.log coverage.xml
- rm -rf $(SRC_PATH)/.mypy_cache .ruff_cache
9 changes: 9 additions & 0 deletions Makefile.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- makefile -*-

SRC_PATH=src
BUILD_PATH=dist
VIRTUAL_ENV_PATH=.venv

# this is what must be delivered to the customer
SCRIPT_INSTALLER_TARGET=$(BUILD_PATH)/aws_ha_script_installer.py

24 changes: 24 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[[source]]

url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"
boto3 = "*"

[dev-packages]
pytest = "*"
pytest-cov = "*"
mock = "*"
black = "*"
coverage = "*"
flake8 = "*"
isort = "*"
ruff = "*"
moto = {extras = ["all"], version = "*"}
boto3-stubs = {extras = ["ec2"], version = "*"}

[requires]
python_version = "3.7"
Loading

0 comments on commit de660df

Please sign in to comment.