2022-11-12 22:57:42 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
2023-04-21 12:39:06 +00:00
|
|
|
import kopf
|
2022-11-12 22:57:42 +00:00
|
|
|
|
2022-11-26 12:49:57 +00:00
|
|
|
from utils.utils import command_wrapper, unlock_bw
|
2022-11-12 22:57:42 +00:00
|
|
|
|
2023-04-21 12:39:06 +00:00
|
|
|
|
2022-11-12 22:57:42 +00:00
|
|
|
@kopf.on.startup()
|
|
|
|
def bitwarden_signin(logger, **kwargs):
|
|
|
|
if 'BW_HOST' in os.environ:
|
2022-11-26 20:33:31 +00:00
|
|
|
try:
|
|
|
|
command_wrapper(f"config server {os.getenv('BW_HOST')}")
|
2023-04-21 12:39:06 +00:00
|
|
|
except BaseException:
|
2022-11-26 20:33:31 +00:00
|
|
|
logger.warn("Revieved none zero exit code from server config")
|
|
|
|
logger.warn("This is expected from startup")
|
|
|
|
pass
|
2022-11-12 22:57:42 +00:00
|
|
|
else:
|
2023-04-21 12:39:06 +00:00
|
|
|
logger.info("BW_HOST not set. Assuming SaaS installation")
|
2022-11-26 20:33:31 +00:00
|
|
|
command_wrapper("login --apikey")
|
2022-11-12 22:57:42 +00:00
|
|
|
unlock_bw(logger)
|