diff --git a/salt/modules/config.py b/salt/modules/config.py index ce490234e1b3..0792d0a30b26 100644 --- a/salt/modules/config.py +++ b/salt/modules/config.py @@ -7,7 +7,6 @@ from __future__ import absolute_import, print_function, unicode_literals import copy import fnmatch -import re import os import logging @@ -129,10 +128,10 @@ def valid_fileproto(uri): salt '*' config.valid_fileproto salt://path/to/file ''' - try: - return bool(re.match('^(?:salt|https?|ftp)://', uri)) - except Exception: - return False + return ( + six.moves.urllib.parse.urlparse(uri).scheme in + salt.utils.files.VALID_PROTOS + ) def option( diff --git a/salt/modules/cp.py b/salt/modules/cp.py index d1deede8e9eb..3c5e8215a63a 100644 --- a/salt/modules/cp.py +++ b/salt/modules/cp.py @@ -492,7 +492,7 @@ def cache_file(path, saltenv='base', source_hash=None): contextkey = '{0}_|-{1}_|-{2}'.format('cp.cache_file', path, saltenv) - path_is_remote = _urlparse(path).scheme in ('http', 'https', 'ftp') + path_is_remote = _urlparse(path).scheme in salt.utils.files.REMOTE_PROTOS try: if path_is_remote and contextkey in __context__: # Prevent multiple caches in the same salt run. Affects remote URLs diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py index a1e3a055a2f5..311576f3e3d5 100644 --- a/salt/modules/win_pkg.py +++ b/salt/modules/win_pkg.py @@ -1522,7 +1522,7 @@ def install(name=None, refresh=False, pkgs=None, **kwargs): continue # Is the installer in a location that requires caching - if installer.startswith(('salt:', 'http:', 'https:', 'ftp:')): + if __salt__['config.valid_fileproto'](installer): # Check for the 'cache_dir' parameter in the .sls file # If true, the entire directory will be cached instead of the diff --git a/tests/integration/modules/test_config.py b/tests/integration/modules/test_config.py index be9aed3396c1..cbc582a52826 100644 --- a/tests/integration/modules/test_config.py +++ b/tests/integration/modules/test_config.py @@ -20,12 +20,18 @@ def test_valid_file_proto(self): ''' self.assertTrue( self.run_function('config.valid_fileproto', ['salt://'])) + self.assertTrue( + self.run_function('config.valid_fileproto', ['file://'])) self.assertTrue( self.run_function('config.valid_fileproto', ['http://'])) self.assertTrue( self.run_function('config.valid_fileproto', ['https://'])) self.assertTrue( self.run_function('config.valid_fileproto', ['ftp://'])) + self.assertTrue( + self.run_function('config.valid_fileproto', ['s3://'])) + self.assertTrue( + self.run_function('config.valid_fileproto', ['swift://'])) self.assertFalse( self.run_function('config.valid_fileproto', ['cheese://'])) diff --git a/tests/unit/modules/test_win_pkg.py b/tests/unit/modules/test_win_pkg.py index 50cd3a8e1106..e0dedb9520bc 100644 --- a/tests/unit/modules/test_win_pkg.py +++ b/tests/unit/modules/test_win_pkg.py @@ -12,6 +12,7 @@ from tests.support.unit import TestCase, skipIf # Import Salt Libs +import salt.modules.config as config import salt.modules.pkg_resource as pkg_resource import salt.modules.win_pkg as win_pkg import salt.utils.data @@ -54,6 +55,7 @@ def setup_loader_modules(self): 'pkg_resource.parse_targets': pkg_resource.parse_targets, 'pkg_resource.sort_pkglist': pkg_resource.sort_pkglist, 'pkg_resource.stringify': pkg_resource.stringify, + 'config.valid_fileproto': config.valid_fileproto, }, }, pkg_resource: {