Going back to using env vars on the entrypoint
This commit is contained in:
parent
18f256ff84
commit
9ca85b6f70
@ -22,12 +22,12 @@ logging.basicConfig(
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
)
|
||||
|
||||
NOW = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
||||
DATABASE_PATH = f"/exports/vaultwarden-{NOW}.kdbx"
|
||||
BW_PATH = "/usr/local/bin/bw"
|
||||
|
||||
kp: Optional[PyKeePass] = None
|
||||
|
||||
NOW = datetime.now().strftime('%Y-%m-%d-%s')
|
||||
DATABASE_PATH = f'/exports/vaultwarden-{NOW}.kdbx'
|
||||
|
||||
|
||||
def bitwarden_to_keepass(args):
|
||||
global kp
|
||||
try:
|
||||
@ -39,12 +39,12 @@ def bitwarden_to_keepass(args):
|
||||
logging.error(f'Wrong password for KeePass database: {e}')
|
||||
return
|
||||
|
||||
folders = subprocess.check_output([BW_PATH, 'list', 'folders', '--session', args.bw_session], encoding='utf8')
|
||||
folders = subprocess.check_output([args.bw_path, 'list', 'folders', '--session', args.bw_session], encoding='utf8')
|
||||
folders = json.loads(folders)
|
||||
groups_by_id = load_folders(folders)
|
||||
logging.info(f'Folders done ({len(groups_by_id)}).')
|
||||
|
||||
items = subprocess.check_output([BW_PATH, 'list', 'items', '--session', args.bw_session], encoding='utf8')
|
||||
items = subprocess.check_output([args.bw_path, 'list', 'items', '--session', args.bw_session], encoding='utf8')
|
||||
items = json.loads(items)
|
||||
logging.info(f'Starting to process {len(items)} items.')
|
||||
for item in items:
|
||||
@ -90,7 +90,7 @@ def bitwarden_to_keepass(args):
|
||||
|
||||
for attachment in bw_item.get_attachments():
|
||||
attachment_raw = subprocess.check_output([
|
||||
BW_PATH, 'get', 'attachment', attachment['id'], '--raw', '--itemid', bw_item.get_id(),
|
||||
args.bw_path, 'get', 'attachment', attachment['id'], '--raw', '--itemid', bw_item.get_id(),
|
||||
'--session', args.bw_session,
|
||||
])
|
||||
attachment_id = kp.add_binary(attachment_raw)
|
||||
@ -171,8 +171,8 @@ def check_args(args):
|
||||
logging.error('Key File for KeePass database is not readable.')
|
||||
return False
|
||||
|
||||
if not os.path.isfile(BW_PATH) or not os.access(BW_PATH, os.X_OK):
|
||||
logging.error('bitwarden-cli was not found or not executable. Make sure bw-cli is installed and in PATH.')
|
||||
if not os.path.isfile(args.bw_path) or not os.access(args.bw_path, os.X_OK):
|
||||
logging.error('bitwarden-cli was not found or not executable. Did you set correct \'--bw-path\'?')
|
||||
return False
|
||||
|
||||
return True
|
||||
@ -201,6 +201,11 @@ parser.add_argument(
|
||||
help='Path to Key File for KeePass database',
|
||||
default=os.environ.get('DATABASE_KEYFILE', None),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--bw-path',
|
||||
help='Path for bw binary',
|
||||
default=os.environ.get('BW_PATH', 'bw'),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
check_args(args) and bitwarden_to_keepass(args)
|
||||
|
@ -1,12 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Login to a VaultWarden instance
|
||||
echo "Connecting to Vaultwarden instance at $VAULTWARDEN_URL"
|
||||
bw config server "$VAULTWARDEN_URL"
|
||||
BW_SESSION="$(bw login --raw)"
|
||||
export BW_SESSION
|
||||
|
||||
bw config server http://192.168.0.186:9998
|
||||
|
||||
export BW_SESSION="$(bw login --raw)"
|
||||
# Set environment variables for the script
|
||||
BW_PATH="$(which bw)"
|
||||
export BW_PATH
|
||||
|
||||
# Convert the VaultWarden data to a KeePass file
|
||||
bw sync
|
||||
|
||||
python3 bitwarden-to-keepass.py
|
||||
|
||||
bw lock
|
||||
|
||||
echo "KeePass file created successfully!"
|
||||
|
Loading…
x
Reference in New Issue
Block a user