golden hour
/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils
⬆️ Go Up
Upload
File/Folder
Size
Actions
__init__.py
237 B
Del
OK
__pycache__
-
Del
OK
aggregation.py
5.17 KB
Del
OK
ansible.py
1.48 KB
Del
OK
args.py
18.33 KB
Del
OK
asynchronous.py
4.06 KB
Del
OK
atomicfile.py
5.33 KB
Del
OK
aws.py
20.37 KB
Del
OK
azurearm.py
11.42 KB
Del
OK
beacons.py
517 B
Del
OK
boto3mod.py
8.36 KB
Del
OK
boto_elb_tag.py
3.02 KB
Del
OK
botomod.py
7.98 KB
Del
OK
cache.py
11.49 KB
Del
OK
channel.py
489 B
Del
OK
cloud.py
116.3 KB
Del
OK
color.py
2.72 KB
Del
OK
compat.py
1.89 KB
Del
OK
configcomparer.py
3.88 KB
Del
OK
configparser.py
10.82 KB
Del
OK
context.py
6.8 KB
Del
OK
crypt.py
5 KB
Del
OK
ctx.py
1.42 KB
Del
OK
data.py
53.03 KB
Del
OK
dateutils.py
2.3 KB
Del
OK
debug.py
4.19 KB
Del
OK
decorators
-
Del
OK
dictdiffer.py
16.48 KB
Del
OK
dicttrim.py
3.9 KB
Del
OK
dictupdate.py
11.33 KB
Del
OK
dns.py
35.21 KB
Del
OK
doc.py
2.25 KB
Del
OK
dockermod
-
Del
OK
entrypoints.py
1.83 KB
Del
OK
environment.py
2.2 KB
Del
OK
error.py
1.18 KB
Del
OK
etcd_util.py
33.25 KB
Del
OK
event.py
52.45 KB
Del
OK
extend.py
8.87 KB
Del
OK
extmods.py
6.04 KB
Del
OK
filebuffer.py
3.15 KB
Del
OK
files.py
27.94 KB
Del
OK
find.py
22.08 KB
Del
OK
fsutils.py
3.29 KB
Del
OK
functools.py
6.02 KB
Del
OK
gitfs.py
130.41 KB
Del
OK
github.py
1.52 KB
Del
OK
gzip_util.py
2.86 KB
Del
OK
hashutils.py
5.91 KB
Del
OK
http.py
33.9 KB
Del
OK
iam.py
1.22 KB
Del
OK
icinga2.py
754 B
Del
OK
idem.py
1.22 KB
Del
OK
immutabletypes.py
2.46 KB
Del
OK
itertools.py
2.36 KB
Del
OK
jid.py
3 KB
Del
OK
jinja.py
33.92 KB
Del
OK
job.py
6.89 KB
Del
OK
json.py
3.78 KB
Del
OK
kickstart.py
41.04 KB
Del
OK
kinds.py
493 B
Del
OK
lazy.py
3.06 KB
Del
OK
listdiffer.py
10.9 KB
Del
OK
locales.py
2.06 KB
Del
OK
mac_utils.py
14.01 KB
Del
OK
mako.py
3.97 KB
Del
OK
master.py
29.7 KB
Del
OK
mattermost.py
1.77 KB
Del
OK
memcached.py
3.56 KB
Del
OK
migrations.py
1.46 KB
Del
OK
mine.py
3.68 KB
Del
OK
minion.py
4.13 KB
Del
OK
minions.py
43.38 KB
Del
OK
mount.py
1.15 KB
Del
OK
msazure.py
5.36 KB
Del
OK
msgpack.py
4.69 KB
Del
OK
nacl.py
13.65 KB
Del
OK
namecheap.py
4.32 KB
Del
OK
napalm.py
23.22 KB
Del
OK
nb_popen.py
7.24 KB
Del
OK
network.py
73.86 KB
Del
OK
nxos.py
12.94 KB
Del
OK
nxos_api.py
4 KB
Del
OK
odict.py
13.21 KB
Del
OK
openstack
-
Del
OK
oset.py
6.41 KB
Del
OK
pagerduty.py
3.03 KB
Del
OK
parsers.py
122.69 KB
Del
OK
path.py
11.24 KB
Del
OK
pbm.py
9.81 KB
Del
OK
pkg
-
Del
OK
platform.py
5.84 KB
Del
OK
powershell.py
4.15 KB
Del
OK
preseed.py
2.64 KB
Del
OK
process.py
40.76 KB
Del
OK
profile.py
3.21 KB
Del
OK
proxy.py
331 B
Del
OK
psutil_compat.py
3.63 KB
Del
OK
pushover.py
4.51 KB
Del
OK
pycrypto.py
5.41 KB
Del
OK
pydsl.py
13.74 KB
Del
OK
pyobjects.py
10.75 KB
Del
OK
reactor.py
18.99 KB
Del
OK
reclass.py
752 B
Del
OK
roster_matcher.py
3.55 KB
Del
OK
rsax931.py
8.42 KB
Del
OK
s3.py
8.78 KB
Del
OK
saltclass.py
14.27 KB
Del
OK
sanitizers.py
2.51 KB
Del
OK
schedule.py
71.81 KB
Del
OK
schema.py
54.26 KB
Del
OK
sdb.py
4.04 KB
Del
OK
slack.py
3.58 KB
Del
OK
smb.py
11.16 KB
Del
OK
smtp.py
3.27 KB
Del
OK
ssdp.py
14.75 KB
Del
OK
ssh.py
769 B
Del
OK
state.py
8.43 KB
Del
OK
stringio.py
355 B
Del
OK
stringutils.py
16.95 KB
Del
OK
systemd.py
5.51 KB
Del
OK
templates.py
24.03 KB
Del
OK
textformat.py
5.03 KB
Del
OK
thin.py
31.91 KB
Del
OK
timed_subprocess.py
4.06 KB
Del
OK
timeout.py
1.53 KB
Del
OK
timeutil.py
2.4 KB
Del
OK
url.py
5 KB
Del
OK
user.py
11.86 KB
Del
OK
validate
-
Del
OK
value.py
247 B
Del
OK
vault.py
21.74 KB
Del
OK
verify.py
25.34 KB
Del
OK
versions.py
17.17 KB
Del
OK
virt.py
3.24 KB
Del
OK
virtualbox.py
22.43 KB
Del
OK
vmware.py
129.74 KB
Del
OK
vsan.py
17.18 KB
Del
OK
vt.py
31.47 KB
Del
OK
vt_helper.py
4.4 KB
Del
OK
win_chcp.py
3.7 KB
Del
OK
win_dacl.py
95.49 KB
Del
OK
win_dotnet.py
4.74 KB
Del
OK
win_functions.py
12.69 KB
Del
OK
win_lgpo_auditpol.py
8.48 KB
Del
OK
win_lgpo_netsh.py
17.87 KB
Del
OK
win_lgpo_reg.py
16.98 KB
Del
OK
win_network.py
16.35 KB
Del
OK
win_osinfo.py
2.83 KB
Del
OK
win_pdh.py
13.85 KB
Del
OK
win_reg.py
30.82 KB
Del
OK
win_runas.py
10.53 KB
Del
OK
win_service.py
5.2 KB
Del
OK
win_system.py
14.47 KB
Del
OK
win_update.py
40.36 KB
Del
OK
winapi.py
818 B
Del
OK
x509.py
73.19 KB
Del
OK
xdg.py
316 B
Del
OK
xmlutil.py
13.91 KB
Del
OK
yaml.py
349 B
Del
OK
yamldumper.py
3.37 KB
Del
OK
yamlencoding.py
1.55 KB
Del
OK
yamllint.py
1.61 KB
Del
OK
yamlloader.py
6.04 KB
Del
OK
yamlloader_old.py
8.15 KB
Del
OK
yast.py
619 B
Del
OK
zeromq.py
1.74 KB
Del
OK
zfs.py
19.15 KB
Del
OK
Edit: path.py
""" Platform independent versions of some os/os.path functions. Gets around PY2's lack of support for reading NTFS links. """ import logging import os import posixpath import re from collections.abc import Iterable import salt.utils.args import salt.utils.platform import salt.utils.stringutils from salt.exceptions import CommandNotFoundError from salt.utils.decorators.jinja import jinja_filter try: import win32file HAS_WIN32FILE = True except ImportError: HAS_WIN32FILE = False log = logging.getLogger(__name__) def islink(path): """ Equivalent to os.path.islink() """ return os.path.islink(path) def readlink(path): """ Equivalent to os.readlink() """ base = os.readlink(path) if salt.utils.platform.is_windows(): # Python 3.8 added support for directory junctions which prefixes the # return with `\\?\`. We need to strip that off. # https://docs.python.org/3/library/os.html#os.readlink if base.startswith("\\\\?\\"): base = base[4:] return base def _is_reparse_point(path): """ Returns True if path is a reparse point; False otherwise. """ result = win32file.GetFileAttributesW(path) if result == -1: return False return True if result & 0x400 else False def _get_reparse_data(path): """ Retrieves the reparse point data structure for the given path. If the path is not a reparse point, None is returned. See http://msdn.microsoft.com/en-us/library/ff552012.aspx for details on the REPARSE_DATA_BUFFER structure returned. """ # ensure paths are using the right slashes path = os.path.normpath(path) if not _is_reparse_point(path): return None fileHandle = None try: fileHandle = win32file.CreateFileW( path, 0x80000000, # GENERIC_READ 1, # share with other readers None, # no inherit, default security descriptor 3, # OPEN_EXISTING 0x00200000 | 0x02000000, # FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS ) reparseData = win32file.DeviceIoControl( fileHandle, 0x900A8, # FSCTL_GET_REPARSE_POINT None, # in buffer 16384, # out buffer size (MAXIMUM_REPARSE_DATA_BUFFER_SIZE) ) finally: if fileHandle: win32file.CloseHandle(fileHandle) return reparseData @jinja_filter("which") def which(exe=None): """ Python clone of /usr/bin/which """ if not exe: log.error("No executable was passed to be searched by salt.utils.path.which()") return None ## define some utilities (we use closures here because our predecessor used them) def is_executable_common(path): """ This returns truth if posixy semantics (which python simulates on windows) states that this is executable. """ return os.path.isfile(path) and os.access(path, os.X_OK) def resolve(path): """ This will take a path and recursively follow the link until we get to a real file. """ while os.path.islink(path): res = readlink(path) # if the link points to a relative target, then convert it to an # absolute path relative to the original path if not os.path.isabs(res): directory, _ = os.path.split(path) res = join(directory, res) path = res return path # windows-only def has_executable_ext(path, ext_membership): """ Extract the extension from the specified path, lowercase it so we can be insensitive, and then check it against the available exts. """ p, ext = os.path.splitext(path) return ext.lower() in ext_membership ## prepare related variables from the environment res = salt.utils.stringutils.to_unicode(os.environ.get("PATH", "")) system_path = res.split(os.pathsep) # add some reasonable defaults in case someone's PATH is busted if not salt.utils.platform.is_windows(): res = set(system_path) extended_path = [ "/sbin", "/bin", "/usr/sbin", "/usr/bin", "/usr/local/sbin", "/usr/local/bin", ] system_path.extend([p for p in extended_path if p not in res]) ## now to define the semantics of what's considered executable on a given platform if salt.utils.platform.is_windows(): # executable semantics on windows requires us to search PATHEXT res = salt.utils.stringutils.to_str(os.environ.get("PATHEXT", ".EXE")) # generate two variables, one of them for O(n) searches (but ordered) # and another for O(1) searches. the previous guy was trying to use # memoization with a function that has no arguments, this provides # the exact same benefit pathext = res.split(os.pathsep) res = {ext.lower() for ext in pathext} # check if our caller already specified a valid extension as then we don't need to match it _, ext = os.path.splitext(exe) if ext.lower() in res: pathext = [""] is_executable = is_executable_common # The specified extension isn't valid, so we just assume it's part of the # filename and proceed to walk the pathext list else: is_executable = lambda path, membership=res: is_executable_common( path ) and has_executable_ext(path, membership) else: # in posix, there's no such thing as file extensions..only zuul pathext = [""] # executable semantics are pretty simple on reasonable platforms... is_executable = is_executable_common ## search for the executable # check to see if the full path was specified as then we don't need # to actually walk the system_path for any reason if is_executable(exe): return exe # now to search through our system_path for path in system_path: p = join(path, exe) # iterate through all extensions to see which one is executable for ext in pathext: pext = p + ext rp = resolve(pext) if is_executable(rp): return p + ext continue continue ## if something was executable, we should've found it already... log.trace( "'%s' could not be found in the following search path: '%s'", exe, system_path ) return None def which_bin(exes): """ Scan over some possible executables and return the first one that is found """ if isinstance(exes, str): exes = [exes] if not isinstance(exes, Iterable): return None for exe in exes: path = which(exe) if not path: continue return path return None @jinja_filter("path_join") def join(*parts, **kwargs): """ This functions tries to solve some issues when joining multiple absolute paths on both *nix and windows platforms. See tests/unit/utils/path_join_test.py for some examples on what's being talked about here. The "use_posixpath" kwarg can be be used to force joining using poxixpath, which is useful for Salt fileserver paths on Windows masters. """ parts = [salt.utils.stringutils.to_str(part) for part in parts] kwargs = salt.utils.args.clean_kwargs(**kwargs) use_posixpath = kwargs.pop("use_posixpath", False) if kwargs: salt.utils.args.invalid_kwargs(kwargs) pathlib = posixpath if use_posixpath else os.path # Normalize path converting any os.sep as needed parts = [pathlib.normpath(p) for p in parts] try: root = parts.pop(0) except IndexError: # No args passed to func return "" root = salt.utils.stringutils.to_unicode(root) if not parts: ret = root else: stripped = [p.lstrip(os.sep) for p in parts] ret = pathlib.join(root, *salt.utils.data.decode(stripped)) return pathlib.normpath(ret) def check_or_die(command): """ Simple convenience function for modules to use for gracefully blowing up if a required tool is not available in the system path. Lazily import `salt.modules.cmdmod` to avoid any sort of circular dependencies. """ if command is None: raise CommandNotFoundError("'None' is not a valid command.") if not which(command): raise CommandNotFoundError("'{}' is not in the path".format(command)) def sanitize_win_path(winpath): """ Remove illegal path characters for windows """ intab = "<>:|?*" if isinstance(winpath, str): winpath = winpath.translate({ord(c): "_" for c in intab}) elif isinstance(winpath, str): outtab = "_" * len(intab) trantab = "".maketrans(intab, outtab) winpath = winpath.translate(trantab) return winpath def safe_path(path, allow_path=None): r""" .. versionadded:: 2017.7.3 Checks that the path is safe for modification by Salt. For example, you wouldn't want to have salt delete the contents of ``C:\Windows``. The following directories are considered unsafe: - C:\, D:\, E:\, etc. - \ - C:\Windows Args: path (str): The path to check allow_paths (str, list): A directory or list of directories inside of path that may be safe. For example: ``C:\Windows\TEMP`` Returns: bool: True if safe, otherwise False """ # Create regex definitions for directories that may be unsafe to modify system_root = os.environ.get("SystemRoot", "C:\\Windows") deny_paths = ( r"[a-z]\:\\$", # C:\, D:\, etc r"\\$", # \ re.escape(system_root), # C:\Windows ) # Make allow_path a list if allow_path and not isinstance(allow_path, list): allow_path = [allow_path] # Create regex definition for directories we may want to make exceptions for allow_paths = list() if allow_path: for item in allow_path: allow_paths.append(re.escape(item)) # Check the path to make sure it's not one of the bad paths good_path = True for d_path in deny_paths: if re.match(d_path, path, flags=re.IGNORECASE) is not None: # Found deny path good_path = False # If local_dest is one of the bad paths, check for exceptions if not good_path: for a_path in allow_paths: if re.match(a_path, path, flags=re.IGNORECASE) is not None: # Found exception good_path = True return good_path def os_walk(top, *args, **kwargs): """ This is a helper than ensures that all paths returned from os.walk are unicode. """ top_query = salt.utils.stringutils.to_str(top) for item in os.walk(top_query, *args, **kwargs): yield salt.utils.data.decode(item, preserve_tuples=True) def expand(path): """ Expands all user and environment variables .. versionadded:: 3005 Args: path (str): A path to a file or directory Returns: str: A fully expanded, real path """ path = os.path.expanduser(path) # expand ~ to home directory path = os.path.expandvars(path) # expand any other environment vars return os.path.realpath(path) # fix path format
Save