-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nazarii
committed
Mar 21, 2024
1 parent
0b4ccbc
commit 7fcb62c
Showing
69 changed files
with
1,190 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ redis-*.tgz | |
db.sqlite3 | ||
.secrets.env | ||
*.spec | ||
.secrets.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
#!/bin/bash | ||
|
||
|
||
help() { | ||
echo "" | ||
echo "Usage: build.sh [--linter <string>] [--build <string>] [--test]" | ||
echo "-l, --linter <string> Linter to run (black, isort, flake8)" | ||
echo "-b, --build <string> Build type (frontend, backend)" | ||
echo "-h, --help <string> Print this help message" | ||
echo "-t, --test <string> Test type (backend)" | ||
echo | ||
} | ||
|
||
install_dependencies() { | ||
pip install -r requirements.txt | ||
} | ||
|
||
run_black() { | ||
echo "Running Black..." | ||
black --check --diff . | ||
} | ||
|
||
run_isort() { | ||
echo "Running isort..." | ||
isort --check --diff . | ||
} | ||
|
||
run_flake8() { | ||
echo "Running Flake8..." | ||
flake8 . | ||
} | ||
|
||
|
||
validate_image_args() { | ||
IMAGE_NAME=${IMAGE_NAME:-$CI_REGISTRY_IMAGE} # "registry.gitlab.com/mds7060534/naivebayes_app/backend" | ||
APP_VERSION=${APP_VERSION:-$CI_COMMIT_REF_SLUG} | ||
PROJECT_PATH=${build_path} | ||
|
||
if [ -z "${IMAGE_NAME}" ]; then | ||
echo "Docker image not specified. Please provide -i | --image-name" | ||
echo "Supported env vars: DOCKER_IMAGE | CI_REGISTRY_IMAGE" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${APP_VERSION}" ]; then | ||
echo "Docker image not specified. Please provide -v | --version" | ||
echo "Supported env vars: APP_VERSION | CI_COMMIT_REF_SLUG" | ||
exit 1 | ||
fi | ||
|
||
IMAGE=${IMAGE_NAME}/${PROJECT_PATH}:${APP_VERSION} | ||
|
||
echo "Image Name: ${IMAGE_NAME}" | ||
echo "App Version: ${APP_VERSION}" | ||
echo "Project Path: ${PROJECT_PATH}" | ||
echo "Image: ${IMAGE}" | ||
} | ||
|
||
run_build() { | ||
|
||
validate_image_args | ||
|
||
CI_PROJECT_DIR=$(pwd) | ||
DOCKERFILE_PATH="./Dockerfile" | ||
CONTEXT="${CI_PROJECT_DIR}/${PROJECT_PATH}" | ||
|
||
/kaniko/executor --context "${CONTEXT}" --dockerfile "${DOCKERFILE_PATH}" --destination "${IMAGE_NAME}" | ||
} | ||
|
||
run_test() { | ||
validate_image_args | ||
|
||
docker pull $IMAGE | ||
docker run --entrypoint="" --rm --name $PROJECT_PATH $IMAGE python -m coverage run -m unittest discover -s tests -p *_test.py | ||
} | ||
|
||
# Main function to execute linting tasks based on the specified linter | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "No arguments provided. Usage: ./build.sh --help" | ||
exit 1 | ||
fi | ||
|
||
|
||
main() { | ||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case "$key" in | ||
-l|--linter) | ||
linter="$2" | ||
shift; shift; | ||
;; | ||
-b|--build) | ||
build="$2" | ||
build_path="$2" | ||
shift; shift; | ||
;; | ||
-t|--test) | ||
test="$2" | ||
build_path="$2" | ||
shift; shift; | ||
;; | ||
-h|--help) | ||
help | ||
exit 0; | ||
;; | ||
-i|--image-name) | ||
IMAGE_NAME="$2" | ||
shift; shift; | ||
;; | ||
-v|--version) | ||
APP_VERSION="$2" | ||
shift; shift; | ||
;; | ||
*) | ||
echo "Invalid argument: $key" | ||
help | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
|
||
main "$@" | ||
|
||
|
||
if [ "$linter" ]; then | ||
case "$linter" in | ||
black) | ||
run_black "$@" | ||
;; | ||
isort) | ||
run_isort "$@" | ||
;; | ||
flake8) | ||
run_flake8 "$@" | ||
;; | ||
*) | ||
echo "Invalid linter: $linter" | ||
exit 1 | ||
;; | ||
esac | ||
fi | ||
|
||
if [ "$build" ]; then | ||
case "$build" in | ||
frontend) | ||
run_build "$@" | ||
;; | ||
backend) | ||
run_build "$@" | ||
;; | ||
*) | ||
echo "Invalid build: $build" | ||
exit 1 | ||
;; | ||
esac | ||
fi | ||
|
||
if [ "$test" ]; then | ||
case "$test" in | ||
backend) | ||
run_test "$@" | ||
;; | ||
*) | ||
echo "Invalid test: $test" | ||
exit 1 | ||
;; | ||
esac | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
EMAIL_HOST=gateway-host | ||
EMAIL_HOST=host.docker.internal | ||
EMAIL_PORT=1025 | ||
EMAIL_USE_TLS=0 | ||
EMAIL_USE_SSL=0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
* Install dependencies | ||
```shell | ||
pipenv install -r docs/requirements.txt --dev | ||
``` | ||
|
||
* doc8 style checks | ||
```shell | ||
doc8 docs/source/ --config web/pyproject.toml | ||
``` | ||
|
||
* Generate documentation | ||
```shell | ||
make -C docs html | ||
``` | ||
|
||
* Check spelling | ||
```shell | ||
make -C docs spelling | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import TYPE_CHECKING, Optional, TypedDict | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.utils.translation import get_language | ||
|
||
from main.tasks import send_information_email | ||
|
||
if TYPE_CHECKING: | ||
from main.models import UserType | ||
|
||
|
||
User: 'UserType' = get_user_model() | ||
|
||
|
||
class EmailSendData(TypedDict): | ||
subject: str | ||
template_name: str | ||
language: str | ||
to_email: str | ||
context: dict | ||
from_email: Optional[str] | ||
file_path_attachments: Optional[str] | ||
|
||
|
||
class BaseEmailService(ABC): | ||
def __init__(self, user: Optional[User] = None, language: Optional[str] = None, from_email: Optional[str] = None): | ||
self._user = user | ||
self._locale: str = language or get_language() | ||
self.from_email = from_email | ||
|
||
@property | ||
def locale(self) -> str: | ||
return self._locale | ||
|
||
@property | ||
def user(self) -> User: | ||
assert self._user, 'User object were not provided' | ||
return self._user | ||
|
||
@property | ||
@abstractmethod | ||
def template_name(self) -> str: | ||
"""Template email path""" | ||
|
||
@property | ||
def to_email(self) -> str: | ||
return self.user.email | ||
|
||
def email_context(self, **kwargs) -> dict: | ||
"""Provide dict with data for email template rendering""" | ||
return {} | ||
|
||
@property | ||
@abstractmethod | ||
def email_subject(self) -> str: | ||
"""Provide email subject""" | ||
|
||
def get_email_data(self, **kwargs) -> EmailSendData: | ||
return { | ||
'subject': self.email_subject, | ||
'template_name': self.template_name, | ||
'language': self.locale, | ||
'to_email': self.to_email, | ||
'context': self.email_context(**kwargs), | ||
'from_email': self.from_email, | ||
'file_path_attachments': None, | ||
} | ||
|
||
def send_email(self, **kwargs): | ||
kwargs: dict = self.get_email_data(**kwargs) | ||
return send_information_email.apply_async(kwargs=kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.conf import settings | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from api.email_service.base import BaseEmailService | ||
|
||
|
||
class PasswordResetService(BaseEmailService): | ||
template_name = 'emails/password_reset.html' | ||
|
||
@property | ||
def email_subject(self) -> str: | ||
return _('Blog password reset') | ||
|
||
def email_context(self, reset_url: str, **kwargs) -> dict: | ||
return { | ||
'full_name': self.user.full_name, | ||
'reset_url': reset_url, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from api.email_service.base import BaseEmailService | ||
|
||
|
||
class SignUpEmailService(BaseEmailService): | ||
template_name = 'emails/verify_email.html' | ||
|
||
@property | ||
def email_subject(self) -> str: | ||
return _('Blog register confirmation email') | ||
|
||
def email_context(self, activate_url: str, **kwargs) -> dict: | ||
return { | ||
'full_name': self.user.full_name, | ||
'activate_url': activate_url, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.