Skip to content

Commit

Permalink
Merge pull request #53462 from lorengordon/remote-sources
Browse files Browse the repository at this point in the history
Supports all valid protos for remote sources
  • Loading branch information
dwoz authored Dec 28, 2019
2 parents bd57aa6 + 929a4b7 commit bbe6a31
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
9 changes: 4 additions & 5 deletions salt/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import absolute_import, print_function, unicode_literals
import copy
import fnmatch
import re
import os
import logging

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/modules/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://']))

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/modules/test_win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit bbe6a31

Please sign in to comment.