work in progress to support raw template types
This commit is contained in:
@ -1,26 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
import kopf
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def get_secret_from_bitwarden(logger, id):
|
||||
logger.info(f"Locking up secret with ID: {id}")
|
||||
return command_wrapper(logger, f"get item {id}")
|
||||
|
||||
def unlock_bw(logger):
|
||||
token_output = command_wrapper(logger, "unlock --passwordenv BW_PASSWORD")
|
||||
tokens = token_output.split('"')[1::2]
|
||||
os.environ["BW_SESSION"] = tokens[1]
|
||||
logger.info("Signin successful. Session exported")
|
||||
|
||||
def command_wrapper(logger, command):
|
||||
system_env = dict(os.environ)
|
||||
sp = subprocess.Popen([f"bw {command}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True, env=system_env)
|
||||
out, err = sp.communicate()
|
||||
if err:
|
||||
logger.warn(f"Error during bw cli invokement: {err}")
|
||||
return out.decode(encoding='UTF-8')
|
||||
|
||||
from utils.utils import command_wrapper, unlock_bw
|
||||
|
||||
@kopf.on.startup()
|
||||
def bitwarden_signin(logger, **kwargs):
|
||||
|
@ -3,7 +3,7 @@ import kubernetes
|
||||
import base64
|
||||
import json
|
||||
|
||||
from bitwardenCrdOperator import unlock_bw, get_secret_from_bitwarden
|
||||
from utils.utils import unlock_bw, get_secret_from_bitwarden
|
||||
|
||||
def create_dockerlogin(logger, secret, secret_json, username_ref, password_ref, registry):
|
||||
secret.type = "dockerconfigjson"
|
||||
|
0
src/filters/__init__.py
Normal file
0
src/filters/__init__.py
Normal file
8
src/filters/bitwarden_filter.py
Normal file
8
src/filters/bitwarden_filter.py
Normal file
@ -0,0 +1,8 @@
|
||||
from utils.utils import get_secret_from_bitwarden
|
||||
|
||||
|
||||
def datetime_format(value, format="%H:%M %d-%m-%y"):
|
||||
return value.strftime(format)
|
||||
|
||||
def bitwarden_lookup(value, id, field):
|
||||
pass
|
@ -3,7 +3,7 @@ import kubernetes
|
||||
import base64
|
||||
import json
|
||||
|
||||
from bitwardenCrdOperator import unlock_bw, get_secret_from_bitwarden
|
||||
from utils.utils import unlock_bw, get_secret_from_bitwarden
|
||||
|
||||
def create_kv(secret, secret_json, content_def):
|
||||
secret.type = "Opaque"
|
||||
|
7
src/template.py
Normal file
7
src/template.py
Normal file
@ -0,0 +1,7 @@
|
||||
import kopf
|
||||
from filters.bitwarden_filter import bitwarden_lookup
|
||||
from jinja2 import Environment
|
||||
|
||||
|
||||
Environment.filters["bitwarden"] = bitwarden_lookup
|
||||
|
0
src/utils/__init__.py
Normal file
0
src/utils/__init__.py
Normal file
20
src/utils/utils.py
Normal file
20
src/utils/utils.py
Normal file
@ -0,0 +1,20 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def get_secret_from_bitwarden(logger, id):
|
||||
logger.info(f"Locking up secret with ID: {id}")
|
||||
return command_wrapper(logger, f"get item {id}")
|
||||
|
||||
def unlock_bw(logger):
|
||||
token_output = command_wrapper(logger, "unlock --passwordenv BW_PASSWORD")
|
||||
tokens = token_output.split('"')[1::2]
|
||||
os.environ["BW_SESSION"] = tokens[1]
|
||||
logger.info("Signin successful. Session exported")
|
||||
|
||||
def command_wrapper(logger, command):
|
||||
system_env = dict(os.environ)
|
||||
sp = subprocess.Popen([f"bw {command}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True, env=system_env)
|
||||
out, err = sp.communicate()
|
||||
if err:
|
||||
logger.warn(f"Error during bw cli invokement: {err}")
|
||||
return out.decode(encoding='UTF-8')
|
Reference in New Issue
Block a user