mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
* Support 1Password Connect (#5588) - Support 1Password Connect with the opv2 client * Follow pep8, be less explicit * Update changelog to include PR * 1Password Connect host and token are now also parameters * Get argument values from the environment or lookup arguments * Move imports * Force using Connect token and host at the same time * Update unit tests * Update documentation * Additional tests
This commit is contained in:
parent
32fa588f47
commit
f8652571f7
4 changed files with 104 additions and 6 deletions
|
@ -18,7 +18,7 @@ from .onepassword_conftest import ( # noqa: F401, pylint: disable=unused-import
|
|||
)
|
||||
from .onepassword_common import MOCK_ENTRIES
|
||||
|
||||
from ansible.errors import AnsibleLookupError
|
||||
from ansible.errors import AnsibleLookupError, AnsibleOptionsError
|
||||
from ansible.plugins.loader import lookup_loader
|
||||
from ansible_collections.community.general.plugins.lookup.onepassword import (
|
||||
OnePassCLIv1,
|
||||
|
@ -82,6 +82,12 @@ def test_assert_logged_in_v2(mocker, args, out, expected_call_args, expected_cal
|
|||
assert result == expected
|
||||
|
||||
|
||||
def test_assert_logged_in_v2_connect():
|
||||
op_cli = OnePassCLIv2(connect_host="http://localhost:8080", connect_token="foobar")
|
||||
result = op_cli.assert_logged_in()
|
||||
assert result
|
||||
|
||||
|
||||
def test_full_signin_v2(mocker):
|
||||
mocker.patch.object(OnePassCLIv2, "_run", return_value=[0, "", ""])
|
||||
|
||||
|
@ -266,3 +272,34 @@ def test_signin(op_fixture, request):
|
|||
op._cli.signin()
|
||||
print(op._cli.version)
|
||||
op._cli._run.assert_called_once_with(['signin', '--raw'], command_input=b"master_pass")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("plugin", "connect_host", "connect_token"),
|
||||
[
|
||||
(plugin, connect_host, connect_token)
|
||||
for plugin in ("community.general.onepassword", "community.general.onepassword_raw")
|
||||
for (connect_host, connect_token) in
|
||||
(
|
||||
("http://localhost", None),
|
||||
(None, "foobar"),
|
||||
)
|
||||
]
|
||||
)
|
||||
def test_op_connect_partial_args(plugin, connect_host, connect_token):
|
||||
op_lookup = lookup_loader.get(plugin)
|
||||
with pytest.raises(AnsibleOptionsError):
|
||||
op_lookup.run("login", vault_name="test vault", connect_host=connect_host, connect_token=connect_token)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("kwargs"),
|
||||
(
|
||||
{"connect_host": "http://localhost", "connect_token": "foobar"},
|
||||
{"service_account_token": "foobar"},
|
||||
)
|
||||
)
|
||||
def test_opv1_unsupported_features(kwargs):
|
||||
op_cli = OnePassCLIv1(**kwargs)
|
||||
with pytest.raises(AnsibleLookupError):
|
||||
op_cli.full_signin()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue