diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index f3cc03936..2ec05ad53 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -3,6 +3,6 @@ description: Detects high entropy strings that are likely to be passwords. entry: detect-secrets-hook args: ['--base64-limit', '4.5', '--hex-limit', '3'] - language: python + language: python3 # for backward compatibility files: .* diff --git a/.travis.yml b/.travis.yml index b3550fe0d..a4765b494 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,10 @@ matrix: python: 3.6 - env: TOXENV=py37 python: 3.7 - dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069) + dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069) - env: TOXENV=py38 python: 3.8 - dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069) - - env: TOXENV=pypy - python: pypy + dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069) install: - pip install tox script: make test diff --git a/CHANGELOG.md b/CHANGELOG.md index f40f0de9a..e7db639c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,9 @@ If you love `detect-secrets`, please star our project on GitHub to show your sup [@xxxx]: https://github.com/xxxx --> + # v0.13.1 @@ -651,6 +653,7 @@ This includes using `# pragma: allowlist secret` now for inline allowlisting. # Special thanks to our awesome contributors! :clap: +- [@0atman] - [@adrianbn] - [@baboateng] - [@cclauss] @@ -674,6 +677,7 @@ This includes using `# pragma: allowlist secret` now for inline allowlisting. - [@whathejoe] - [@zioalex] +[@0atman]: https://github.com/0atman [@adrianbn]: https://github.com/adrianbn [@baboateng]: https://github.com/baboateng [@cclauss]: https://github.com/cclauss diff --git a/detect_secrets/core/audit.py b/detect_secrets/core/audit.py index de96ca34b..ec47d11b8 100644 --- a/detect_secrets/core/audit.py +++ b/detect_secrets/core/audit.py @@ -1,6 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals - import codecs import io import json @@ -10,11 +7,7 @@ from builtins import input from collections import defaultdict from copy import deepcopy - -try: - from functools import lru_cache -except ImportError: # pragma: no cover - from functools32 import lru_cache +from functools import lru_cache from ..plugins.common import initialize from ..plugins.common.util import get_mapping_from_secret_type_to_class_name diff --git a/detect_secrets/core/baseline.py b/detect_secrets/core/baseline.py index 7ff755b30..4a6cf77bb 100644 --- a/detect_secrets/core/baseline.py +++ b/detect_secrets/core/baseline.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import json import os import re diff --git a/detect_secrets/core/code_snippet.py b/detect_secrets/core/code_snippet.py index 8ff70f8a8..5b5a997da 100644 --- a/detect_secrets/core/code_snippet.py +++ b/detect_secrets/core/code_snippet.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import itertools from .color import AnsiColor diff --git a/detect_secrets/core/color.py b/detect_secrets/core/color.py index 7016250ba..038392fed 100644 --- a/detect_secrets/core/color.py +++ b/detect_secrets/core/color.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from enum import Enum diff --git a/detect_secrets/core/log.py b/detect_secrets/core/log.py index c0898778d..ef37db905 100644 --- a/detect_secrets/core/log.py +++ b/detect_secrets/core/log.py @@ -7,7 +7,7 @@ def get_logger(name=None, format_string=None): :type name: str :param name: used for declaring log channels. - :type format_string: str + :type format_string: str|None :param format_string: for custom formatting """ logging.captureWarnings(True) @@ -18,14 +18,15 @@ def get_logger(name=None, format_string=None): log.set_debug_level = _set_debug_level.__get__(log) log.set_debug_level(0) - if not format_string: - format_string = '[%(module)s]\t%(levelname)s\t%(message)s' - # Setting up log formats log.handlers = [] handler = logging.StreamHandler(sys.stderr) handler.setFormatter( - logging.Formatter(format_string), + logging.Formatter( + format_string + or + '[%(module)s]\t%(levelname)s\t%(message)s', + ), ) log.addHandler(handler) diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index a3ee549ef..9af886cad 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import codecs import json import os @@ -210,28 +208,21 @@ def scan_diff( ), ) - def scan_file(self, filename, filename_key=None): + def scan_file(self, filename): """Scans a specified file, and adds information to self.data :type filename: str :param filename: full path to file to scan. - :type filename_key: str - :param filename_key: key to store in self.data - :returns: boolean; though this value is only used for testing """ - - if not filename_key: - filename_key = filename - if os.path.islink(filename): return False if os.path.splitext(filename)[1] in IGNORED_FILE_EXTENSIONS: return False try: with codecs.open(filename, encoding='utf-8') as f: - self._extract_secrets_from_file(f, filename_key) + self._extract_secrets_from_file(f, filename) return True except IOError: diff --git a/detect_secrets/core/usage.py b/detect_secrets/core/usage.py index e2cc3f3c8..d827a75ce 100644 --- a/detect_secrets/core/usage.py +++ b/detect_secrets/core/usage.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import argparse from collections import namedtuple @@ -281,12 +279,9 @@ class PluginDescriptor( ), ): def __new__(cls, related_args=None, **kwargs): - if not related_args: - related_args = [] - return super(PluginDescriptor, cls).__new__( cls, - related_args=related_args, + related_args=related_args or [], **kwargs ) diff --git a/detect_secrets/main.py b/detect_secrets/main.py index c939bfd28..8a033e453 100644 --- a/detect_secrets/main.py +++ b/detect_secrets/main.py @@ -1,8 +1,3 @@ -#!/usr/bin/python -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals - import json import sys diff --git a/detect_secrets/plugins/artifactory.py b/detect_secrets/plugins/artifactory.py index 0085b9b7d..0d0ee6a8d 100644 --- a/detect_secrets/plugins/artifactory.py +++ b/detect_secrets/plugins/artifactory.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/aws.py b/detect_secrets/plugins/aws.py index 8d96894c0..1fa406ef0 100644 --- a/detect_secrets/plugins/aws.py +++ b/detect_secrets/plugins/aws.py @@ -1,8 +1,6 @@ """ This plugin searches for AWS key IDs """ -from __future__ import absolute_import - import hashlib import hmac import re diff --git a/detect_secrets/plugins/basic_auth.py b/detect_secrets/plugins/basic_auth.py index 87e10e21a..5baeb7dd4 100644 --- a/detect_secrets/plugins/basic_auth.py +++ b/detect_secrets/plugins/basic_auth.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/cloudant.py b/detect_secrets/plugins/cloudant.py index a7219438e..14192deec 100644 --- a/detect_secrets/plugins/cloudant.py +++ b/detect_secrets/plugins/cloudant.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re import requests diff --git a/detect_secrets/plugins/common/filters.py b/detect_secrets/plugins/common/filters.py index e95e4a9b5..f7ad1dafd 100644 --- a/detect_secrets/plugins/common/filters.py +++ b/detect_secrets/plugins/common/filters.py @@ -6,8 +6,6 @@ import re import string -from detect_secrets.util import is_python_2 - def is_found_with_aho_corasick(secret, automaton): """ @@ -22,10 +20,6 @@ def is_found_with_aho_corasick(secret, automaton): if not automaton: return False - if is_python_2(): # pragma: no cover - # Due to pyahocorasick - secret = secret.encode('utf-8') - try: # .lower() to make everything case-insensitive next(automaton.iter(string=secret.lower())) diff --git a/detect_secrets/plugins/common/ini_file_parser.py b/detect_secrets/plugins/common/ini_file_parser.py index f9b766c71..5aaec74a6 100644 --- a/detect_secrets/plugins/common/ini_file_parser.py +++ b/detect_secrets/plugins/common/ini_file_parser.py @@ -1,9 +1,4 @@ -from __future__ import unicode_literals - -try: - from backports import configparser -except ImportError: # pragma: no cover - import configparser +import configparser import re @@ -37,12 +32,7 @@ def __init__(self, file, add_header=False, exclude_lines_regex=None): :param exclude_lines_regex: optional regex for ignored lines. """ self.parser = configparser.ConfigParser() - try: - # Python2.7 compatible - self.parser.optionxform = unicode - except NameError: # pragma: no cover - # Python3 compatible - self.parser.optionxform = str + self.parser.optionxform = str self.exclude_lines_regex = exclude_lines_regex @@ -52,12 +42,7 @@ def __init__(self, file, add_header=False, exclude_lines_regex=None): # like config files, without a section header. content = '[global]\n' + content - try: - # Python2.7 compatible - self.parser.read_string(unicode(content)) - except NameError: # pragma: no cover - # Python3 compatible - self.parser.read_string(content) + self.parser.read_string(content) # Hacky way to keep track of line location file.seek(0) diff --git a/detect_secrets/plugins/common/util.py b/detect_secrets/plugins/common/util.py index 87602e106..9815b566f 100644 --- a/detect_secrets/plugins/common/util.py +++ b/detect_secrets/plugins/common/util.py @@ -1,10 +1,6 @@ -try: - from functools import lru_cache -except ImportError: # pragma: no cover - from functools32 import lru_cache - import os from abc import abstractproperty +from functools import lru_cache from importlib import import_module from detect_secrets.plugins.base import BasePlugin diff --git a/detect_secrets/plugins/high_entropy_strings.py b/detect_secrets/plugins/high_entropy_strings.py index 706ad776b..26bc52c64 100644 --- a/detect_secrets/plugins/high_entropy_strings.py +++ b/detect_secrets/plugins/high_entropy_strings.py @@ -1,10 +1,5 @@ -from __future__ import absolute_import - -try: - from backports import configparser -except ImportError: # pragma: no cover - import configparser import base64 +import configparser import math import re import string diff --git a/detect_secrets/plugins/ibm_cloud_iam.py b/detect_secrets/plugins/ibm_cloud_iam.py index 9a2e8f18b..65a23d116 100644 --- a/detect_secrets/plugins/ibm_cloud_iam.py +++ b/detect_secrets/plugins/ibm_cloud_iam.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import requests from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/ibm_cos_hmac.py b/detect_secrets/plugins/ibm_cos_hmac.py index 482bb2e46..5849f844a 100644 --- a/detect_secrets/plugins/ibm_cos_hmac.py +++ b/detect_secrets/plugins/ibm_cos_hmac.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import datetime import hashlib import hmac diff --git a/detect_secrets/plugins/jwt.py b/detect_secrets/plugins/jwt.py index 5a45eba7b..b16ed9083 100644 --- a/detect_secrets/plugins/jwt.py +++ b/detect_secrets/plugins/jwt.py @@ -1,8 +1,6 @@ """ This plugin finds JWT tokens """ -from __future__ import absolute_import - import base64 import json import re @@ -10,13 +8,6 @@ from .base import classproperty from .base import RegexBasedDetector -try: - # Python 2 - from future_builtins import filter -except ImportError: # pragma: no cover - # Python 3 - pass - class JwtTokenDetector(RegexBasedDetector): """Scans for JWTs.""" diff --git a/detect_secrets/plugins/keyword.py b/detect_secrets/plugins/keyword.py index 147550063..42c2c7918 100644 --- a/detect_secrets/plugins/keyword.py +++ b/detect_secrets/plugins/keyword.py @@ -24,8 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from __future__ import absolute_import - import re from .base import BasePlugin diff --git a/detect_secrets/plugins/mailchimp.py b/detect_secrets/plugins/mailchimp.py index b39820a72..f90f6cc90 100644 --- a/detect_secrets/plugins/mailchimp.py +++ b/detect_secrets/plugins/mailchimp.py @@ -1,8 +1,6 @@ """ This plugin searches for Mailchimp keys """ -from __future__ import absolute_import - import re from base64 import b64encode diff --git a/detect_secrets/plugins/private_key.py b/detect_secrets/plugins/private_key.py index eab761929..edd4b5681 100644 --- a/detect_secrets/plugins/private_key.py +++ b/detect_secrets/plugins/private_key.py @@ -24,8 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/slack.py b/detect_secrets/plugins/slack.py index 1c29388d0..cb6427d89 100644 --- a/detect_secrets/plugins/slack.py +++ b/detect_secrets/plugins/slack.py @@ -1,8 +1,6 @@ """ This plugin searches for Slack tokens """ -from __future__ import absolute_import - import re import requests diff --git a/detect_secrets/plugins/softlayer.py b/detect_secrets/plugins/softlayer.py index 30268de2e..b2ca78cf6 100644 --- a/detect_secrets/plugins/softlayer.py +++ b/detect_secrets/plugins/softlayer.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re import requests diff --git a/detect_secrets/plugins/stripe.py b/detect_secrets/plugins/stripe.py index eac70e856..f7f1839b9 100644 --- a/detect_secrets/plugins/stripe.py +++ b/detect_secrets/plugins/stripe.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re from base64 import b64encode diff --git a/detect_secrets/plugins/twilio.py b/detect_secrets/plugins/twilio.py index 78e149481..4d5b397e3 100644 --- a/detect_secrets/plugins/twilio.py +++ b/detect_secrets/plugins/twilio.py @@ -1,8 +1,6 @@ """ This plugin searches for Twilio API keys """ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/pre_commit_hook.py b/detect_secrets/pre_commit_hook.py index 22ad4da7c..b6740d77b 100644 --- a/detect_secrets/pre_commit_hook.py +++ b/detect_secrets/pre_commit_hook.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import -from __future__ import unicode_literals - import os import subprocess import sys diff --git a/detect_secrets/util.py b/detect_secrets/util.py index 86b73f8b7..b5515be64 100644 --- a/detect_secrets/util.py +++ b/detect_secrets/util.py @@ -1,11 +1,6 @@ import hashlib import os import subprocess -import sys - - -def is_python_2(): - return sys.version_info[0] < 3 def build_automaton(word_list): diff --git a/setup.py b/setup.py index 1fd9e5541..8d526b213 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ long_description=( 'Check out detect-secrets on `GitHub `_!' ), - license='Copyright Yelp, Inc. 2018', + license='Copyright Yelp, Inc. 2020', author='Aaron Loo', author_email='aaronloo@yelp.com', url='https://github.com/Yelp/detect-secrets', @@ -23,12 +23,6 @@ 'requests', ], extras_require={ - ':python_version=="2.7"': [ - 'configparser', - 'enum34', - 'future', - 'functools32', - ], 'word_list': [ 'pyahocorasick', ], @@ -40,7 +34,6 @@ ], }, classifiers=[ - 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'License :: OSI Approved :: Apache Software License', 'Intended Audience :: Developers', diff --git a/testing/mocks.py b/testing/mocks.py index 6597618a8..4ef010eb0 100644 --- a/testing/mocks.py +++ b/testing/mocks.py @@ -138,11 +138,7 @@ def __init__(self): self.clear() def add(self, message, *args, **kwargs): - try: - # For python 2.x compatible - self.message += unicode(message) + '\n' - except NameError: - self.message += str(message) + '\n' + self.message += str(message) + '\n' def clear(self): self.message = '' diff --git a/tests/plugins/keyword_test.py b/tests/plugins/keyword_test.py index 9b8866ba2..8e658e300 100644 --- a/tests/plugins/keyword_test.py +++ b/tests/plugins/keyword_test.py @@ -6,7 +6,6 @@ from detect_secrets.core.potential_secret import PotentialSecret from detect_secrets.plugins.keyword import KeywordDetector -from detect_secrets.util import is_python_2 from testing.mocks import mock_file_object @@ -203,9 +202,6 @@ def test_analyze_standard_positives_with_automaton(self, file_content): automaton = ahocorasick.Automaton() word = 'thisone' - if is_python_2(): # pragma: no cover - # Due to pyahocorasick - word = word.encode('utf-8') automaton.add_word(word, word) automaton.make_automaton() diff --git a/tox.ini b/tox.ini index 978620583..4bac44f4d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] project = detect_secrets # These should match the travis env list -envlist = py{35,36,37,38,py,py3} +envlist = py{35,36,37,38} skip_missing_interpreters = true tox_pip_extensions_ext_venv_update = true