diff --git a/docker-compose.yml b/docker-compose.yml index c87131806ed11e69728a904bd75b473ccb859dde..5107772bdc2591746f967e60f2c9deb08b7f092c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -546,7 +546,7 @@ services: condition: service_healthy environment: LOG_LEVEL: "${LOG_LEVEL}" - TOPIC: thing_creation + TOPIC: configdb_update MQTT_BROKER: mqtt-broker:1883 MQTT_USER: "${MQTT_USER}" MQTT_PASSWORD: "${MQTT_PASSWORD}" @@ -560,6 +560,12 @@ services: DB_API_BASE_URL: "${DB_API_BASE_URL}" JOURNALING: "${JOURNALING}" FERNET_ENCRYPTION_SECRET: "${FERNET_ENCRYPTION_SECRET}" + CONFIGDB_DSN: "postgresql://\ + ${CONFIGDB_USER}:\ + ${CONFIGDB_PASSWORD}@\ + ${CONFIGDB_HOST}:\ + ${CONFIGDB_PORT}/\ + ${CONFIGDB_DB}" entrypoint: ["python3", "setup_minio.py"] diff --git a/src/setup_minio.py b/src/setup_minio.py index f13c338bc1a62fcc408b978890f358c40bd1bbe8..6ef3d565b4804ca28d7b014433aeda9f2d6a78c2 100755 --- a/src/setup_minio.py +++ b/src/setup_minio.py @@ -5,9 +5,10 @@ import logging from minio_cli_wrapper.mc import Mc from timeio.mqtt import AbstractHandler, MQTTMessage -from timeio.thing import Thing +from timeio.feta import Thing from timeio.common import get_envvar, setup_logging from timeio.crypto import decrypt, get_crypt_key +from timeio.typehints import MqttPayload logger = logging.getLogger("minio-setup") @@ -30,9 +31,10 @@ class CreateThingInMinioHandler(AbstractHandler): secret_key=get_envvar("MINIO_SECURE_KEY"), secure=get_envvar("MINIO_SECURE", default=True, cast_to=bool), ) + self.configdb_dsn = get_envvar("CONFIGDB_DSN") - def act(self, content: dict, message: MQTTMessage): - thing = Thing.get_instance(content) + def act(self, content: MqttPayload.ConfigDBUpdate, message: MQTTMessage): + thing = Thing.from_uuid(content["thing"], dsn=self.configdb_dsn) user = thing.raw_data_storage.username passw = decrypt(thing.raw_data_storage.password, get_crypt_key()) bucket = thing.raw_data_storage.bucket_name