summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-03 14:52:02 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-09-27 09:48:35 +0200
commitaf0a3255b470e9e0db1fe19de680a7abb66b0641 (patch)
tree8a34344f54323f96a098604239670f915a98959e /ogcp/views.py
parent2cbe6b774c8ffb10129f994d51f4237586331b7e (diff)
Add helper function to send requests to all ogServers
'multi_request()' function make requests to ogServers defined in the configuration and aggregates it responses. This commit also makes 'get_scopes()' use it.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 1ccd39b..a26ad55 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -176,13 +176,33 @@ def get_allowed_scopes(scopes, allowed_scopes):
else:
get_allowed_scopes(scope, allowed_scopes)
+def multi_request(method, uri, payload=None):
+ responses = []
+
+ for server in servers:
+ response = {}
+
+ if method == 'get':
+ r = server.get(uri, payload)
+ elif method == 'post':
+ r = server.post(uri, payload)
+ else:
+ raise Exception('Invalid method, use get or post')
+
+ response['server'] = server.name
+ response['status_code'] = r.status_code
+ response['json'] = r.json()
+ responses.append(response)
+
+ return responses
+
def get_scopes(ips=set()):
list_scopes = []
- for server in servers:
- r = server.get('/scopes')
- scopes = r.json()
+ responses = multi_request('get', '/scopes')
+ for r in responses:
+ scopes = r['json']
server_scope = {}
- server_scope['name'] = server.name
+ server_scope['name'] = r['server']
server_scope.update(scopes)
list_scopes.append(server_scope)
all_scopes = {'scope': list_scopes}