HEX
Server: Apache
System: Linux server.enlacediseno.com 4.18.0-553.62.1.el8_10.x86_64 #1 SMP Wed Jul 16 04:08:25 EDT 2025 x86_64
User: maor (1069)
PHP: 7.3.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/migrations.py
"""
Migration tools
"""

import os.path
import shutil

import salt.syspaths as syspaths


def migrate_paths(opts):
    """
    Migrate old minion and master pki file paths to new ones.
    """
    oldpki_dir = os.path.join(syspaths.CONFIG_DIR, "pki")

    if not os.path.exists(oldpki_dir):
        # There's not even a pki directory, don't bother migrating
        return

    newpki_dir = opts["pki_dir"]

    if opts["default_include"].startswith("master"):
        keepers = [
            "master.pem",
            "master.pub",
            "syndic_master.pub",
            "minions",
            "minions_pre",
            "minions_rejected",
        ]
        if not os.path.exists(newpki_dir):
            os.makedirs(newpki_dir)
        for item in keepers:
            oi_path = os.path.join(oldpki_dir, item)
            ni_path = os.path.join(newpki_dir, item)
            if os.path.exists(oi_path) and not os.path.exists(ni_path):
                shutil.move(oi_path, ni_path)

    if opts["default_include"].startswith("minion"):
        keepers = [
            "minion_master.pub",
            "minion.pem",
            "minion.pub",
        ]
        if not os.path.exists(newpki_dir):
            os.makedirs(newpki_dir)
        for item in keepers:
            oi_path = os.path.join(oldpki_dir, item)
            ni_path = os.path.join(newpki_dir, item)
            if os.path.exists(oi_path) and not os.path.exists(ni_path):
                shutil.move(oi_path, ni_path)