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 18:16:55 +00:00
|
|
|
import os
|
2022-09-10 12:55:53 +00:00
|
|
|
|
2022-09-10 18:16:55 +00:00
|
|
|
def get_secret_from_bitwarden(type, id):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@kopf.on.startup()
|
|
|
|
def bitwarden_signin(logger, **kwargs):
|
|
|
|
if 'BW_HOST' in os.environ:
|
|
|
|
output = os.popen(f"bw config server {os.getenv('BW_HOST')}")
|
|
|
|
else:
|
|
|
|
logger.info(f"BW_HOST not set. Assuming SaaS installation")
|
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 18:16:55 +00:00
|
|
|
annotations = {
|
|
|
|
"managed": "bitwarden-secrets.lerentis.uploadfilter24.eu",
|
|
|
|
"managedObject": name
|
|
|
|
}
|
|
|
|
secret = kubernetes.client.V1Secret()
|
|
|
|
secret.metadata = kubernetes.client.V1ObjectMeta(name=secret_name, annotations=annotations)
|
|
|
|
secret.type = "Opaque"
|
|
|
|
secret.data = {
|
|
|
|
'username': str(base64.b64encode("test".encode("utf-8")), "utf-8"),
|
|
|
|
'password': str(base64.b64encode("test".encode("utf-8")), "utf-8")
|
2022-09-10 17:34:07 +00:00
|
|
|
}
|
2022-09-10 12:55:53 +00:00
|
|
|
|
|
|
|
obj = api.create_namespaced_secret(
|
2022-09-10 18:16:55 +00:00
|
|
|
secret_namespace, secret
|
2022-09-10 12:55:53 +00:00
|
|
|
)
|
|
|
|
|
2022-09-10 18:16:55 +00:00
|
|
|
logger.info(f"Secret {secret_namespace}/{secret_name} is created")
|
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')
|
2022-09-10 18:16:55 +00:00
|
|
|
def my_handler(spec, name, namespace, logger, **kwargs):
|
2022-09-10 12:55:53 +00:00
|
|
|
pass
|