Skip to content

Commit

Permalink
Netrino passes req to execute, need to handle that.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vuader committed Jul 31, 2018
1 parent 19ddfc4 commit 93b14d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
29 changes: 27 additions & 2 deletions psychokinetic/openstack/api/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
from luxon.core.handlers.wsgi.request import Request
from luxon.exceptions import FieldMissing


def getScope(req):
gotOne = False
scope = {'domain': req.context_domain}
if 'project_name' in req.json:
scope['project_name'] = req.json['project_name']
gotOne = True
if 'project_id' in req.json:
scope['project_id'] = req.json['project_id']
gotOne = True
if not gotOne:
raise FieldMissing(field="project_name or project_id",
label="Project",
description="Please Specify Tenant/Project")
return scope


class APIBase(object):
Expand All @@ -39,6 +57,7 @@ class APIBase(object):
type (str): Openstack Endpoint Type: internal, public, or admin
"""

def __init__(self, client, type):
self._client = client
self._type = type
Expand All @@ -59,11 +78,11 @@ def url(self):
_ep_interface = '_%s_endpoints' % self._client.interface

if self._type in getattr(self._client, _ep_interface):
return getattr(self._client,_ep_interface)[self._type]
return getattr(self._client, _ep_interface)[self._type]

raise ValueError("No '%s' endpoint found" % self._type)

def execute(self, method, uri, **kwargs):
def execute(self, method, uri='', **kwargs):
"""Executes the call on the given URI.
Ags:
Expand All @@ -74,5 +93,11 @@ def execute(self, method, uri, **kwargs):
Returns:
Response object.
"""
if isinstance(method, Request):
uri = method.json['uri']
kwargs['data'] = method.json['data']
self.client.identity.scope(**getScope(method))
method = method.json['method']

uri = self.url + '/' + uri
return self.client.execute(method, uri, **kwargs)
10 changes: 10 additions & 0 deletions psychokinetic/openstack/api/identityv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,13 @@ def unscope(self):
del self.client['domain_header']
except:
pass

def revoke(self, token):
"""Revokes token
Args:
token (str): Token to revoke.
"""
_token_url = self.client.keystone_url.rstrip('/') + '/auth/tokens'
self.client['X-Subject-Token'] = token
return self.client.execute('DELETE', _token_url)

0 comments on commit 93b14d9

Please sign in to comment.