-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Sawyers
committed
Dec 25, 2018
0 parents
commit 259c69a
Showing
23 changed files
with
765 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Created by .ignore support plugin (hsz.mobi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM jfloff/alpine-python | ||
LABEL Description="Docker container for standing up a pyramid web app to bridge Smartthings events to a rethinkDB" Maintainer="Andrew Sawyers <[email protected]>" | ||
SHELL ["/bin/bash", "-c"] | ||
|
||
# We copy this file first to leverage docker cache | ||
COPY src /app/ | ||
|
||
WORKDIR /app | ||
|
||
RUN pip install -U pip && \ | ||
pip install -r requirements.txt && \ | ||
python setup.py install | ||
|
||
ENTRYPOINT [ "pserve" ] | ||
|
||
CMD [ "/app/production.ini" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package: pyramidbridge | ||
environment: dev | ||
handlers: | ||
date: | ||
arrow_format: "YYYY/MM/DD" | ||
default_format: "YYYY/MM/DD" | ||
query_format: "YYYY-MM-DD" | ||
datetime: | ||
arrow_format: "YYYY/MM/DD HH:mm:ss" | ||
default_format: "%%Y/%%m/%%d %%H:%%M:%%S" | ||
logging: | ||
name: pyramidbridge | ||
level: DEBUG | ||
rethinkdb: | ||
host: rethinkdb | ||
port: 28015 | ||
smartthings: | ||
db: smartthings | ||
events: | ||
table: events | ||
subscribe: | ||
table: subscriptions | ||
user: pyre | ||
password: f1r3st0rm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
testpaths = pyramidbridge | ||
python_files = *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CHANGES | ||
|
||
0.2.0 | ||
---- | ||
- add subscribe route for supporting sending messages back to smartthings | ||
|
||
0.1.0 | ||
---- | ||
- initial pyramid app for briding smartthigns events to the rethinkDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include *.txt *.ini *.cfg *.rst *.yml | ||
recursive-include pyramidbridge *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2 *.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A Smartthings event messaging bridge to RethinkDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
### | ||
# app configuration | ||
# https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/environment.html | ||
### | ||
|
||
[app:main] | ||
use = egg:pyramidbridge | ||
|
||
pyramid.reload_templates = true | ||
pyramid.debug_authorization = false | ||
pyramid.debug_notfound = false | ||
pyramid.debug_routematch = false | ||
pyramid.default_locale_name = en | ||
pyramid.includes = | ||
pyramid_chameleon | ||
pyramid_debugtoolbar | ||
|
||
# By default, the toolbar only appears for clients from IP addresses | ||
# '127.0.0.1' and '::1'. | ||
# debugtoolbar.hosts = 127.0.0.1 ::1 | ||
|
||
### | ||
# wsgi server configuration | ||
### | ||
|
||
[server:main] | ||
use = egg:waitress#main | ||
listen = 0.0.0.0:6543 | ||
|
||
### | ||
# logging configuration | ||
# https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/logging.html | ||
### | ||
|
||
[loggers] | ||
keys = root, pyramidbridge | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = INFO | ||
handlers = console | ||
|
||
[logger_pyramidbridge] | ||
level = DEBUG | ||
handlers = | ||
qualname = pyramidbridge | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
### | ||
# app configuration | ||
# https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/environment.html | ||
### | ||
|
||
[app:main] | ||
use = egg:pyramidbridge | ||
|
||
pyramid.reload_templates = false | ||
pyramid.debug_authorization = false | ||
pyramid.debug_notfound = false | ||
pyramid.debug_routematch = false | ||
pyramid.default_locale_name = en | ||
|
||
### | ||
# wsgi server configuration | ||
### | ||
|
||
[server:main] | ||
use = egg:waitress#main | ||
listen = *:6543 | ||
|
||
### | ||
# logging configuration | ||
# https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/logging.html | ||
### | ||
|
||
[loggers] | ||
keys = root, pyramidbridge | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
|
||
[logger_pyramidbridge] | ||
level = INFO | ||
handlers = console | ||
qualname = pyramidbridge | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stdout,) | ||
level = DEBUG | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pyramid.config import Configurator | ||
|
||
|
||
def main(global_config, **settings): | ||
""" This function returns a Pyramid WSGI application. | ||
""" | ||
config = Configurator(settings=settings) | ||
config.include('pyramid_chameleon') | ||
|
||
config.add_static_view('static', 'static', cache_max_age=3600) | ||
config.add_route('smartthings_add_event', '/push') | ||
config.add_route('smartthings_subscribe', '/smartthings/subscribe') | ||
config.scan() | ||
return config.make_wsgi_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
"""rethinkDB connection""" | ||
import arrow | ||
import rethinkdb as r | ||
|
||
|
||
class Connection(object): | ||
"""RethinkDB Connection handler""" | ||
__connection__ = None | ||
__db__ = None | ||
__host__ = None | ||
__port__ = None | ||
__user__ = None | ||
__password__ = None | ||
__session__ = None | ||
__table__ = None | ||
|
||
def __init__(self, | ||
host, | ||
port, | ||
user, | ||
password, | ||
db, | ||
**kw): | ||
self.__db__ = db | ||
self.__host__ = host | ||
self.__password__ = password | ||
self.__port__ = port | ||
self.__user__ = user | ||
self.__table__ = kw.get('table') | ||
self._setup_connection(**kw) | ||
|
||
def _setup_connection(self, **kw): | ||
if self.__connection__ is None: | ||
self.__connection__ = r.connect(host=self.host, | ||
port=self.port, | ||
user=self.user, | ||
password=self.password, | ||
db=self.db, | ||
**kw) | ||
|
||
@property | ||
def db(self): | ||
return self.__db__ | ||
|
||
@property | ||
def host(self): | ||
return self.__host__ | ||
|
||
@property | ||
def password(self): | ||
return self.__password__ | ||
|
||
@property | ||
def port(self): | ||
return self.__port__ | ||
|
||
@property | ||
def session(self): | ||
"""get the connection to the database""" | ||
if self.__connection__ == None: | ||
self._setup_connection() | ||
|
||
return self.__connection__ | ||
|
||
@property | ||
def table(self): | ||
return self.__table__ | ||
|
||
@property | ||
def user(self): | ||
return self.__user__ | ||
|
||
def close(self): | ||
if self.__session__: | ||
self.session.close() | ||
|
||
def remove(self): | ||
"""close and remove the connection""" | ||
self.close() | ||
self.__connection__ = None | ||
|
||
def commit(self): | ||
"""call run on the db""" | ||
return | ||
|
||
def open(self): | ||
""" | ||
close the connection if it is open | ||
reopen a new connection to the DB""" | ||
self.session.reconnect() | ||
|
||
@property | ||
def connect(self): | ||
"""make the connection; create a connection if it does not | ||
exist. | ||
""" | ||
self._setup_connection() | ||
|
||
@property | ||
def created(self): | ||
return r.now() | ||
|
||
modified = created | ||
|
||
@property | ||
def model(self): | ||
"""create a model of the record to store in the database | ||
""" | ||
return self.__model__ | ||
|
||
@property | ||
def r(self): | ||
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package: pyramidbridge | ||
environment: dev | ||
handlers: | ||
date: | ||
arrow_format: "YYYY/MM/DD" | ||
default_format: "YYYY/MM/DD" | ||
query_format: "YYYY-MM-DD" | ||
datetime: | ||
arrow_format: "YYYY/MM/DD HH:mm:ss" | ||
default_format: "%%Y/%%m/%%d %%H:%%M:%%S" | ||
logging: | ||
name: pyramidbridge | ||
level: INFO | ||
rethinkdb: | ||
host: rethinkdb | ||
port: 28015 | ||
smartthings: | ||
db: smartthings | ||
events: | ||
table: events | ||
subscribe: | ||
table: subscriptions | ||
user: smartthings | ||
password: sm@rt!3s |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.