Skip to content

Commit 7f61f57

Browse files
committed
remove redundant enum service
1 parent 08e063b commit 7f61f57

6 files changed

Lines changed: 13 additions & 24 deletions

File tree

lambdas/id_sync/src/pds_details.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import tempfile
66

7-
from common.api_clients.authentication import AppRestrictedAuth, Service
7+
from common.api_clients.authentication import AppRestrictedAuth
88
from common.api_clients.pds_service import PdsService
99
from common.cache import Cache
1010
from common.clients import get_secrets_manager_client, logger
@@ -20,7 +20,6 @@ def pds_get_patient_details(nhs_number: str) -> dict:
2020
try:
2121
cache = Cache(directory=safe_tmp_dir)
2222
authenticator = AppRestrictedAuth(
23-
service=Service.PDS,
2423
secret_manager_client=get_secrets_manager_client(),
2524
environment=pds_env,
2625
cache=cache,

lambdas/shared/src/common/api_clients/authentication.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,25 @@
22
import json
33
import time
44
import uuid
5-
from enum import Enum
65

76
import jwt
87
import requests
98

9+
from common.api_clients.constants import API_CACHE_KEY
1010
from common.clients import logger
1111
from common.models.errors import UnhandledResponseError
1212

1313
from ..cache import Cache
1414

1515

16-
class Service(Enum):
17-
PDS = "pds"
18-
IMMUNIZATION = "imms"
19-
20-
2116
class AppRestrictedAuth:
22-
def __init__(self, service: Service, secret_manager_client, environment, cache: Cache):
17+
def __init__(self, secret_manager_client, environment, cache: Cache):
2318
self.secret_manager_client = secret_manager_client
2419
self.cache = cache
25-
self.cache_key = f"{service.value}_access_token"
20+
self.cache_key = API_CACHE_KEY
2621

2722
self.expiry = 30
28-
self.secret_name = (
29-
f"imms/outbound/{environment}/jwt-secrets"
30-
if service == Service.PDS
31-
else f"imms/immunization/{environment}/jwt-secrets"
32-
)
23+
self.secret_name = f"imms/outbound/{environment}/jwt-secrets"
3324

3425
self.token_url = (
3526
f"https://{environment}.api.service.nhs.uk/oauth2/token"

lambdas/shared/src/common/api_clients/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Constants used by API clients"""
44

55
DEV_ENVIRONMENT = "dev"
6+
API_CACHE_KEY = "api_client_access_token"
67

78

89
class Constants:

lambdas/shared/src/common/api_clients/get_pds_details.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import tempfile
77

8-
from common.api_clients.authentication import AppRestrictedAuth, Service
8+
from common.api_clients.authentication import AppRestrictedAuth
99
from common.api_clients.errors import PdsSyncException
1010
from common.api_clients.pds_service import PdsService
1111
from common.cache import Cache
@@ -20,7 +20,6 @@ def pds_get_patient_details(nhs_number: str) -> dict:
2020
try:
2121
cache = Cache(directory=safe_tmp_dir)
2222
authenticator = AppRestrictedAuth(
23-
service=Service.PDS,
2423
secret_manager_client=get_secrets_manager_client(),
2524
environment=PDS_ENV,
2625
cache=cache,

lambdas/shared/src/common/api_clients/mns_setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import boto3
55
from botocore.config import Config
66

7-
from common.api_clients.authentication import AppRestrictedAuth, Service
7+
from common.api_clients.authentication import AppRestrictedAuth
88
from common.api_clients.constants import DEV_ENVIRONMENT
99
from common.api_clients.mns_service import MnsService
1010
from common.api_clients.mock_mns_service import MockMnsService
@@ -23,7 +23,6 @@ def get_mns_service(mns_env: str = "int"):
2323
cache = Cache(directory="/tmp")
2424
logging.info("Creating authenticator...")
2525
authenticator = AppRestrictedAuth(
26-
service=Service.PDS,
2726
secret_manager_client=boto3.client("secretsmanager", config=boto_config),
2827
environment=mns_env,
2928
cache=cache,

lambdas/shared/tests/test_common/api_clients/test_authentication.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import responses
88
from responses import matchers
99

10-
from common.api_clients.authentication import AppRestrictedAuth, Service
10+
from common.api_clients.authentication import AppRestrictedAuth
1111
from common.models.errors import UnhandledResponseError
1212

1313

@@ -33,7 +33,7 @@ def setUp(self):
3333
self.cache.get.return_value = None
3434

3535
env = "an-env"
36-
self.authenticator = AppRestrictedAuth(Service.PDS, self.secret_manager_client, env, self.cache)
36+
self.authenticator = AppRestrictedAuth(self.secret_manager_client, env, self.cache)
3737
self.url = f"https://{env}.api.service.nhs.uk/oauth2/token"
3838

3939
@responses.activate
@@ -89,12 +89,12 @@ def test_env_mapping(self):
8989
"""it should target int environment for none-prod environment, otherwise int"""
9090
# For env=none-prod
9191
env = "some-env"
92-
auth = AppRestrictedAuth(Service.PDS, None, env, None)
92+
auth = AppRestrictedAuth(None, env, None)
9393
self.assertTrue(auth.token_url.startswith(f"https://{env}."))
9494

9595
# For env=prod
9696
env = "prod"
97-
auth = AppRestrictedAuth(Service.PDS, None, env, None)
97+
auth = AppRestrictedAuth(None, env, None)
9898
self.assertTrue(env not in auth.token_url)
9999

100100
def test_returned_cached_token(self):
@@ -126,7 +126,7 @@ def test_update_cache(self):
126126
self.authenticator.get_access_token()
127127

128128
# Then
129-
self.cache.put.assert_called_once_with(f"{Service.PDS.value}_access_token", cached_token)
129+
self.cache.put.assert_called_once_with("api_client_access_token", cached_token)
130130

131131
@responses.activate
132132
def test_expired_token_in_cache(self):

0 commit comments

Comments
 (0)