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',
|
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
|
kp: Optional[PyKeePass] = None
|
||||||
|
|
||||||
|
NOW = datetime.now().strftime('%Y-%m-%d-%s')
|
||||||
|
DATABASE_PATH = f'/exports/vaultwarden-{NOW}.kdbx'
|
||||||
|
|
||||||
|
|
||||||
def bitwarden_to_keepass(args):
|
def bitwarden_to_keepass(args):
|
||||||
global kp
|
global kp
|
||||||
try:
|
try:
|
||||||
@ -39,12 +39,12 @@ def bitwarden_to_keepass(args):
|
|||||||
logging.error(f'Wrong password for KeePass database: {e}')
|
logging.error(f'Wrong password for KeePass database: {e}')
|
||||||
return
|
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)
|
folders = json.loads(folders)
|
||||||
groups_by_id = load_folders(folders)
|
groups_by_id = load_folders(folders)
|
||||||
logging.info(f'Folders done ({len(groups_by_id)}).')
|
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)
|
items = json.loads(items)
|
||||||
logging.info(f'Starting to process {len(items)} items.')
|
logging.info(f'Starting to process {len(items)} items.')
|
||||||
for item in items:
|
for item in items:
|
||||||
@ -90,7 +90,7 @@ def bitwarden_to_keepass(args):
|
|||||||
|
|
||||||
for attachment in bw_item.get_attachments():
|
for attachment in bw_item.get_attachments():
|
||||||
attachment_raw = subprocess.check_output([
|
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,
|
'--session', args.bw_session,
|
||||||
])
|
])
|
||||||
attachment_id = kp.add_binary(attachment_raw)
|
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.')
|
logging.error('Key File for KeePass database is not readable.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not os.path.isfile(BW_PATH) or not os.access(BW_PATH, os.X_OK):
|
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. Make sure bw-cli is installed and in PATH.')
|
logging.error('bitwarden-cli was not found or not executable. Did you set correct \'--bw-path\'?')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -201,6 +201,11 @@ parser.add_argument(
|
|||||||
help='Path to Key File for KeePass database',
|
help='Path to Key File for KeePass database',
|
||||||
default=os.environ.get('DATABASE_KEYFILE', None),
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
check_args(args) and bitwarden_to_keepass(args)
|
check_args(args) and bitwarden_to_keepass(args)
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
#!/bin/sh
|
#!/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
|
# Set environment variables for the script
|
||||||
|
BW_PATH="$(which bw)"
|
||||||
export BW_SESSION="$(bw login --raw)"
|
export BW_PATH
|
||||||
|
|
||||||
|
# Convert the VaultWarden data to a KeePass file
|
||||||
bw sync
|
bw sync
|
||||||
|
|
||||||
python3 bitwarden-to-keepass.py
|
python3 bitwarden-to-keepass.py
|
||||||
|
|
||||||
bw lock
|
bw lock
|
||||||
|
|
||||||
|
echo "KeePass file created successfully!"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user