-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
ed12f1a
commit b07839b
Showing
12 changed files
with
436 additions
and
7 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 |
---|---|---|
@@ -1 +1,8 @@ | ||
# Node.js | ||
node_modules | ||
|
||
# Python | ||
*.py[cod] | ||
*.egg-info/ | ||
.eggs/ | ||
.tox/ |
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,15 @@ | ||
[[source]] | ||
name = "pypi" | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
|
||
[dev-packages] | ||
tox = "*" | ||
pytest = "*" | ||
responses = "*" | ||
|
||
[packages] | ||
requests = "*" | ||
|
||
[requires] | ||
python_version = "3.7" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 .client import PipedreamSdkClient | ||
|
||
|
||
_CLIENT = None | ||
|
||
|
||
def _get_client(): | ||
global _CLIENT | ||
|
||
if _CLIENT is None: | ||
_CLIENT = PipedreamSdkClient() | ||
return _CLIENT | ||
|
||
|
||
def send_event(*args, **kwargs): | ||
_get_client().send_event(*args, **Jkwargs) |
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 @@ | ||
version = '0.0.1dev0' |
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,63 @@ | ||
import hashlib | ||
import json | ||
import os | ||
|
||
import requests | ||
|
||
from .about import version | ||
|
||
|
||
class PipedreamSdkClient: | ||
def __init__(self, api_key=None, api_secret=None, sdk_host=None, sdk_protocol=None): | ||
self._sdk_version = '0.3.0' | ||
self._api_key = api_key or os.getenv('PD_SDK_API_KEY') | ||
self._api_secret = api_secret or os.getenv('PD_SDK_SECRET_KEY') | ||
self._sdk_host = ( | ||
sdk_host | ||
or os.getenv('PD_SDK_HOST') | ||
or 'sdk.m.pipedream.net' | ||
) | ||
self._sdk_protocol = ( | ||
sdk_protocol | ||
or os.getenv('PD_SDK_PROTO') | ||
or 'https' | ||
) | ||
|
||
def send_event(self, raw_event, exports=None, deployment=None): | ||
"""Send an event to the PipedreamHQ SDK | ||
:return: None | ||
""" | ||
# Manually create the payload so a signature can be generated | ||
event = {'raw_event': raw_event} | ||
data = json.dumps(event) | ||
headers = { | ||
'content-type': 'application/json', | ||
'user-agent': f'pipedream-sdk:python/{version}', | ||
'x-pd-sdk-version': self._sdk_version, | ||
} | ||
|
||
if self._api_secret: | ||
headers['x-pd-sig'] = self._sign(data) | ||
# TODO: warn if no secret is present | ||
|
||
#TODO: raise exception if POST fails | ||
response = requests.post(self._request_uri(deployment), data=data, headers=headers) | ||
import pdb; pdb.set_trace() | ||
|
||
def _request_uri(self, deployment): | ||
uri_parts = [ | ||
f'{self._sdk_protocol}://{self._sdk_host}', | ||
'pipelines', | ||
self._api_key, | ||
] | ||
if deployment: | ||
uri_parts += ['deployments', deployment] | ||
uri_parts.append('events') | ||
return '/'.join(uri_parts) | ||
|
||
def _sign(self, data): | ||
sig = hashlib.sha256(self._api_secret.encode('utf-8')) | ||
sig.update(data.encode('utf-8')) | ||
return sig.hexdigest() | ||
|
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,8 @@ | ||
import os | ||
|
||
client_version = '0.0.1dev0' | ||
|
||
sdk_version = '0.3.0' | ||
hostname = os.getenv('PD_SDK_HOST') or 'sdk.m.pipedream.net' | ||
protocol = os.getenv('PD_SDK_PROTO') or 'https' | ||
user_agent = f'pipedream-sdk:python/{client_version}' |
Oops, something went wrong.