Skip to content

Commit 6f15113

Browse files
author
kadhikari
committed
Some modifications on remarks
1 parent e51497b commit 6f15113

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

source/jormungandr/jormungandr/api.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,21 @@ def add_info_newrelic(response, *args, **kwargs):
9090
record_custom_parameter('navitia-request-id', request.id)
9191

9292
token = get_token()
93+
# No log will be added in newrelic if token is absent in the request
9394
if token:
9495
user = get_user(token=token, abort_if_no_token=False)
9596
if user:
9697
record_custom_parameter('user_id', str(user.id))
97-
# This method verifies database connection and gets object Key only once when cache expires.
98-
app_name = get_app_name(token)
99-
if app_name:
100-
record_custom_parameter('token_name', app_name)
101-
102-
record_custom_parameter('version', __version__)
103-
coverages = get_used_coverages()
104-
if coverages:
105-
record_custom_parameter('coverage', coverages[0])
98+
# This method verifies database connection and gets object Key only once when cache expires.
99+
app_name = get_app_name(token)
100+
if app_name:
101+
record_custom_parameter('token_name', app_name)
102+
103+
record_custom_parameter('version', __version__)
104+
# No access to database required
105+
coverages = get_used_coverages()
106+
if coverages:
107+
record_custom_parameter('coverage', coverages[0])
106108
except:
107109
logger = logging.getLogger(__name__)
108110
logger.exception('error while reporting to newrelic:')

source/jormungandr/jormungandr/authentication.py

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def uncached_get_user(token):
200200
# if user doesn't exist for a token, get default token with user_type = no_access
201201
if not user:
202202
user = User.get_without_access()
203+
logging.getLogger(__name__).warning('Invalid token : {}'.format(token[0:10]))
203204
except Exception as e:
204205
logging.getLogger(__name__).error('No access to table User (error: {})'.format(e))
205206
g.can_connect_to_database = False

source/navitiacommon/navitiacommon/models/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def get_from_key(cls, token, valid_until):
196196

197197
@classmethod
198198
def get_without_access(cls):
199-
query = cls.query.filter(cls.type == 'no_access')
199+
query = cls.query.filter(cls.type == 'no_access' and cls.login == 'user_without_access')
200200
return query.first()
201201

202202
def has_access(self, instance_id, api_name):

source/tyr/migrations/versions/04f9b89e3ef5_add_no_access_in_user_type.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@
2020

2121

2222
def upgrade():
23-
tmp_type.create(op.get_bind(), checkfirst=False)
24-
op.execute('ALTER TABLE "user" ALTER COLUMN type DROP DEFAULT')
25-
op.execute('ALTER TABLE "user" ALTER COLUMN type TYPE _user_type USING type::text::_user_type')
26-
old_type.drop(op.get_bind(), checkfirst=False)
27-
28-
new_type.create(op.get_bind(), checkfirst=False)
29-
op.execute('ALTER TABLE "user" ALTER COLUMN type TYPE user_type USING type::text::user_type')
30-
op.execute('ALTER TABLE "user" ALTER COLUMN type SET DEFAULT \'with_free_instances\'')
31-
tmp_type.drop(op.get_bind(), checkfirst=False)
23+
op.execute("COMMIT")
24+
op.execute("ALTER TYPE user_type ADD VALUE 'no_access'")
3225
op.execute(
3326
'INSERT INTO "user"(login, email, type) values(\'user_without_access\', \'[email protected]\', \'no_access\')'
3427
)

0 commit comments

Comments
 (0)