Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

add logging abstraction #434

Closed
wants to merge 13 commits into from
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.6.2

* Added logging module abstraction. You can now define the logging module to be used by setting the
`LOGGING_MODULE` environment variable.

## 6.6.1

* Upgrade confidant to python 3.10.14
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.1
6.6.2
4 changes: 3 additions & 1 deletion confidant/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
import importlib

import boto3
import guard
Expand All @@ -17,6 +17,8 @@
jwks,
)

logging = importlib.import_module(settings.LOGGING_MODULE)

if not settings.get('DEBUG'):
boto3.set_stream_logger(level=logging.CRITICAL)
logging.getLogger('botocore').setLevel(logging.CRITICAL)
Expand Down
5 changes: 3 additions & 2 deletions confidant/authnz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
import importlib

import kmsauth
from flask import abort, request, g, make_response
from flask import url_for
from functools import wraps

from confidant import settings
from confidant.utils import stats
from confidant.utils.stats import stats

from confidant.authnz.errors import (
UserUnknownError,
Expand All @@ -17,6 +17,7 @@

_VALIDATOR = None

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
user_mod = userauth.init_user_auth_class()

Expand Down
3 changes: 2 additions & 1 deletion confidant/authnz/userauth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
import logging
import datetime
import importlib
import random

import yaml
Expand All @@ -24,6 +24,7 @@
from confidant.utils.misc import dict_deep_update
from confidant.authnz import errors

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)


Expand Down
5 changes: 4 additions & 1 deletion confidant/clients/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Module for accessing services external to Confidant."""

import boto3
import logging
import importlib

from confidant import settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)

CLIENT_CACHE = {}
Expand Down
4 changes: 3 additions & 1 deletion confidant/encrypted_settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import yaml
import base64
import logging
import importlib
import json

from cryptography.fernet import Fernet

import confidant.clients
from confidant.settings import LOGGING_MODULE
from confidant.lib import cryptolib

logging = importlib.import_module(LOGGING_MODULE)
logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion confidant/routes/blind_credentials.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
import importlib
import uuid

from flask import blueprints, jsonify, request
Expand All @@ -18,6 +18,7 @@
)
from confidant.models.blind_credential import BlindCredential

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('blind_credentials', __name__)

Expand Down
3 changes: 2 additions & 1 deletion confidant/routes/certificates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
import importlib

from flask import blueprints, jsonify, request

Expand All @@ -15,6 +15,7 @@
)
from confidant.utils import misc

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('certificates', __name__)

Expand Down
6 changes: 4 additions & 2 deletions confidant/routes/credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import importlib
import json
import logging
import re
import uuid

Expand All @@ -25,9 +25,11 @@
webhook,
)
from confidant.services.ciphermanager import CipherManager
from confidant.utils import maintenance, misc, stats
from confidant.utils import maintenance, misc
from confidant.utils.stats import stats
from confidant.utils.dynamodb import decode_last_evaluated_key

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('credentials', __name__)

Expand Down
5 changes: 3 additions & 2 deletions confidant/routes/jwks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging
import importlib

from flask import blueprints, jsonify, request

from confidant import authnz
from confidant import authnz, settings
from confidant.services.jwkmanager import JWKManager
from confidant.schema.jwks import jwt_response_schema, JWTResponse, \
jwks_list_response_schema, JWKSListResponse
from confidant.settings import ACL_MODULE
from confidant.utils import misc

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('jwks', __name__)

Expand Down
3 changes: 2 additions & 1 deletion confidant/routes/saml.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import importlib

import flask
from flask import blueprints, jsonify, request, session

from confidant import authnz, settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('saml', __name__)

Expand Down
6 changes: 4 additions & 2 deletions confidant/routes/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
import importlib

from flask import blueprints, jsonify, request
from pynamodb.exceptions import DoesNotExist, PutError
Expand All @@ -20,9 +20,11 @@
servicemanager,
webhook,
)
from confidant.utils import maintenance, misc, stats
from confidant.utils import maintenance, misc
from confidant.utils.stats import stats
from confidant.utils.dynamodb import decode_last_evaluated_key

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('services', __name__)

Expand Down
3 changes: 2 additions & 1 deletion confidant/routes/static_files.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import logging
import importlib

from flask import blueprints, current_app, send_from_directory
from werkzeug.exceptions import NotFound

from confidant import authnz, settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
blueprint = blueprints.Blueprint('static_files', __name__)

Expand Down
8 changes: 5 additions & 3 deletions confidant/scripts/archive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import logging
import importlib
from datetime import datetime

from flask_script import Command, Option
Expand All @@ -8,10 +8,12 @@
from confidant.models.credential import Credential
from confidant.services import credentialmanager

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)

logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)
if settings.LOGGING_MODULE == 'logging':
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)


class ArchiveCredentials(Command):
Expand Down
9 changes: 6 additions & 3 deletions confidant/scripts/migrate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
import logging
import importlib
from flask_script import Command

from confidant import settings
from confidant.models.blind_credential import BlindCredential
from confidant.models.service import Service

Expand All @@ -11,9 +12,11 @@
from pynamodb.constants import STRING_SET
from pynamodb.models import Model

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)
if settings.LOGGING_MODULE == 'logging':
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)


def is_old_unicode_set(values):
Expand Down
8 changes: 5 additions & 3 deletions confidant/scripts/migrate_bool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
import importlib
import time
import sys

Expand All @@ -14,9 +14,11 @@

from confidant import settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)
if settings.LOGGING_MODULE == 'logging':
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)


class GenericCredential(Model):
Expand Down
10 changes: 6 additions & 4 deletions confidant/scripts/restore.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import sys
import logging
import importlib

from flask_script import Command, Option
from pynamodb.exceptions import DoesNotExist

from confidant import settings
from confidant.models.credential import Credential, CredentialArchive
from confidant.utils import stats
from confidant.utils.stats import stats

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)

logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)
if settings.LOGGING_MODULE == 'logging':
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)


class RestoreCredentials(Command):
Expand Down
8 changes: 5 additions & 3 deletions confidant/scripts/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import logging
import importlib
from flask_script import Command
from botocore.exceptions import ClientError

Expand All @@ -9,10 +9,12 @@
from confidant.models.service import Service
from confidant.utils.dynamodb import create_dynamodb_tables

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)

logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)
if settings.LOGGING_MODULE == 'logging':
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)


class ManageGrants(Command):
Expand Down
5 changes: 3 additions & 2 deletions confidant/services/certificatemanager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import hashlib
import logging
import importlib
import time

from cryptography import x509
Expand All @@ -13,8 +13,9 @@

import confidant.clients
from confidant import settings
from confidant.utils import stats
from confidant.utils.stats import stats

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion confidant/services/ciphermanager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import base64
import re
import logging
import importlib

from cryptography.fernet import Fernet

from confidant import settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)


Expand Down
5 changes: 3 additions & 2 deletions confidant/services/credentialmanager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import copy
import re
import logging
import importlib

from confidant import settings
from confidant.models.blind_credential import BlindCredential
from confidant.models.credential import Credential, CredentialArchive
from confidant.models.service import Service
from confidant.utils import stats
from confidant.utils.stats import stats
from pynamodb.exceptions import DoesNotExist


logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion confidant/services/graphite.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import requests
import json
import logging
import importlib

from confidant import settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion confidant/services/iamrolemanager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import gevent
import logging
import importlib
import random

import confidant.clients
from confidant import settings

logging = importlib.import_module(settings.LOGGING_MODULE)
logger = logging.getLogger(__name__)
ROLES = []

Expand Down
Loading
Loading