Debian Codegraph @

ansible_collections/community/general/plugins/lookup/onepassword_raw.py

raw
1 # Copyright (c) 2018, Scott Buchanan <[email protected]>
2 # Copyright (c) 2016, Andrew Zenk <[email protected]> (lastpass.py used as starting point)
3 # Copyright (c) 2018, Ansible Project
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 name: onepassword_raw
11 author:
12 - Scott Buchanan (@scottsb)
13 - Andrew Zenk (@azenk)
14 - Sam Doran (@samdoran)
15 short_description: Fetch an entire item from 1Password
16 description:
17 - P(community.general.onepassword_raw#lookup) wraps C(op) command line utility to fetch an entire item from 1Password.
18 options:
19 _terms:
20 description: Identifier(s) (case-insensitive UUID or name) of item(s) to retrieve.
21 required: true
22 type: list
23 elements: string
24 account_id:
25 version_added: 7.5.0
26 domain:
27 version_added: 6.0.0
28 service_account_token:
29 version_added: 7.1.0
30 extends_documentation_fragment:
31 - community.general._onepassword
32 - community.general._onepassword.lookup
33 """
34
35 EXAMPLES = r"""
36 ---
37 - name: Retrieve all data about Wintermute
38 ansible.builtin.debug:
39 var: lookup('community.general.onepassword_raw', 'Wintermute')
40
41 - name: Retrieve all data about Wintermute when not signed in to 1Password
42 ansible.builtin.debug:
43 var: lookup('community.general.onepassword_raw', 'Wintermute', subdomain='Turing', vault_password='DmbslfLvasjdl')
44 """
45
46 RETURN = r"""
47 _raw:
48 description: Entire item requested.
49 type: list
50 elements: dict
51 """
52
53 import json
54
55 from ansible.plugins.lookup import LookupBase
56
57 from ansible_collections.community.general.plugins.lookup.onepassword import OnePass
58 from ansible_collections.community.general.plugins.plugin_utils._lookup import check_for_wrong_terms
59
60
61 class LookupModule(LookupBase):
62 def run(self, terms, variables=None, **kwargs):
63 self.set_options(var_options=variables, direct=kwargs)
64 check_for_wrong_terms(self, direct=kwargs)
65
66 vault = self.get_option("vault")
67 subdomain = self.get_option("subdomain")
68 domain = self.get_option("domain", "1password.com")
69 username = self.get_option("username")
70 secret_key = self.get_option("secret_key")
71 master_password = self.get_option("master_password")
72 service_account_token = self.get_option("service_account_token")
73 account_id = self.get_option("account_id")
74 connect_host = self.get_option("connect_host")
75 connect_token = self.get_option("connect_token")
76
77 op = OnePass(
78 subdomain=subdomain,
79 domain=domain,
80 username=username,
81 secret_key=secret_key,
82 master_password=master_password,
83 service_account_token=service_account_token,
84 account_id=account_id,
85 connect_host=connect_host,
86 connect_token=connect_token,
87 )
88 op.assert_logged_in()
89
90 values = []
91 for term in terms:
92 data = json.loads(op.get_raw(term, vault))
93 values.append(data)
94
95 return values