Skip to content

Commit 4a6266d

Browse files
author
Martin Silkjær
committed
Added option for download of attachments and update of Readme.md
1 parent efdda86 commit 4a6266d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ok: [localhost] => {
5252
```yaml
5353
# Get username for Google
5454
- debug:
55-
msg: {{ lookup('bitwarden', 'Google', field='username' }}
55+
msg: {{ lookup('bitwarden', 'Google', field='username') }}
5656
```
5757
5858
The above might result in:
@@ -69,7 +69,7 @@ ok: [localhost] => {
6969
```yaml
7070
# Get all available fields for an entry
7171
- debug:
72-
msg: {{ lookup('bitwarden', 'Google', field='item' }}
72+
msg: {{ lookup('bitwarden', 'Google', field='item') }}
7373
```
7474
7575
The above might result in:
@@ -109,7 +109,7 @@ ok: [localhost] => {
109109
```yaml
110110
# Get the value of a custom field
111111
- debug:
112-
msg: {{ lookup('bitwarden', 'Google', field='mycustomfield', custom_field=true }}
112+
msg: {{ lookup('bitwarden', 'Google', field='mycustomfield', custom_field=true) }}
113113
```
114114
115115
The above might result in:
@@ -120,3 +120,21 @@ ok: [localhost] => {
120120
"msg": "the value of my custom field"
121121
}
122122
```
123+
124+
### download attachments files
125+
126+
```yaml
127+
# Get the value of a custom field
128+
- debug:
129+
msg: {{ lookup('bitwarden', 'privateKey.pem', itemid='123456-1234-1234-abbf-60c345aaa3e', attachments=true ) }}
130+
```
131+
Optional parameters - output='/ansible/publicKey.pem'
132+
133+
The above might result in:
134+
135+
```
136+
TASK [debug] *********************************************************
137+
ok: [localhost] => {
138+
"msg": "Saved /publicKey.pem"
139+
}
140+
```

lookup_plugins/bitwarden.py

+13
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def get_custom_field(self, key, field):
120120
data = json.loads(self.get_entry(key, 'item'))
121121
return next(x for x in data['fields'] if x['name'] == field)['value']
122122

123+
def get_attachments(self, key, itemid, output):
124+
attachment = ['get', 'attachment', '{}'.format(key), '--output={}'.format(output), '--itemid={}'.format(itemid)]
125+
return self._run(attachment)
126+
123127

124128
class LookupModule(LookupBase):
125129

@@ -142,6 +146,15 @@ def run(self, terms, variables=None, **kwargs):
142146
values.append(bw.get_custom_field(term, field))
143147
elif field == 'notes':
144148
values.append(bw.get_notes(term))
149+
if kwargs.get('attachments'):
150+
if kwargs.get('itemid'):
151+
itemid = kwargs.get('itemid')
152+
output = kwargs.get('output', term)
153+
values.append(bw.get_attachments(term, itemid, output))
154+
else:
155+
raise AnsibleError("Missing value for - itemid - "
156+
"Please set parameters as example: - "
157+
"itemid='f12345-d343-4bd0-abbf-4532222' ")
145158
else:
146159
values.append(bw.get_entry(term, field))
147160
return values

0 commit comments

Comments
 (0)