style: ドキュメントコメント修正

This commit is contained in:
shimoda.m@nds-tyo.co.jp 2022-07-07 13:46:04 +09:00
parent 7f6f4659dc
commit 4f57e1ecf4
2 changed files with 63 additions and 7 deletions

View File

@ -22,3 +22,8 @@ class ParameterNotFoundException(MeDaCaException):
class DatabaseConnectionException(MeDaCaException):
"""データベース接続に失敗した場合の例外"""
pass
class QueryExecutionException(MeDaCaException):
"""クエリ実行に失敗した場合の例外"""
pass

View File

@ -16,7 +16,8 @@ from constants import (CHECK_TARGET_SCHEMAS,
from database import Database
from dto.view_secutiry_option import ViewSecurityOption
from exceptions import (DatabaseConnectionException, FileNotFoundException,
MeDaCaException, ParameterNotFoundException)
MeDaCaException, ParameterNotFoundException,
QueryExecutionException)
from medaca_logger import MeDaCaLogger
logger = MeDaCaLogger.get_logger()
@ -35,7 +36,7 @@ def handler(event, context):
connection = connection_database(db_host, db_user_name, db_user_password)
logger.info('I-03-01', 'データベースへの接続開始 終了')
logger.info('I-04-01', 'Viewセキュリティオプション チェック開始')
check_result = check_view_security_option(connection, check_target_schemas)
check_result = fetch_view_security_options(connection, check_target_schemas)
if len(check_result) == 0:
logger.info('I-04-02', 'Viewセキュリティオプション 未設定のViewはありません。処理を終了します。')
@ -61,7 +62,7 @@ def read_check_target_schemas() -> list:
"""設定ファイル[チェック対象スキーマ名ファイル]を読み込む
Raises:
exceptions.FileNotFoundException: ファイルが読み込めなかったエラー
FileNotFoundException: ファイルが読み込めなかったエラー
Exception: 想定外のエラー
Returns:
@ -82,7 +83,7 @@ def read_db_param_from_parameter_store() -> tuple:
"""パラメータストアからDB接続情報を取得する
Raises:
FileNotFoundException: _description_
ParameterNotFoundException: 指定されたパラメータが存在しないエラー
Exception: 想定外のエラー
Returns:
@ -102,6 +103,19 @@ def read_db_param_from_parameter_store() -> tuple:
def connection_database(host: str, user_name: str, password: str) -> Database:
"""データベース接続
Args:
host (str): DBホスト
user_name (str): DBユーザー名
password (str): DBパスワード
Raises:
DatabaseConnectionException: データベースへの接続に失敗したエラー
Returns:
Database: データベース操作クラス
"""
try:
database = Database(host, user_name, password)
database.connect()
@ -110,7 +124,20 @@ def connection_database(host: str, user_name: str, password: str) -> Database:
raise DatabaseConnectionException('E-03-02', f'データベースへの接続に失敗しました エラー内容:{e}')
def check_view_security_option(connection: Database, check_target_schemas: list) -> list:
def fetch_view_security_options(connection: Database, check_target_schemas: list) -> tuple:
"""SECURITY INVOKERのついていないViewの一覧を取得する
Args:
connection (Database): 接続済みDB操作クラス
check_target_schemas (str): チェック対象のスキーマ一覧
Raises:
QueryExecutionException: クエリ実行エラー
Returns:
tuple: クエリ実行結果
"""
select_view_security_option_sql = f"""
SELECT
TABLE_SCHEMA,
@ -123,13 +150,12 @@ def check_view_security_option(connection: Database, check_target_schemas: list)
)
AND SECURITY_TYPE <> '{INFORMATION_SCHEMA_SECURITY_TYPE_INVOKER}'
"""
print(select_view_security_option_sql)
try:
with connection.query(select_view_security_option_sql) as cursor:
result = cursor.fetchall()
return result
except Exception as e:
raise DatabaseConnectionException('E-03-02', f'Viewセキュリティオプションチェックに失敗しました エラー内容{e}')
raise QueryExecutionException('E-03-02', f'Viewセキュリティオプションチェックに失敗しました エラー内容{e}')
def make_notice_mail(view_security_options: list[ViewSecurityOption]):
@ -149,6 +175,19 @@ def make_notice_mail(view_security_options: list[ViewSecurityOption]):
def read_mail_title(config_bucket: ConfigBucket):
"""メールタイトルを読み込む
Args:
config_bucket (ConfigBucket): 設定ファイル保管バケット操作クラス
Raises:
FileNotFoundException: ファイルが読み込めなかったエラー
Exception: 想定外のエラー
Returns:
str: メールタイトル
"""
try:
mail_title = config_bucket.notice_mail_title_template
except botocore.exceptions.ClientError as e:
@ -161,6 +200,18 @@ def read_mail_title(config_bucket: ConfigBucket):
def read_mail_body_template(config_bucket: ConfigBucket):
"""メール本文を読み込む
Args:
config_bucket (ConfigBucket): 設定ファイル保管バケット操作クラス
Raises:
FileNotFoundException: ファイルが読み込めなかったエラー
Exception: 想定外のエラー
Returns:
str: メール本文
"""
try:
mail_body_template = config_bucket.notice_mail_body_template
except botocore.exceptions.ClientError as e: