Skip to content

Commit 433181e

Browse files
committed
Improve collection of attributes from data files by limiting to the core
Python types available. This avoids imported functions/etc polluting host data.
1 parent dbc5a2a commit 433181e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pyinfra/cli.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import shlex
1111
import logging
1212
import traceback
13+
1314
from os import path
1415
from fnmatch import fnmatch
1516
from datetime import datetime
@@ -27,11 +28,10 @@
2728
io_bases = IOBase
2829

2930
import six
31+
3032
from termcolor import colored
3133

3234
from pyinfra import logger, pseudo_inventory
33-
from pyinfra.pseudo_modules import PseudoModule
34-
3535
from pyinfra.api import Config, Inventory
3636
from pyinfra.api.facts import get_fact_names, is_fact
3737
from pyinfra.api.exceptions import PyinfraError
@@ -42,6 +42,11 @@
4242
STDOUT_LOG_LEVELS = (logging.DEBUG, logging.INFO)
4343
STDERR_LOG_LEVELS = (logging.WARNING, logging.ERROR, logging.CRITICAL)
4444

45+
ALLOWED_DATA_TYPES = tuple(
46+
list(six.string_types) + list(six.integer_types)
47+
+ [bool, dict, list, set, tuple, float, complex]
48+
)
49+
4550

4651
class CliError(PyinfraError):
4752
pass
@@ -557,11 +562,10 @@ def make_inventory(
557562
# Read the files locals into a dict
558563
attrs = exec_file(data_filename, return_locals=True)
559564

560-
# Strip out any pseudo module imports and _prefixed variables
561565
data.update({
562566
key: value
563567
for key, value in six.iteritems(attrs)
564-
if not isinstance(value, PseudoModule)
568+
if isinstance(value, ALLOWED_DATA_TYPES)
565569
and not key.startswith('_')
566570
and key.islower()
567571
})
@@ -588,7 +592,6 @@ def make_inventory(
588592
host for host in all_hosts
589593
if (isinstance(host, tuple) and fnmatch(host[0], limit))
590594
or (isinstance(host, six.string_types) and fnmatch(host, limit))
591-
592595
]
593596

594597
# Reassign the ALL group w/limit

0 commit comments

Comments
 (0)