Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Support APS API#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bd7a3d2bbff427f2fc68263c491c18aa42b3af796fe6b04d7546799ef40ead2a63161b8133e035852729File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -241,3 +241,11 @@ This is an example of what is returned in the case of an error: | ||
| 'method' : 'AccountDetailsGet_API' | ||
| } | ||
| ``` | ||
| APS API Usage Example | ||
| --------------------------------------- | ||
| ```{.sourceCode .python} | ||
| import apsapi | ||
| aapi = apsapi.API(url = 'https://hostname:6308') | ||
| resp = aapi.GET( '/aps/2/resources/' + safilter, {'APS-Token': token} ) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. safilter what is it? I can't find in README.md any information about it. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
| ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import httplib | ||
| import json | ||
| import ssl | ||
| import urllib2 | ||
| from urlparse import urljoin | ||
| class HTTPSClientAuthHandler(urllib2.HTTPSHandler, object): | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use only Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTTPSHandler is old-style class with out object I cannot use super() in init() Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok | ||
| def __init__(self, key, cert, context=None): | ||
| super(HTTPSClientAuthHandler, self).__init__(context=context) | ||
| self.key = key | ||
| self.cert = cert | ||
| def https_open(self, req): | ||
| # Rather than pass in a reference to a connection class, we pass in | ||
| # a reference to a function which, for all intents and purposes, | ||
| # will behave as a constructor | ||
| return self.do_open(self.get_connection, req) | ||
| def get_connection(self, host, timeout=300): | ||
| return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert, context=self._context) | ||
| class API(object): | ||
| def __init__(self, url, use_unverified_context=False): | ||
| """ | ||
| Takes something like the following argument as input: | ||
| url = 'https://a.bvt.aps.sw.ru:6308' | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to use depersonalized example instead eg. hostname or example.com | ||
| """ | ||
| self.url = url | ||
| self.use_unverified_context = use_unverified_context | ||
| def call(self, verb, path, headers=None, data=None, cert=None): | ||
| if not data: | ||
| data = {} | ||
| else: | ||
| data = json.dumps(data) | ||
| url = urljoin(self.url, path) | ||
| if not headers: | ||
| headers = {} | ||
| req = urllib2.Request(url, headers=headers, data=data) | ||
| req.get_method = lambda: verb | ||
| context = None | ||
| if self.use_unverified_context: | ||
| context = ssl._create_unverified_context() | ||
| try: | ||
| if cert: | ||
| opener = urllib2.build_opener(HTTPSClientAuthHandler(cert, cert, context=context)) | ||
| resp = opener.open(req) | ||
| else: | ||
| resp = urllib2.urlopen(req, context=context) | ||
| except urllib2.HTTPError as error: | ||
| content = error.read() | ||
| if content: | ||
| error.aps = json.loads(content) | ||
| else: | ||
| error.aps = {'code': 0, 'type': '', 'message': ''} | ||
| raise error | ||
| content = resp.read() | ||
| # Converting JSON immediately if presented | ||
| if content: | ||
| content = json.loads(content) | ||
| return content | ||
| def get(self, path, headers=None, data=None, cert=None): | ||
| return self.call('GET', path, headers, data, cert) | ||
| def put(self, path, headers=None, data=None, cert=None): | ||
| return self.call('PUT', path, headers, data, cert) | ||
| def post(self, path, headers=None, data=None, cert=None): | ||
| return self.call('POST', path, headers, data, cert) | ||
| def delete(self, path, headers=None, data=None, cert=None): | ||
| return self.call('DELETE', path, headers, data, cert) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,7 +22,7 @@ def version_file(mode='r'): | ||
| version=version(), | ||
| author='apsliteteam, oznu', | ||
| author_email='aps@odin.com', | ||
| packages=['osaapi'], | ||
| packages=['osaapi', 'apsapi'], | ||
| url='https://aps.odin.com', | ||
| license='Apache License', | ||
| description='A python client for the Odin Service Automation (OSA) and billing APIs.', | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A python binding for Odin Automation and APS controller https://doc.apsstandard.org/7.1/api/rest/ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url = 'h -> url='h