Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions postgress/1.0.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions postgress/1.0.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# PostgreSQL Shuffle App
This app connects to PostgreSQL and executes queries.
55 changes: 55 additions & 0 deletions postgress/1.0.0/api.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions postgress/1.0.0/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
psycopg2-binary
shuffle-sdk
35 changes: 35 additions & 0 deletions postgress/1.0.0/src/app.py
Original file line number Diff line number Diff line change
@@ -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()
Loading