Skip to content

Commit

Permalink
feat: add --no-version-check cmdline option
Browse files Browse the repository at this point in the history
Skip the remote version check (to s3) if the user passes
`--no-version-check` as a cmdline option.

Fixes #42

Signed-off-by: Dominic Evans <[email protected]>
  • Loading branch information
dnwe committed Nov 22, 2023
1 parent f939493 commit 2513f61
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
16 changes: 15 additions & 1 deletion detect_secrets/core/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def add_no_verify_flag(parser):
)


def add_no_version_check_flag(parser):
parser.add_argument(
'--no-version-check',
action='store_true',
help='Disables detect-secrets up-to-date version check.',
)


def add_output_verified_false_flag(parser):
parser.add_argument(
'--output-verified-false',
Expand Down Expand Up @@ -75,7 +83,9 @@ def __init__(self):
self.add_default_arguments()

def add_default_arguments(self):
self._add_verbosity_argument()._add_version_argument()
self._add_no_version_check_flag()\
._add_verbosity_argument()\
._add_version_argument()

def add_pre_commit_arguments(self):
self._add_filenames_argument()\
Expand Down Expand Up @@ -160,6 +170,10 @@ def _add_no_verify_flag(self):
add_no_verify_flag(self.parser)
return self

def _add_no_version_check_flag(self):
add_no_version_check_flag(self.parser)
return self

def _add_output_verified_false_flag(self):
add_output_verified_false_flag(self.parser)
return self
Expand Down
6 changes: 3 additions & 3 deletions detect_secrets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def parse_args(argv, parserBuilder):


def main(argv=None):

version_check()

if len(sys.argv) == 1: # pragma: no cover
sys.argv.append('-h')

Expand All @@ -30,6 +27,9 @@ def main(argv=None):
if args.verbose: # pragma: no cover
log.set_debug_level(3)

if not args.no_version_check:
version_check()

if args.action == 'scan':
automaton = None
word_list_hash = None
Expand Down
4 changes: 3 additions & 1 deletion detect_secrets/pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def parse_args(argv):


def main(argv=None):
version_check()
args = parse_args(argv)
if args.verbose: # pragma: no cover
log.set_debug_level(3)

if not args.no_version_check:
version_check()

try:
# If baseline is provided, we first want to make sure
# it's valid, before doing any further computation.
Expand Down
9 changes: 8 additions & 1 deletion detect_secrets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
from packaging.version import parse

from detect_secrets import VERSION
from detect_secrets.core.log import get_logger

log = get_logger(format_string='%(message)s')

def version_check():
# check if running latest version, if not print warning
# get latest version from GHE
yellow = '\033[93m'
end_yellow = '\033[0m'

current_version = parse(VERSION)
log.debug('detect-secrets: checking if up-to-date: version=%s',
current_version)
try:
resp = requests.get(
(
Expand All @@ -24,7 +30,8 @@ def version_check():
)
resp.raise_for_status()
latest_version = parse(resp.text)
current_version = parse(VERSION)
log.debug('detect-secrets: latest_version=%s up-to-date=%r',
latest_version, current_version >= latest_version)
if current_version < latest_version:
print(
yellow +
Expand Down

0 comments on commit 2513f61

Please sign in to comment.