summaryrefslogtreecommitdiff
path: root/modules/nifi/nifi_utils.py
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@ut.ee>2025-04-25 21:43:54 +0300
committerRasmus Luha <rasmus.luha@ut.ee>2025-04-25 21:43:54 +0300
commit0a16e0e3e586456cf2e86dbdad4b66787b036a5d (patch)
tree7e82621e2d06d84801598b195fe3150140431d94 /modules/nifi/nifi_utils.py
parent9ba62c9bf9f19053f6eb664db70eb342812efc38 (diff)
some restructuring, start telegraf module
Diffstat (limited to 'modules/nifi/nifi_utils.py')
-rw-r--r--modules/nifi/nifi_utils.py45
1 files changed, 44 insertions, 1 deletions
diff --git a/modules/nifi/nifi_utils.py b/modules/nifi/nifi_utils.py
index 88953d6..74cba81 100644
--- a/modules/nifi/nifi_utils.py
+++ b/modules/nifi/nifi_utils.py
@@ -1,6 +1,49 @@
-import requests
import config
+import requests
+import sys
+import json
+
+
+def update_template(file_path, dot_path, new_key, new_value):
+
+ # Step 2: Load the copied JSON
+ with open(file_path, "r") as f:
+ data = json.load(f)
+
+ # Step 3: Walk the path (e.g. 'flowContents.processors[0].properties')
+ keys = dot_path.split(".")
+ current = data
+
+ for key in keys:
+ if key.endswith("]"): # Handle list index like processors[0]
+ list_key = key[:key.index("[")]
+ index = int(key[key.index("[") + 1 : key.index("]")])
+ current = current[list_key][index]
+ else:
+ current = current[key]
+
+ # Step 4: Add or update the key
+ current[new_key] = new_value
+ print(f"🛠 Added '{new_key}': '{new_value}' at path '{dot_path}'")
+
+ # Step 5: Save back the JSON
+ with open(file_path, "w") as f:
+ json.dump(data, f, indent=2)
+ print("✅ Changes saved.")
+
+def set_database_credentials(file_path,dot_path):
+ ## Update URL
+ update_template(file_path, dot_path, "HTTP URL", config.DB_URL)
+
+ ## Update username
+ update_template(file_path, dot_path, "username", config.DB_USER)
+
+ ## Update username
+ update_template(file_path, dot_path, "password", config.DB_PASS)
+
+
+
# export TOKEN=$(curl -k -X POST https://127.0.0.1.nip.io/nifi-api/access/token\