2022-09-04 21:21:33 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import kopf
|
2022-09-10 12:55:53 +00:00
|
|
|
import kubernetes
|
2022-09-10 13:23:53 +00:00
|
|
|
import base64
|
2022-09-10 13:07:34 +00:00
|
|
|
from jinja2 import Template
|
2022-09-10 12:55:53 +00:00
|
|
|
|
2022-09-04 21:21:33 +00:00
|
|
|
|
2022-09-09 21:41:06 +00:00
|
|
|
@kopf.on.create('bitwarden-secrets.lerentis.uploadfilter24.eu')
|
2022-09-10 12:55:53 +00:00
|
|
|
def create_fn(spec, name, namespace, logger, **kwargs):
|
|
|
|
|
|
|
|
type = spec.get('type')
|
|
|
|
id = spec.get('id')
|
|
|
|
secret_name = spec.get('name')
|
|
|
|
secret_namespace = spec.get('namespace')
|
|
|
|
|
|
|
|
api = kubernetes.client.CoreV1Api()
|
|
|
|
|
2022-09-10 13:18:47 +00:00
|
|
|
# TODO: this should better be a os lookup
|
|
|
|
with open('/home/bw-operator/templates/username-password.yaml.j2') as file_:
|
2022-09-10 13:07:34 +00:00
|
|
|
template = Template(file_.read())
|
2022-09-10 12:55:53 +00:00
|
|
|
|
|
|
|
data = template.render(
|
|
|
|
original_crd=name,
|
|
|
|
secret_name=secret_name,
|
|
|
|
namespace=secret_namespace,
|
2022-09-10 13:23:53 +00:00
|
|
|
username=base64.b64encode("test"),
|
|
|
|
password=base64.b64encode("test")
|
2022-09-10 12:55:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
obj = api.create_namespaced_secret(
|
|
|
|
namespace=secret_namespace,
|
|
|
|
body=data
|
|
|
|
)
|
|
|
|
|
|
|
|
logger.info(f"Secret {name} is created: {obj}")
|
2022-09-04 21:21:33 +00:00
|
|
|
|
|
|
|
|
2022-09-10 12:55:53 +00:00
|
|
|
@kopf.on.update('bitwarden-secrets.lerentis.uploadfilter24.eu')
|
|
|
|
def my_handler(spec, old, new, diff, **_):
|
|
|
|
pass
|
2022-09-04 21:21:33 +00:00
|
|
|
|
2022-09-10 12:55:53 +00:00
|
|
|
@kopf.on.delete('bitwarden-secrets.lerentis.uploadfilter24.eu')
|
|
|
|
def my_handler(spec, **_):
|
|
|
|
pass
|