diff --git a/postgress/1.0.0/Dockerfile b/postgress/1.0.0/Dockerfile new file mode 100644 index 00000000..41f976bb --- /dev/null +++ b/postgress/1.0.0/Dockerfile @@ -0,0 +1,27 @@ +# Base our app image off of the WALKOFF App SDK image +FROM frikky/shuffle:app_sdk as base + +# We're going to stage away all of the bloat from the build tools so lets create a builder stage +FROM base as builder + +# Install all alpine build tools needed for our pip installs +RUN apk --no-cache add --update alpine-sdk libffi libffi-dev musl-dev openssl-dev + +# Install all of our pip packages in a single directory that we can copy to our base image later +RUN mkdir /install +WORKDIR /install +COPY requirements.txt /requirements.txt +RUN pip install --prefix="/install" -r /requirements.txt + +# Switch back to our base image and copy in all of our built packages and source code +FROM base +COPY --from=builder /install /usr/local +COPY src /app + +# Install any binary dependencies needed in our final image +# RUN apk --no-cache add --update my_binary_dependency + + +# Finally, lets run our app! +WORKDIR /app +CMD python app.py --log-level DEBUG diff --git a/postgress/1.0.0/README.md b/postgress/1.0.0/README.md new file mode 100644 index 00000000..12b051c2 --- /dev/null +++ b/postgress/1.0.0/README.md @@ -0,0 +1,2 @@ +# PostgreSQL Shuffle App +This app connects to PostgreSQL and executes queries. diff --git a/postgress/1.0.0/api.yaml b/postgress/1.0.0/api.yaml new file mode 100644 index 00000000..26467487 --- /dev/null +++ b/postgress/1.0.0/api.yaml @@ -0,0 +1,55 @@ +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 new file mode 100644 index 00000000..78f864b2 --- /dev/null +++ b/postgress/1.0.0/requirements.txt @@ -0,0 +1,2 @@ +psycopg2-binary +shuffle-sdk diff --git a/postgress/1.0.0/src/app.py b/postgress/1.0.0/src/app.py new file mode 100644 index 00000000..3c973e49 --- /dev/null +++ b/postgress/1.0.0/src/app.py @@ -0,0 +1,35 @@ +import psycopg2 +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" + 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( + host=host, + port=port, + dbname=dbname, + user=user, + password=password, + cursor_factory=RealDictCursor + ) + return conn + + 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: + cur.execute(query) + try: + return {"result": cur.fetchall()} + except psycopg2.ProgrammingError: + return {"message": "Query executed successfully, no data returned."} + +if __name__ == "__main__": + PostgreSQL.run()