Skip to content

Commit

Permalink
Deglobalise API version
Browse files Browse the repository at this point in the history
  • Loading branch information
nemozak1 committed Dec 1, 2023
1 parent b2f017e commit 76c66e3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apimanager/apicollections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def apicollections_update(request):
'is_sharable': True if request.POST.get('api_collection_is_sharable').strip().lower() == "true" else False,
'description': request.POST.get('api_collection_description').strip()
}
result = api.put(urlpath, payload=payload, version=settings.API_ROOT['v510'])
result = api.put(urlpath, payload=payload, version=settings.API_VERSION['v510'])
return result


Expand Down
8 changes: 3 additions & 5 deletions apimanager/apimanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'base.context_processors.api_root',
'base.context_processors.api_version_processor',
'base.context_processors.api_username',
'base.context_processors.api_user_id',
'base.context_processors.api_tester_url',
Expand Down Expand Up @@ -319,8 +319,6 @@
# Global
UNDEFINED = "<undefined>"

API_ROOT_KEY = "v510"

# Local settings can replace any value ABOVE
try:
from apimanager.local_settings import * # noqa
Expand All @@ -331,8 +329,8 @@
OBPv500 = API_HOST + '/obp/v5.0.0'
OBPv510 = API_HOST + '/obp/v5.1.0'

# Settings here might use parts overwritten in local settings
API_ROOT = {
# API Versions
API_VERSION = {
"v500": OBPv500,
"v510": OBPv510
}
Expand Down
8 changes: 4 additions & 4 deletions apimanager/atms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
template_name = "atms/update.html"
success_url = '/atms/list'
form_class = CreateAtmForm
v510 = settings.API_ROOT['v510']
v510 = settings.API_VERSION['v510']

def dispatch(self, request, *args, **kwargs):
self.api = API(request.session.get('obp'))
Expand Down Expand Up @@ -410,7 +410,7 @@ def atm_attribute_save(request):
'value': request.POST.get('value').strip(),
'is_active': True
}
result = api.post(urlpath_save, payload = payload, version=settings.API_ROOT['v510'])
result = api.post(urlpath_save, payload = payload, version=settings.API_VERSION['v510'])
return result


Expand All @@ -428,7 +428,7 @@ def atm_attribute_update(request):
'value': request.POST.get('value').strip(),
'is_active': True
}
result = api.put(urlpath_update, payload=payload, version=settings.API_ROOT['v510'])
result = api.put(urlpath_update, payload=payload, version=settings.API_VERSION['v510'])
return result


Expand All @@ -441,7 +441,7 @@ def atm_attribute_delete(request):

api = API(request.session.get('obp'))
urlpath_delete = '/banks/{}/atms/{}/attributes/{}'.format(bank_id, atm_id, atm_attribute_id)
result = api.delete(urlpath_delete, version=settings.API_ROOT['v510'])
result = api.delete(urlpath_delete, version=settings.API_VERSION['v510'])
return result


Expand Down
8 changes: 4 additions & 4 deletions apimanager/banks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class UpdateBanksView(LoginRequiredMixin, FormView):
template_name = "banks/update.html"
form_class = CreateBankForm
success_url = '/banks/list'
v510 = settings.API_ROOT['v510']
v510 = settings.API_VERSION['v510']

def dispatch(self, request, *args, **kwargs):
self.api = API(request.session.get('obp'))
Expand Down Expand Up @@ -183,7 +183,7 @@ def bank_attribute_save(request):
'value': request.POST.get('value').strip(),
'is_active': True
}
result = api.post(urlpath_save, payload = payload, version=settings.API_ROOT['v510'])
result = api.post(urlpath_save, payload = payload, version=settings.API_VERSION['v510'])
return result


Expand All @@ -201,7 +201,7 @@ def bank_attribute_update(request):
'value': request.POST.get('value').strip(),
'is_active': True
}
result = api.put(urlpath_update, payload=payload, version=settings.API_ROOT['v510'])
result = api.put(urlpath_update, payload=payload, version=settings.API_VERSION['v510'])
return result


Expand All @@ -212,6 +212,6 @@ def bank_attribute_delete(request):
bank_attribute_id = request.POST.get('bank_attribute_id').strip()
api = API(request.session.get('obp'))
urlpath_delete = '/banks/{}/attributes/{}'.format(bank_id, bank_attribute_id)
result = api.delete(urlpath_delete, version=settings.API_ROOT['v510'])
result = api.delete(urlpath_delete, version=settings.API_VERSION['v510'])
return result

