free-key-value-definition #1

Merged
lerentis merged 3 commits from feature/free-key-value-definition into main 2022-10-03 14:00:12 +00:00
Showing only changes of commit fb33e28cd7 - Show all commits

View File

@ -6,6 +6,8 @@ import os
import subprocess
import json
from pprint import pprint
def get_secret_from_bitwarden(logger, id):
return command_wrapper(logger, f"get item {id}")
@ -33,15 +35,12 @@ def bitwarden_signin(logger, **kwargs):
unlock_bw(logger)
@kopf.on.create('bitwarden-secrets.lerentis.uploadfilter24.eu')
def create_fn(spec, name, namespace, logger, **kwargs):
def create_fn(spec, name, namespace, logger, body, **kwargs):
logger.info(f"Type of spec: {type(body)}")
scope = body['spec']['scope']
logger.info(f"spec: {scope}")
scope = spec.get('scope')
items = []
for index in range(len(scope)):
for element in scope[index]:
logger.info(f"Type: {type(element)}")
for test in element:
logger.info(f"Key: {test}")
id = spec.get('id')
@ -61,10 +60,13 @@ def create_fn(spec, name, namespace, logger, **kwargs):
secret = kubernetes.client.V1Secret()
secret.metadata = kubernetes.client.V1ObjectMeta(name=secret_name, annotations=annotations)
secret.type = "Opaque"
secret.data = {
'username': str(base64.b64encode(secret_json_object["login"]["username"].encode("utf-8")), "utf-8"),
'password': str(base64.b64encode(secret_json_object["login"]["password"].encode("utf-8")), "utf-8")
}
secret.data = {}
for elemw in scope:
for k, elem in elemw.items():
for key,value in elem.items():
logger.info(f"key: {key} value: {value}")
secret.data["username"] = str(base64.b64encode(secret_json_object["login"]["username"].encode("utf-8")), "utf-8")
secret.data["password"] = str(base64.b64encode(secret_json_object["login"]["password"].encode("utf-8")), "utf-8")
obj = api.create_namespaced_secret(
secret_namespace, secret