From e4604e40a451150d2d5f8bef9d6a9c8dfc00c6d6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 18 Oct 2019 10:49:33 +0300 Subject: Revert "Change: get and use tokens" This reverts commit 4dd2e14cd15ad2840cfc3636251802f8eb0bc9ba. --- ick2/apibase.py | 63 ++++++++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) (limited to 'ick2/apibase.py') diff --git a/ick2/apibase.py b/ick2/apibase.py index e18ebe2..f330eae 100644 --- a/ick2/apibase.py +++ b/ick2/apibase.py @@ -16,15 +16,10 @@ import ick2 -import bottle - - class APIbase: def __init__(self, state): - assert (state is None or - isinstance(state, ick2.MemoryPersistentState) or - isinstance(state, ick2.MuckPersistentState)) + assert state is None or isinstance(state, ick2.MemoryPersistentState) self._trans = ick2.TransactionalState(state) def get_routes(self, path): @@ -57,26 +52,12 @@ class APIbase: }, ] - # This is quite ugly. The apifw library we use as a wrapper around - # Bottle should be doing this. But due to stupid reasons, it's - # awkward to modify that library, for now, and anyway all of this - # is going to be rewritten in a better programming language - # eventually, so we take the past of least effort and increase - # technical debt. - def _get_token(self): - v = bottle.request.get_header('Authorization', '') - prefix = 'Bearer ' - if v.startswith(prefix): - return v[len(prefix):] - return None - def GET(self, callback): def wrapper(content_type, body, **kwargs): ick2.log.log( 'trace', msg_text='GET called', kwargs=kwargs, content_type=content_type, body=body) try: - kwargs['token'] = self._get_token() if 'raw_uri_path' in kwargs: del kwargs['raw_uri_path'] body = callback(**kwargs) @@ -101,7 +82,6 @@ class APIbase: 'trace', msg_text='POST called', kwargs=kwargs, content_type=content_type, body=body) try: - kwargs['token'] = self._get_token() body = callback(body, **kwargs) except ick2.ExistsAlready as e: ick2.log.log('error', msg_text=str(e), kwargs=kwargs) @@ -114,7 +94,6 @@ class APIbase: ick2.log.log( 'trace', msg_text='PUT called', kwargs=kwargs, content_type=content_type, body=body) - kwargs['token'] = self._get_token() if 'raw_uri_path' in kwargs: del kwargs['raw_uri_path'] try: @@ -133,7 +112,6 @@ class APIbase: 'trace', msg_text='DELETE called', kwargs=kwargs, content_type=content_type, body=body) try: - kwargs['token'] = self._get_token() if 'raw_uri_path' in kwargs: del kwargs['raw_uri_path'] body = callback(**kwargs) @@ -144,19 +122,19 @@ class APIbase: return ick2.OK(body) return wrapper - def create(self, body, token=None, **kwargs): + def create(self, body, **kwargs): raise NotImplementedError() - def update(self, body, name, token=None, **kwargs): + def update(self, body, name, **kwargs): raise NotImplementedError() - def delete(self, name, token=None, **kwargs): + def delete(self, name, **kwargs): raise NotImplementedError() - def list(self, token=None, **kwargs): + def list(self, **kwargs): raise NotImplementedError() - def show(self, name, token=None, **kwargs): + def show(self, name, **kwargs): raise NotImplementedError() @@ -166,27 +144,26 @@ class ResourceApiBase(APIbase): super().__init__(state) self._type_name = type_name - def list(self, token=None, **kwargs): - resources = self._trans.get_resources(token, self._type_name) + def list(self, **kwargs): + resources = self._trans.get_resources(self._type_name) return { self._type_name: [r.as_dict() for r in resources] } - def show(self, name, token=None, **kwargs): - return self._trans.get_resource(token, self._type_name, name).as_dict() + def show(self, name, **kwargs): + return self._trans.get_resource(self._type_name, name).as_dict() - def create(self, body, token=None, **kwargs): + def create(self, body, **kwargs): ick2.log.log( 'trace', msg_text='create resource', - resource_type=self._type_name, - body=body, token=token, kwargs=kwargs) + resource_type=self._type_name, body=body, kwargs=kwargs) as_dict = self.mangle_new_resource(body) rid = self.get_resource_name(as_dict) - if self._trans.has_resource(token, self._type_name, rid): + if self._trans.has_resource(self._type_name, rid): raise ick2.ExistsAlready(rid) - with self._trans.new(token, self._type_name, rid) as resource: + with self._trans.new(self._type_name, rid) as resource: resource.from_dict(as_dict) return as_dict @@ -197,12 +174,12 @@ class ResourceApiBase(APIbase): def get_resource_name(self, resource): # pragma: no cover raise NotImplementedError() - def update(self, body, name, token=None, **kwargs): + def update(self, body, name, **kwargs): rid = self.get_resource_name(body) - if not self._trans.has_resource(token, self._type_name, rid): + if not self._trans.has_resource(self._type_name, rid): raise ick2.NotFound(kind=self._type_name, rid=rid) - with self._trans.modify(token, self._type_name, rid) as resource: + with self._trans.modify(self._type_name, rid) as resource: as_dict = self.mangle_updated_resource(resource.as_dict(), body) resource.from_dict(as_dict) @@ -211,7 +188,7 @@ class ResourceApiBase(APIbase): def mangle_updated_resource(self, old, new): # pragma: no cover return new - def delete(self, name, token=None, **kwargs): - if not self._trans.has_resource(token, self._type_name, name): + def delete(self, name, **kwargs): + if not self._trans.has_resource(self._type_name, name): raise ick2.NotFound(kind=self._type_name, rid=name) - self._trans.remove_resource(token, self._type_name, name) + self._trans.remove_resource(self._type_name, name) -- cgit v1.2.1