Skip to content

Commit dcbbefa

Browse files
authored
Merge pull request #425 from yashsinghcodes/newapp
new postgress python app
2 parents 192d496 + b2534fa commit dcbbefa

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

postgress/1.0.0/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Base our app image off of the WALKOFF App SDK image
2+
FROM frikky/shuffle:app_sdk as base
3+
4+
# We're going to stage away all of the bloat from the build tools so lets create a builder stage
5+
FROM base as builder
6+
7+
# Install all alpine build tools needed for our pip installs
8+
RUN apk --no-cache add --update alpine-sdk libffi libffi-dev musl-dev openssl-dev
9+
10+
# Install all of our pip packages in a single directory that we can copy to our base image later
11+
RUN mkdir /install
12+
WORKDIR /install
13+
COPY requirements.txt /requirements.txt
14+
RUN pip install --prefix="/install" -r /requirements.txt
15+
16+
# Switch back to our base image and copy in all of our built packages and source code
17+
FROM base
18+
COPY --from=builder /install /usr/local
19+
COPY src /app
20+
21+
# Install any binary dependencies needed in our final image
22+
# RUN apk --no-cache add --update my_binary_dependency
23+
24+
25+
# Finally, lets run our app!
26+
WORKDIR /app
27+
CMD python app.py --log-level DEBUG

postgress/1.0.0/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# PostgreSQL Shuffle App
2+
This app connects to PostgreSQL and executes queries.

postgress/1.0.0/api.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
app_version: 1.0.0
2+
name: postgress
3+
description: postgress integration. Compatible with SQL databases.
4+
contact_info:
5+
name: "@d4rkw0lv3s"
6+
url: https://github.com/D4rkw0lv3s
7+
email: d4rkw0lv3s@outlook.pt
8+
tags:
9+
- postgress
10+
categories:
11+
- Intel
12+
- Network
13+
actions:
14+
- name: run_query
15+
description: Create a new database
16+
parameters:
17+
- name: host
18+
description: mysql server ip or fqdn
19+
example: "myserver.com or 127.0.0.1"
20+
required: true
21+
schema:
22+
type: string
23+
- name: port
24+
description: mysql database
25+
example: "my_database"
26+
required: false
27+
schema:
28+
type: string
29+
- name: dbname
30+
description: mysql database
31+
example: "my_database"
32+
required: false
33+
schema:
34+
type: string
35+
- name: user
36+
description: mysql database
37+
example: "my_database"
38+
required: false
39+
schema:
40+
type: string
41+
- name: password
42+
description: mysql database
43+
example: "my_database"
44+
required: false
45+
schema:
46+
type: string
47+
- name: query
48+
description: mysql database
49+
example: "my_database"
50+
required: false
51+
schema:
52+
type: string
53+
return:
54+
schema:
55+
type: string

postgress/1.0.0/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
psycopg2-binary
2+
shuffle-sdk

postgress/1.0.0/src/app.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import psycopg2
2+
from psycopg2.extras import RealDictCursor
3+
#from walkoff_app_sdk.app_base import AppBase
4+
from shuffle_sdk import AppBase
5+
6+
7+
class PostgreSQL(AppBase):
8+
__version__ = "1.0.0"
9+
app_name = "PostgreSQL"
10+
11+
def __init__(self, redis, logger, console_logger=None):
12+
super().__init__(redis, logger, console_logger)
13+
14+
def connect(self, host, port, dbname, user, password):
15+
conn = psycopg2.connect(
16+
host=host,
17+
port=port,
18+
dbname=dbname,
19+
user=user,
20+
password=password,
21+
cursor_factory=RealDictCursor
22+
)
23+
return conn
24+
25+
def run_query(self, host, port, dbname, user, password, query):
26+
with self.connect(host, port, dbname, user, password) as conn:
27+
with conn.cursor() as cur:
28+
cur.execute(query)
29+
try:
30+
return {"result": cur.fetchall()}
31+
except psycopg2.ProgrammingError:
32+
return {"message": "Query executed successfully, no data returned."}
33+
34+
if __name__ == "__main__":
35+
PostgreSQL.run()

0 commit comments

Comments
 (0)