Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💥 Drop Python 2 support #292

Merged
merged 10 commits into from
Mar 31, 2020
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: .*
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ If you love `detect-secrets`, please star our project on GitHub to show your sup
[@xxxx]: https://github.com/xxxx
-->

<!--
### Unreleased
-->


# v0.13.1
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
9 changes: 1 addition & 8 deletions detect_secrets/core/audit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import print_function
from __future__ import unicode_literals

import codecs
import io
import json
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/core/baseline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import json
import os
import re
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/core/code_snippet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import itertools

from .color import AnsiColor
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/core/color.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from enum import Enum


Expand Down
11 changes: 6 additions & 5 deletions detect_secrets/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
13 changes: 2 additions & 11 deletions detect_secrets/core/secrets_collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import codecs
import json
import os
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions detect_secrets/core/usage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import argparse
from collections import namedtuple

Expand Down Expand Up @@ -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
)

Expand Down
5 changes: 0 additions & 5 deletions detect_secrets/main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/artifactory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re

from .base import RegexBasedDetector
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/aws.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
This plugin searches for AWS key IDs
"""
from __future__ import absolute_import

import hashlib
import hmac
import re
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/basic_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re

from .base import RegexBasedDetector
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/cloudant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re

import requests
Expand Down
6 changes: 0 additions & 6 deletions detect_secrets/plugins/common/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import re
import string

from detect_secrets.util import is_python_2


def is_found_with_aho_corasick(secret, automaton):
"""
Expand All @@ -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()))
Expand Down
21 changes: 3 additions & 18 deletions detect_secrets/plugins/common/ini_file_parser.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions detect_secrets/plugins/common/util.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/ibm_cloud_iam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import requests

from .base import RegexBasedDetector
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/ibm_cos_hmac.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import datetime
import hashlib
import hmac
Expand Down
9 changes: 0 additions & 9 deletions detect_secrets/plugins/jwt.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
"""
This plugin finds JWT tokens
"""
from __future__ import absolute_import

import base64
import json
import re

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."""
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/mailchimp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
This plugin searches for Mailchimp keys
"""
from __future__ import absolute_import

import re
from base64 import b64encode

Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/private_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/slack.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
This plugin searches for Slack tokens
"""
from __future__ import absolute_import

import re

import requests
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/softlayer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re

import requests
Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/stripe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re
from base64 import b64encode

Expand Down
2 changes: 0 additions & 2 deletions detect_secrets/plugins/twilio.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
This plugin searches for Twilio API keys
"""
from __future__ import absolute_import

import re

from .base import RegexBasedDetector
Expand Down
3 changes: 0 additions & 3 deletions detect_secrets/pre_commit_hook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import os
import subprocess
import sys
Expand Down
Loading