Skip to content

Commit 60b2857

Browse files
authored
Merge pull request #40 from ShipChain/feature/internal-service-check
Add optional parameter to is_internal_call check
2 parents b4cc574 + 48e1ada commit 60b2857

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "shipchain-common"
3-
version = "1.0.24"
3+
version = "1.0.25"
44
description = "A PyPI package containing shared code for ShipChain's Python/Django projects."
55

66
license = "Apache-2.0"

src/shipchain_common/authentication.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ def get_jwt_from_request(request):
4343
return None
4444

4545

46-
def is_internal_call(request):
47-
return ('X_NGINX_SOURCE' in request.META and request.META['X_NGINX_SOURCE'] == 'internal'
48-
and request.META['X_SSL_CLIENT_VERIFY'] == 'SUCCESS')
46+
def is_internal_call(request, service_name=None):
47+
is_internal = ('X_NGINX_SOURCE' in request.META and request.META['X_NGINX_SOURCE'] == 'internal'
48+
and request.META['X_SSL_CLIENT_VERIFY'] == 'SUCCESS')
49+
if service_name and is_internal:
50+
certificate_cn = parse_dn(request.META['X_SSL_CLIENT_DN'])['CN']
51+
is_internal = certificate_cn == f'{service_name}.{settings.ENVIRONMENT.lower()}-internal'
52+
return is_internal
4953

5054

5155
class InternalRequest(BasePermission):
5256
def has_permission(self, request, view):
5357
if settings.ENVIRONMENT in ('LOCAL', 'INT'):
5458
return True
55-
if is_internal_call(request):
56-
certificate_cn = parse_dn(request.META['X_SSL_CLIENT_DN'])['CN']
57-
return certificate_cn == f'{self.SERVICE_NAME}.{settings.ENVIRONMENT.lower()}-internal'
58-
return False
59+
return is_internal_call(request, self.SERVICE_NAME)
5960

6061

6162
class EngineRequest(InternalRequest):

0 commit comments

Comments
 (0)