corva-worker-python 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/corva_worker_python-0.1.0-py2.7.egg-info/PKG-INFO +19 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/corva_worker_python-0.1.0-py2.7.egg-info/SOURCES.txt +10 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/corva_worker_python-0.1.0-py2.7.egg-info/dependency_links.txt +1 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/corva_worker_python-0.1.0-py2.7.egg-info/top_level.txt +1 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/__init__.py +3 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/__init__.pyc +0 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/api.py +74 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/api.pyc +0 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/data.py +37 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/data.pyc +0 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/exceptions.py +18 -0
- usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/worker/exceptions.pyc +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: corva-worker-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SDK for interacting with Corva
|
|
5
|
+
Home-page: https://bitbucket.com/corva/corva-worker-python
|
|
6
|
+
Author: Jordan Ambra
|
|
7
|
+
Author-email: jordan.ambra@corva.ai
|
|
8
|
+
License: The Unlicense
|
|
9
|
+
Description-Content-Type: UNKNOWN
|
|
10
|
+
Description: UNKNOWN
|
|
11
|
+
Keywords: corva
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
corva_worker_python.egg-info/PKG-INFO
|
|
4
|
+
corva_worker_python.egg-info/SOURCES.txt
|
|
5
|
+
corva_worker_python.egg-info/dependency_links.txt
|
|
6
|
+
corva_worker_python.egg-info/top_level.txt
|
|
7
|
+
worker/__init__.py
|
|
8
|
+
worker/api.py
|
|
9
|
+
worker/data.py
|
|
10
|
+
worker/exceptions.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
worker
|
|
Binary file
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from worker.data import Result
|
|
5
|
+
from worker import exceptions
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Worker(object):
|
|
9
|
+
HTTP_METHODS = ('get', 'post', 'patch', 'put', 'delete')
|
|
10
|
+
options = {
|
|
11
|
+
"api_url": "API_ROOT_URL",
|
|
12
|
+
"api_key": "API_KEY",
|
|
13
|
+
"app_name": "APP_NAME"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def __init__(self, *args, **kwargs):
|
|
17
|
+
self.configure(self.options, kwargs)
|
|
18
|
+
|
|
19
|
+
def configure(self, options, values):
|
|
20
|
+
for attribute, environment_key in options.items():
|
|
21
|
+
value = values.pop(attribute, os.getenv(environment_key, None))
|
|
22
|
+
if not value:
|
|
23
|
+
error = "No {0} parameter or {1} environment variable defined".format(attribute, environment_key)
|
|
24
|
+
raise exceptions.Misconfigured(error)
|
|
25
|
+
|
|
26
|
+
setattr(self, attribute, value)
|
|
27
|
+
|
|
28
|
+
def get(self, *args, **kwargs):
|
|
29
|
+
return self.call("get", *args, **kwargs)
|
|
30
|
+
|
|
31
|
+
def post(self, *args, **kwargs):
|
|
32
|
+
return self.call("post", *args, **kwargs)
|
|
33
|
+
|
|
34
|
+
def patch(self, *args, **kwargs):
|
|
35
|
+
return self.call("patch", *args, **kwargs)
|
|
36
|
+
|
|
37
|
+
def put(self, *args, **kwargs):
|
|
38
|
+
return self.call("put", *args, **kwargs)
|
|
39
|
+
|
|
40
|
+
def delete(self, *args, **kwargs):
|
|
41
|
+
return self.call("delete", *args, **kwargs)
|
|
42
|
+
|
|
43
|
+
def call(self, method, path, **kwargs):
|
|
44
|
+
content_type = kwargs.pop("content_type", "application/json")
|
|
45
|
+
headers = {
|
|
46
|
+
"Authorization": "API {0}".format(self.api_key),
|
|
47
|
+
"Content-Type": content_type,
|
|
48
|
+
"X-Corva-App": self.app_name
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
method = method.lower()
|
|
52
|
+
if method not in Worker.HTTP_METHODS:
|
|
53
|
+
raise exceptions.APIError("Invalid HTTP method {0}".format(method))
|
|
54
|
+
|
|
55
|
+
http_method = getattr(requests, method)
|
|
56
|
+
data = kwargs.pop("data", None)
|
|
57
|
+
if not path.startswith(self.api_url):
|
|
58
|
+
path = "{0}/{1}".format(self.api_url, path)
|
|
59
|
+
|
|
60
|
+
response = http_method(url=path, data=data, params=kwargs, headers=headers)
|
|
61
|
+
|
|
62
|
+
asset_id = kwargs.get("asset_id", "Unknown") or "Unknown"
|
|
63
|
+
|
|
64
|
+
if response.status_code in (401, 403):
|
|
65
|
+
raise exceptions.Forbidden("No access to asset {0}".format(asset_id))
|
|
66
|
+
|
|
67
|
+
if response.status_code == 404:
|
|
68
|
+
raise exceptions.AssetNotFound("Asset {0} Not Found".format(asset_id))
|
|
69
|
+
|
|
70
|
+
if not response.ok:
|
|
71
|
+
raise exceptions.APIError("Unable to reach Corva API")
|
|
72
|
+
|
|
73
|
+
result = Result(response, **kwargs)
|
|
74
|
+
return result
|
|
Binary file
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from worker import exceptions
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Result(object):
|
|
5
|
+
|
|
6
|
+
def __init__(self, response, **kwargs):
|
|
7
|
+
self.response = response
|
|
8
|
+
self.params = kwargs
|
|
9
|
+
self.data = None
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
self.data = response.json()
|
|
13
|
+
except Exception:
|
|
14
|
+
raise exceptions.APIError("Invalid API response")
|
|
15
|
+
|
|
16
|
+
def __repr__(self):
|
|
17
|
+
return repr(self.data)
|
|
18
|
+
|
|
19
|
+
def __iter__(self):
|
|
20
|
+
return iter(self.data)
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def status(self):
|
|
24
|
+
return self.response.status_code
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def count(self):
|
|
28
|
+
if not self.data:
|
|
29
|
+
return 0
|
|
30
|
+
|
|
31
|
+
if isinstance(self.data, list):
|
|
32
|
+
return len(self.data)
|
|
33
|
+
|
|
34
|
+
if isinstance(self.data, dict):
|
|
35
|
+
return 1
|
|
36
|
+
|
|
37
|
+
return 0
|
|
Binary file
|