Commit dc4f9131 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Fix internal API

parent 32d9903e
Pipeline #20580 passed with stages
in 5 minutes and 44 seconds
...@@ -25,8 +25,8 @@ logger = logging.getLogger(__name__) ...@@ -25,8 +25,8 @@ logger = logging.getLogger(__name__)
class UpdateLookupStatsHandlerParams(APIHandlerParams): class UpdateLookupStatsHandlerParams(APIHandlerParams):
def parse(self, values, conn): def parse(self, values, db):
super(UpdateLookupStatsHandlerParams, self).parse(values, conn) super(UpdateLookupStatsHandlerParams, self).parse(values, db)
self.secret = values.get('secret') self.secret = values.get('secret')
self.application_id = values.get('application_id', type=int) self.application_id = values.get('application_id', type=int)
self.date = values.get('date') self.date = values.get('date')
...@@ -83,13 +83,13 @@ class UpdateUserAgentStatsHandler(APIHandler): ...@@ -83,13 +83,13 @@ class UpdateUserAgentStatsHandler(APIHandler):
class LookupStatsHandlerParams(APIHandlerParams): class LookupStatsHandlerParams(APIHandlerParams):
def parse(self, values, conn): def parse(self, values, db):
super(LookupStatsHandlerParams, self).parse(values, conn) super(LookupStatsHandlerParams, self).parse(values, db)
self.secret = values.get('secret') self.secret = values.get('secret')
apikeys = values.getlist('client') apikeys = values.getlist('client')
if not apikeys: if not apikeys:
raise errors.InvalidAPIKeyError() raise errors.InvalidAPIKeyError()
self.applications = find_applications_by_apikeys(conn, apikeys) self.applications = find_applications_by_apikeys(db.get_app_db(), apikeys)
if not self.applications: if not self.applications:
raise errors.InvalidAPIKeyError() raise errors.InvalidAPIKeyError()
self.from_date = values.get('from') self.from_date = values.get('from')
...@@ -117,7 +117,7 @@ class LookupStatsHandler(APIHandler): ...@@ -117,7 +117,7 @@ class LookupStatsHandler(APIHandler):
kwargs['to_date'] = params.to_date kwargs['to_date'] = params.to_date
if params.days is not None: if params.days is not None:
kwargs['days'] = params.days kwargs['days'] = params.days
stats = find_application_lookup_stats_multi(self.conn, application_ids.keys(), **kwargs) stats = find_application_lookup_stats_multi(self.ctx.db.get_app_db(), application_ids.keys(), **kwargs)
for entry in stats: for entry in stats:
entry['date'] = entry['date'].strftime('%Y-%m-%d') entry['date'] = entry['date'].strftime('%Y-%m-%d')
return {'stats': stats} return {'stats': stats}
...@@ -125,8 +125,8 @@ class LookupStatsHandler(APIHandler): ...@@ -125,8 +125,8 @@ class LookupStatsHandler(APIHandler):
class CreateAccountHandlerParams(APIHandlerParams): class CreateAccountHandlerParams(APIHandlerParams):
def parse(self, values, conn): def parse(self, values, db):
super(CreateAccountHandlerParams, self).parse(values, conn) super(CreateAccountHandlerParams, self).parse(values, db)
self.secret = values.get('secret') self.secret = values.get('secret')
...@@ -138,7 +138,7 @@ class CreateAccountHandler(APIHandler): ...@@ -138,7 +138,7 @@ class CreateAccountHandler(APIHandler):
if self.cluster.secret != params.secret: if self.cluster.secret != params.secret:
logger.warning('Invalid cluster secret') logger.warning('Invalid cluster secret')
raise errors.NotAllowedError() raise errors.NotAllowedError()
account_id, account_api_key = insert_account(self.conn, { account_id, account_api_key = insert_account(self.ctx.db.get_app_db(), {
'name': 'External User', 'name': 'External User',
'anonymous': True, 'anonymous': True,
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment