From bf386af15d91cfa07b53af2a6a028c23a3e88e51 Mon Sep 17 00:00:00 2001 From: SecEnthusiast76 Date: Fri, 15 May 2026 11:33:42 +0200 Subject: [PATCH] Fixing an issue in the postgress app where Shuffle would not be able to serialize results to JSON as it would see RealDictObject instead. Adding App Authentication support to postgress app. --- postgress/1.0.0/api.yaml | 55 ----------------------- postgress/1.0.0/requirements.txt | 2 - postgress/{1.0.0 => 1.1.0}/Dockerfile | 0 postgress/{1.0.0 => 1.1.0}/README.md | 0 postgress/1.1.0/api.yaml | 64 +++++++++++++++++++++++++++ postgress/1.1.0/requirements.txt | 2 + postgress/{1.0.0 => 1.1.0}/src/app.py | 17 +++---- 7 files changed, 75 insertions(+), 65 deletions(-) delete mode 100644 postgress/1.0.0/api.yaml delete mode 100644 postgress/1.0.0/requirements.txt rename postgress/{1.0.0 => 1.1.0}/Dockerfile (100%) rename postgress/{1.0.0 => 1.1.0}/README.md (100%) create mode 100644 postgress/1.1.0/api.yaml create mode 100644 postgress/1.1.0/requirements.txt rename postgress/{1.0.0 => 1.1.0}/src/app.py (68%) diff --git a/postgress/1.0.0/api.yaml b/postgress/1.0.0/api.yaml deleted file mode 100644 index 26467487..00000000 --- a/postgress/1.0.0/api.yaml +++ /dev/null @@ -1,55 +0,0 @@ -app_version: 1.0.0 -name: postgress -description: postgress integration. Compatible with SQL databases. -contact_info: - name: "@d4rkw0lv3s" - url: https://github.com/D4rkw0lv3s - email: d4rkw0lv3s@outlook.pt -tags: - - postgress -categories: - - Intel - - Network -actions: - - name: run_query - description: Create a new database - parameters: - - name: host - description: mysql server ip or fqdn - example: "myserver.com or 127.0.0.1" - required: true - schema: - type: string - - name: port - description: mysql database - example: "my_database" - required: false - schema: - type: string - - name: dbname - description: mysql database - example: "my_database" - required: false - schema: - type: string - - name: user - description: mysql database - example: "my_database" - required: false - schema: - type: string - - name: password - description: mysql database - example: "my_database" - required: false - schema: - type: string - - name: query - description: mysql database - example: "my_database" - required: false - schema: - type: string - return: - schema: - type: string diff --git a/postgress/1.0.0/requirements.txt b/postgress/1.0.0/requirements.txt deleted file mode 100644 index 78f864b2..00000000 --- a/postgress/1.0.0/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -psycopg2-binary -shuffle-sdk diff --git a/postgress/1.0.0/Dockerfile b/postgress/1.1.0/Dockerfile similarity index 100% rename from postgress/1.0.0/Dockerfile rename to postgress/1.1.0/Dockerfile diff --git a/postgress/1.0.0/README.md b/postgress/1.1.0/README.md similarity index 100% rename from postgress/1.0.0/README.md rename to postgress/1.1.0/README.md diff --git a/postgress/1.1.0/api.yaml b/postgress/1.1.0/api.yaml new file mode 100644 index 00000000..a404d6c0 --- /dev/null +++ b/postgress/1.1.0/api.yaml @@ -0,0 +1,64 @@ +app_version: 1.1.0 +name: postgress +description: postgress integration. Compatible with SQL databases. +contact_info: + name: "@d4rkw0lv3s" + url: https://github.com/D4rkw0lv3s + email: d4rkw0lv3s@outlook.pt +tags: + - postgress + - postgresql +categories: + - Intel + - Network +authentication: + required: true + parameters: + - name: host + description: PostgreSQL server IP or FQDN + example: myserver.com or 127.0.0.1 + required: true + multiline: false + schema: + type: string + - name: port + description: PostgreSQL database port + example: "5432" + required: false + multiline: false + schema: + type: string + - name: dbname + description: PostgreSQL database name + example: my_database + required: true + multiline: false + schema: + type: string + - name: user + description: PostgreSQL user name + example: my_username + required: true + multiline: false + schema: + type: string + - name: password + description: PostgreSQL user password + example: my_password + required: true + multiline: false + schema: + type: string +actions: + - name: run_query + description: Create a new database + parameters: + - name: query + description: PostgreSQL query + example: SELECT 1 + required: true + schema: + type: string + return: + schema: + type: string diff --git a/postgress/1.1.0/requirements.txt b/postgress/1.1.0/requirements.txt new file mode 100644 index 00000000..91f18f26 --- /dev/null +++ b/postgress/1.1.0/requirements.txt @@ -0,0 +1,2 @@ +psycopg2-binary == 2.9.12 +shuffle-sdk >= 0.0.31 diff --git a/postgress/1.0.0/src/app.py b/postgress/1.1.0/src/app.py similarity index 68% rename from postgress/1.0.0/src/app.py rename to postgress/1.1.0/src/app.py index 3c973e49..8f3f43c2 100644 --- a/postgress/1.0.0/src/app.py +++ b/postgress/1.1.0/src/app.py @@ -1,18 +1,18 @@ -import psycopg2 +from psycopg2 import connect, ProgrammingError from psycopg2.extras import RealDictCursor -#from walkoff_app_sdk.app_base import AppBase from shuffle_sdk import AppBase class PostgreSQL(AppBase): - __version__ = "1.0.0" + __version__ = "1.1.0" app_name = "PostgreSQL" def __init__(self, redis, logger, console_logger=None): super().__init__(redis, logger, console_logger) - def connect(self, host, port, dbname, user, password): - conn = psycopg2.connect( + @staticmethod + def connect(host, port, dbname, user, password): + conn = connect( host=host, port=port, dbname=dbname, @@ -24,12 +24,13 @@ def connect(self, host, port, dbname, user, password): def run_query(self, host, port, dbname, user, password, query): with self.connect(host, port, dbname, user, password) as conn: - with conn.cursor() as cur: + with conn.cursor(cursor_factory=RealDictCursor) as cur: cur.execute(query) try: - return {"result": cur.fetchall()} - except psycopg2.ProgrammingError: + return {"result": [dict(row) for row in cur.fetchall() if row]} + except ProgrammingError: return {"message": "Query executed successfully, no data returned."} + if __name__ == "__main__": PostgreSQL.run()