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

Supports all valid protos for remote sources #53462

Merged
merged 3 commits into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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