diff options
author | Rasmus Luha <rasmus.luha@ut.ee> | 2025-04-23 01:15:49 +0300 |
---|---|---|
committer | Rasmus Luha <rasmus.luha@ut.ee> | 2025-04-23 01:15:49 +0300 |
commit | 1d41a08fe30bbb5b8a4cea7db14740109960b467 (patch) | |
tree | 389690c31478e687acf8e1294b7930d13f74822f | |
parent | 003351a014acbe7f56b23806f8068502f25d8b8f (diff) |
Nifi stuff WORKS!
-rw-r--r-- | modules/nifi/core.py | 7 | ||||
-rw-r--r-- | testing.py | 89 |
2 files changed, 2 insertions, 94 deletions
diff --git a/modules/nifi/core.py b/modules/nifi/core.py index be3cc1f..24489e4 100644 --- a/modules/nifi/core.py +++ b/modules/nifi/core.py @@ -136,9 +136,7 @@ def modify_all_processors(data_values, schedulingPeriod, new_pipeline_name, api_ if needs_SplitJson: ## SplitJson update split_json_path = "$"+re.sub(r'\[(.*?)\]', r'[*]', path_parts[0]) - print("Got here") update_template(new_pipeline_path, "flowContents.processors[3].properties", "JsonPath Expression", split_json_path) - print("Got also here") ## EvaluateJsonPath processor setup for key, value in data_values.items() : @@ -168,9 +166,8 @@ def modify_all_processors(data_values, schedulingPeriod, new_pipeline_name, api_ ## Add api credentials if api_username != "placeholder": - update_template(new_pipeline_path, "flowContents.processors[1]", "Request Username", api_username) - #update_template(new_pipeline_path, "flowContents.processors[1]", "Request Password", api_password) - #update_template(new_pipeline_path, "flowContents.processors[1]", "Request Password", base64.b64encode(api_password.encode()).decode()) + update_template(new_pipeline_path, "flowContents.processors[1].properties", "Request Username", api_username) + update_template(new_pipeline_path, "flowContents.processors[1].properties", "Request Password", api_password) diff --git a/testing.py b/testing.py deleted file mode 100644 index 4ace0e5..0000000 --- a/testing.py +++ /dev/null @@ -1,89 +0,0 @@ -import config as config - -import requests -import json - -# Configuration -PLAINTEXT_PW = "TODO" -INPUT_TEMPLATE = "template.json" -OUTPUT_FILE = "configured-flow.json" - -# API Endpoints -BASE_URL = f"{config.NIFI_HOST}/nifi-api" -LOGIN_URL = f"{BASE_URL}/access/token" -ENCRYPT_URL = f"{BASE_URL}/flow/encrypt-text" - -def get_access_token(): - """Authenticate with NiFi and get JWT token""" - try: - response = requests.post( - LOGIN_URL, - headers={"Content-Type": "application/x-www-form-urlencoded"}, - data=f"username={config.NIFI_USER}&password={config.NIFI_PASS}", - verify=False # For self-signed certificates - ) - response.raise_for_status() - return response.text - except requests.exceptions.RequestException as e: - print(f"Authentication failed: {str(e)}") - exit(1) - -def encrypt_password(token, plaintext): - """Encryptpassword using NiFi's API""" - try: - response = requests.post( - ENCRYPT_URL, - headers={ - "Content-Type": "application/x-www-form-urlencoded", - "Authorization": f"Bearer {token}" - }, - data=f"value={plaintext}", - verify=False - ) - response.raise_for_status() - return response.json()["value"] - except requests.exceptions.RequestException as e: - print(f"Encryption failed: {str(e)}") - exit(1) - - - - - - - - - -def update_template(encrypted_pw): - """Update JSON template with encrypted password""" - try: - with open(INPUT_TEMPLATE, "r") as f: - flow = json.load(f) - - # Find and update InvokeHTTP processor - for processor in flow["flowContents"]["processors"]: - if processor["type"] == "org.apache.nifi.processors.standard.InvokeHTTP": - # Update password property - processor["properties"]["Request password"] = encrypted_pw - # Mark property as sensitive - processor["propertyDescriptors"]["Request password"]["sensitive"] = True - - with open(OUTPUT_FILE, "w") as f: - json.dump(flow, f, indent=2) - - print(f"Successfully generated: {OUTPUT_FILE}") - except Exception as e: - print(f"Template update failed: {str(e)}") - exit(1) - -if __name__ == "__main__": - # 1. Authenticate - token = get_access_token() - - print("token part DONE") - - # 2. Encrypt config.NIFI_PASS - encrypt_password(token, PLAINTEXT_PW) - - # 3. Update template - #update_template(encrypted_config.NIFI_PASS) |