mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add ssl argument to mongo pillar
This commit is contained in:
parent
23db530c03
commit
a8ec3585a4
2 changed files with 33 additions and 0 deletions
|
@ -129,12 +129,25 @@ def ext_pillar(
|
|||
careful with other fields in the document as they must be string
|
||||
serializable. Defaults to ``None``.
|
||||
"""
|
||||
host = __opts__["mongo.host"]
|
||||
port = __opts__["mongo.port"]
|
||||
ssl = __opts__.get("mongo.ssl") or False
|
||||
log.info("connecting to %s:%s for mongo ext_pillar", host, port)
|
||||
conn = pymongo.MongoClient(host=host, port=port, ssl=ssl)
|
||||
|
||||
log.debug("using database '%s'", __opts__["mongo.db"])
|
||||
mdb = conn[__opts__["mongo.db"]]
|
||||
|
||||
uri = __opts__.get("mongo.uri")
|
||||
host = __opts__.get("mongo.host")
|
||||
port = __opts__.get("mongo.port")
|
||||
user = __opts__.get("mongo.user")
|
||||
password = __opts__.get("mongo.password")
|
||||
|
||||
if user and password:
|
||||
log.debug("authenticating as '%s'", user)
|
||||
mdb.authenticate(user, password)
|
||||
|
||||
db = __opts__.get("mongo.db")
|
||||
|
||||
if uri:
|
||||
|
|
|
@ -28,3 +28,23 @@ def test_config_exception():
|
|||
with patch.dict(mongo.__opts__, opts):
|
||||
with pytest.raises(salt.exceptions.SaltConfigurationError):
|
||||
mongo.ext_pillar("minion1", {})
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expected_ssl, use_ssl",
|
||||
[
|
||||
(True, {"mongo.ssl": True}),
|
||||
(False, {"mongo.ssl": False}),
|
||||
(False, {"mongo.ssl": None}),
|
||||
(False, {}),
|
||||
],
|
||||
)
|
||||
def test_mongo_pillar_should_use_ssl_when_set_in_opts(expected_ssl, use_ssl):
|
||||
with patch.dict(
|
||||
"salt.pillar.mongo.__opts__",
|
||||
{**use_ssl, **{"mongo.host": "fnord", "mongo.port": "fnordport"}},
|
||||
), patch("salt.pillar.mongo.pymongo", create=True) as fake_mongo:
|
||||
mongo.ext_pillar(minion_id="blarp", pillar=None)
|
||||
fake_mongo.MongoClient.assert_called_with(
|
||||
host="fnord", port="fnordport", ssl=expected_ssl
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue