def _get_host_overrides(config, hostname): """Get host specific parameters from a vault_pki_overrides file. Args: config a in-memory representation of /etc/salt/master. Returns: A dictionary of Vault compatible keys for PKI signing. """ override_file = config.get('vault_pki_overrides_file') if not override_file: return {} opts = __opts__.copy() opts['file_client'] = 'local' minion = salt_minion.MasterMinion(opts) overrides_filepath = minion.functions['cp.cache_file'](override_file) try: with open(overrides_filepath, 'r') as f: override_data = yaml.safe_load(f.read()) except (IOError, yaml.YAMLError): log.warning( 'vault_pki_overrides_file is unreadable or not YaML, skipping.') return {} # Check hostname against minions matching the pattern + return overrides. ckminions = salt_minion_utils.CkMinions(__opts__) for pattern, values in override_data.items(): minions = ckminions.check_minions(pattern, 'compound') if 'minions' in minions: # In Salt 2018 this is now in a dictionary minions = minions['minions'] if hostname in minions: return values return {}
def setUp(self): self.ckminions = minions.CkMinions({})