Skip to content

Commit

Permalink
Assign LOGGER instead of importing (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtzcx committed Jul 18, 2020
1 parent 4ba6d54 commit 60fb572
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion repokid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import import_string

__version__ = "0.14.0"
__version__ = "0.14.1"


def init_config():
Expand Down
4 changes: 3 additions & 1 deletion repokid/cli/repokid_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"""

import json
import logging
import sys

from docopt import docopt
from repokid import __version__ as __version__
from repokid import CONFIG
from repokid import get_hooks
from repokid import LOGGER
from repokid.commands.repo import repo_all_roles, repo_role, repo_stats, rollback_role
from repokid.commands.role import (
display_role,
Expand All @@ -61,6 +61,8 @@

# http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html

LOGGER = logging.getLogger("repokid")


def _generate_default_config(filename=None):
"""
Expand Down
4 changes: 3 additions & 1 deletion repokid/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import csv
import datetime
import json
import logging
import pprint
import time

Expand All @@ -23,7 +24,6 @@
get_role_inline_policies,
put_role_policy,
)
from repokid import LOGGER
import repokid.hooks
from repokid.role import Role, Roles
from repokid.utils import roledata as roledata
Expand All @@ -44,6 +44,8 @@
from repokid.utils.roledata import partial_update_role_data
from tabulate import tabulate

LOGGER = logging.getLogger("repokid")


def repo_role(
account_number,
Expand Down
4 changes: 3 additions & 1 deletion repokid/commands/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.
import csv
import json
import logging

from policyuniverse.arn import ARN
from repokid import LOGGER
import repokid.hooks
from repokid.role import Role, Roles
from repokid.utils import roledata as roledata
Expand All @@ -33,6 +33,8 @@
import tabview as t
from tqdm import tqdm

LOGGER = logging.getLogger("repokid")


def display_roles(account_number, dynamo_table, inactive=False):
"""
Expand Down
5 changes: 4 additions & 1 deletion repokid/commands/role_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging

from cloudaux.aws.iam import get_account_authorization_details
from repokid import LOGGER
from repokid.filters import FilterPlugins
from repokid.role import Role, Roles
from repokid.utils import roledata as roledata
from repokid.utils.aardvark import get_aardvark_data
from repokid.utils.dynamo import set_role_data
from tqdm import tqdm

LOGGER = logging.getLogger("repokid")


def update_role_cache(account_number, dynamo_table, config, hooks):
"""
Expand Down
4 changes: 3 additions & 1 deletion repokid/commands/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from datetime import datetime as dt
import logging
import time

from repokid import LOGGER
import repokid.hooks
from repokid.role import Role, Roles
from repokid.utils.dynamo import (
Expand All @@ -26,6 +26,8 @@
from tabulate import tabulate
from tqdm import tqdm

LOGGER = logging.getLogger("repokid")


def schedule_repo(account_number, dynamo_table, config, hooks):
"""
Expand Down
5 changes: 4 additions & 1 deletion repokid/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging

import import_string
from repokid import LOGGER

LOGGER = logging.getLogger("repokid")


# inspiration from https://github.com/slackhq/python-rtmbot/blob/master/rtmbot/core.py
Expand Down
4 changes: 3 additions & 1 deletion repokid/filters/age/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime
import logging

from dateutil.tz import tzlocal
from repokid import LOGGER
from repokid.filters import Filter

LOGGER = logging.getLogger("repokid")


class AgeFilter(Filter):
def apply(self, input_list):
Expand Down
4 changes: 3 additions & 1 deletion repokid/filters/blocklist/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import json
import logging
import sys

import botocore
from cloudaux.aws.sts import boto3_cached_conn
from repokid import LOGGER
from repokid.filters import Filter

LOGGER = logging.getLogger("repokid")


def get_blocklist_from_bucket(bucket_config):
try:
Expand Down
4 changes: 3 additions & 1 deletion repokid/filters/exclusive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fnmatch
import logging

from repokid import LOGGER
from repokid.filters import Filter

LOGGER = logging.getLogger("repokid")


class ExclusiveFilter(Filter):
def __init__(self, config=None):
Expand Down
5 changes: 4 additions & 1 deletion repokid/hooks/loggers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from repokid import LOGGER
import logging

import repokid.hooks as hooks
from repokid.role import Role

LOGGER = logging.getLogger("repokid")


@hooks.implements_hook("BEFORE_REPO_ROLES", 1)
def log_before_repo_roles(input_dict):
Expand Down
4 changes: 3 additions & 1 deletion repokid/utils/aardvark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import sys

from repokid import LOGGER
import requests

LOGGER = logging.getLogger("repokid")


def get_aardvark_data(aardvark_api_location, account_number=None, arn=None):
"""
Expand Down
3 changes: 2 additions & 1 deletion repokid/utils/dynamo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import copy
import datetime
import logging
import sys

import boto3
from botocore.exceptions import ClientError as BotoClientError
from cloudaux.aws.sts import boto3_cached_conn as boto3_cached_conn
from repokid import LOGGER as LOGGER

LOGGER = logging.getLogger("repokid")
# used as a placeholder for empty SID to work around this: https://github.com/aws/aws-sdk-js/issues/833
DYNAMO_EMPTY_STRING = "---DYNAMO-EMPTY-STRING---"

Expand Down
3 changes: 2 additions & 1 deletion repokid/utils/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import datetime
import json
import logging
import re

import botocore
Expand All @@ -22,12 +23,12 @@
get_role_inline_policies,
put_role_policy,
)
from repokid import LOGGER
from repokid.utils import roledata as roledata
from repokid.utils.dynamo import set_role_data
from repokid.utils.logging import log_deleted_and_repoed_policies
from repokid.utils.roledata import partial_update_role_data

LOGGER = logging.getLogger("repokid")
MAX_AWS_POLICY_SIZE = 10240


Expand Down
2 changes: 1 addition & 1 deletion repokid/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from socket import gethostname
import traceback

from repokid import LOGGER
LOGGER = logging.getLogger("repokid")


class JSONFormatter(logging.Formatter):
Expand Down
3 changes: 2 additions & 1 deletion repokid/utils/roledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
from collections import defaultdict
import copy
import datetime
import logging
import time

from cloudaux.aws.iam import get_role_inline_policies
from dateutil.tz import tzlocal
from policyuniverse import all_permissions, expand_policy, get_actions_from_statement
from repokid import CONFIG as CONFIG
from repokid import LOGGER as LOGGER
import repokid.hooks
from repokid.role import Role
from repokid.utils.aardvark import get_aardvark_data
Expand All @@ -32,6 +32,7 @@
store_initial_role_data,
)

LOGGER = logging.getLogger("repokid")
BEGINNING_OF_2015_MILLI_EPOCH = 1420113600000
IAM_ACCESS_ADVISOR_UNSUPPORTED_SERVICES = frozenset([""])
IAM_ACCESS_ADVISOR_UNSUPPORTED_ACTIONS = frozenset(["iam:passrole"])
Expand Down

0 comments on commit 60fb572

Please sign in to comment.