6 changes: 3 additions & 3 deletions apimanager/base/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

USER_CURRENT = "/users/current"

def api_root(request):
"""Returns the configured API_ROOT"""
return {'API_ROOT': settings.API_ROOT['v500']}
def api_version_processor(request):
"""Returns the configured API_VERSION"""
return {'API_VERSION': settings.API_VERSION['v500']}


def portal_page(request):
Expand Down
2 changes: 1 addition & 1 deletion apimanager/methodrouting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_context_data(self, **kwargs):
else:
method_routings[i]['parameters'] = json.dumps(method_routings[i]['parameters'], sort_keys=False)

if(str(settings.API_ROOT).find("127.0.0.1") == -1):
if(str(settings.API_VERSION).find("127.0.0.1") == -1):
method_Swagger_Url = '{}/message-docs?connector=stored_procedure_vDec2019#'.format(settings.API_HOST.replace(".openbankproject.", "-explorer.openbankproject."))
else:
method_Swagger_Url = "http://127.0.0.1:8082/message-docs?connector=stored_procedure_vDec2019#"
Expand Down
2 changes: 1 addition & 1 deletion apimanager/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_metrics(self, cleaned_data):
urlpath = '{}?{}'.format(self.api_urlpath, params)
api = API(self.request.session.get('obp'))
try:
metrics = api.get(urlpath)
metrics = api.get(urlpath, version=settings.API_VERSION["v510"])
metrics = self.to_django(metrics['metrics'])
except APIError as err:
if DEBUG:
Expand Down
18 changes: 9 additions & 9 deletions apimanager/obp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, session_data=None):
self.start_session(session_data)
self.session_data = session_data

def call(self, method='GET', url='', payload=None, version=settings.API_ROOT[settings.API_ROOT_KEY]):
def call(self, method='GET', url='', payload=None, version=settings.API_VERSION['v500']):
"""Workhorse which actually calls the API"""
log(logging.INFO, '{} {}'.format(method, url))
if payload:
Expand All @@ -64,11 +64,11 @@ def call(self, method='GET', url='', payload=None, version=settings.API_ROOT[set
response.execution_time = elapsed
return response

def get(self, urlpath='', version=settings.API_ROOT[settings.API_ROOT_KEY]):
def get(self, urlpath='', version=settings.API_VERSION['v500']):
"""
Gets data from the API
Convenience call which uses API_ROOT from settings
Convenience call which uses API_VERSION from settings
"""
url = version + urlpath
response = self.handle_response(self.call('GET', url))
Expand All @@ -77,31 +77,31 @@ def get(self, urlpath='', version=settings.API_ROOT[settings.API_ROOT_KEY]):
else:
return response

def delete(self, urlpath, version=settings.API_ROOT[settings.API_ROOT_KEY]):
def delete(self, urlpath, version=settings.API_VERSION['v500']):
"""
Deletes data from the API
Convenience call which uses API_ROOT from settings
Convenience call which uses API_VERSION from settings
"""
url = version + urlpath
response = self.call('DELETE', url)
return self.handle_response(response)

def post(self, urlpath, payload, version=settings.API_ROOT[settings.API_ROOT_KEY]):
def post(self, urlpath, payload, version=settings.API_VERSION['v500']):
"""
Posts data to given urlpath with given payload
Convenience call which uses API_ROOT from settings
Convenience call which uses API_VERSION from settings
"""
url = version + urlpath
response = self.call('POST', url, payload)
return self.handle_response(response)

def put(self, urlpath, payload, version=settings.API_ROOT[settings.API_ROOT_KEY]):
def put(self, urlpath, payload, version=settings.API_VERSION['v500']):
"""
Puts data on given urlpath with given payload
Convenience call which uses API_ROOT from settings
Convenience call which uses API_VERSION from settings
"""
url = version + urlpath
response = self.call('PUT', url, payload)
Expand Down
2 changes: 1 addition & 1 deletion apimanager/obp/gatewaylogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create_jwt(self, data):
def prepare_gateway_login_token(self, data):
token = self.create_jwt(data)
# Make a test call to see if the token works
url = '{}{}'.format(settings.API_ROOT, '/users/current')
url = '{}{}'.format(settings.API_VERSION, '/users/current')
api = self.get_session()
try:
response = api.get(url)
Expand Down

0 comments on commit 76c66e3

Please sign in to comment.