make flake8 happy
This commit is contained in:
parent
250d5b26cc
commit
e5dd4eae60
|
@ -1,10 +1,11 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# (c) 2018, Matt Stofko <matt@mjslabs.com>
|
# (c) 2018, Matt Stofko <matt@mjslabs.com>
|
||||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see LICENSE or
|
||||||
|
# https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
#
|
||||||
# This plugin can be run directly by specifying the field followed by a list of entries, e.g.
|
# This plugin can be run directly by specifying the field followed by a list of
|
||||||
# bitwarden.py password google.com wufoo.com
|
# entries, e.g. bitwarden.py password google.com wufoo.com
|
||||||
#
|
#
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
@ -34,7 +35,8 @@ DOCUMENTATION = """
|
||||||
- BW_SESSION environment var (from `bw login` or `bw unlock`)
|
- BW_SESSION environment var (from `bw login` or `bw unlock`)
|
||||||
short_description: look up data from a bitwarden vault
|
short_description: look up data from a bitwarden vault
|
||||||
description:
|
description:
|
||||||
- use the bw command line utility to grab one or more items stored in a bitwarden vault
|
- use the bw command line utility to grab one or more items stored in a
|
||||||
|
bitwarden vault
|
||||||
options:
|
options:
|
||||||
_terms:
|
_terms:
|
||||||
description: name of item that contains the field to fetch
|
description: name of item that contains the field to fetch
|
||||||
|
@ -82,17 +84,23 @@ class Bitwarden(object):
|
||||||
out, err = p.communicate()
|
out, err = p.communicate()
|
||||||
rc = p.wait()
|
rc = p.wait()
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
display.debug("Received error when running '{0} {1}': {2}".format(self.cli_path, args, out))
|
display.debug("Received error when running '{0} {1}': {2}"
|
||||||
|
.format(self.cli_path, args, out))
|
||||||
if out.startswith("Vault is locked."):
|
if out.startswith("Vault is locked."):
|
||||||
raise AnsibleError("Error accessing Bitwarden vault. Run 'bw unlock' to unlock the vault.")
|
raise AnsibleError("Error accessing Bitwarden vault. "
|
||||||
|
"Run 'bw unlock' to unlock the vault.")
|
||||||
elif out.startswith("You are not logged in."):
|
elif out.startswith("You are not logged in."):
|
||||||
raise AnsibleError("Error accessing Bitwarden vault. Run 'bw login' to login.")
|
raise AnsibleError("Error accessing Bitwarden vault. "
|
||||||
|
"Run 'bw login' to login.")
|
||||||
elif out.startswith("Failed to decrypt."):
|
elif out.startswith("Failed to decrypt."):
|
||||||
raise AnsibleError("Error accessing Bitwarden vault. Make sure BW_SESSION is set properly.")
|
raise AnsibleError("Error accessing Bitwarden vault. "
|
||||||
|
"Make sure BW_SESSION is set properly.")
|
||||||
elif out.startswith("Not found."):
|
elif out.startswith("Not found."):
|
||||||
raise AnsibleError("Error accessing Bitwarden vault. Specified item not found.")
|
raise AnsibleError("Error accessing Bitwarden vault. "
|
||||||
|
"Specified item not found.")
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("Unknown failure in 'bw' command: {0}".format(out))
|
raise AnsibleError("Unknown failure in 'bw' command: "
|
||||||
|
"{0}".format(out))
|
||||||
return out.strip()
|
return out.strip()
|
||||||
|
|
||||||
def get_entry(self, key, field):
|
def get_entry(self, key, field):
|
||||||
|
@ -109,7 +117,9 @@ class LookupModule(LookupBase):
|
||||||
bw = Bitwarden(path=kwargs.get('path', 'bw'))
|
bw = Bitwarden(path=kwargs.get('path', 'bw'))
|
||||||
|
|
||||||
if not bw.logged_in:
|
if not bw.logged_in:
|
||||||
raise AnsibleError("Not logged into Bitwarden: please run 'bw login', or 'bw unlock' and set the BW_SESSION environment variable first")
|
raise AnsibleError("Not logged into Bitwarden: please run "
|
||||||
|
"'bw login', or 'bw unlock' and set the "
|
||||||
|
"BW_SESSION environment variable first")
|
||||||
|
|
||||||
field = kwargs.get('field', 'password')
|
field = kwargs.get('field', 'password')
|
||||||
values = []
|
values = []
|
||||||
|
@ -123,7 +133,8 @@ class LookupModule(LookupBase):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
print("Usage: {0} <field> <name> [name name ...]".format(os.path.basename(__file__)))
|
print("Usage: {0} <field> <name> [name name ...]"
|
||||||
|
.format(os.path.basename(__file__)))
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
print(LookupModule().run(sys.argv[2:], None, field=sys.argv[1]))
|
print(LookupModule().run(sys.argv[2:], None, field=sys.argv[1]))
|
||||||
|
|
Loading…
Reference in a new issue