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-08-05 13:40:37 +0200
commit9c8b0432b1be4528d2bc493c8dd3ae09c83c385c (patch)
tree29260ff8fa83a5fd8e4ce6a7a4060c5ecd1454e6 /ogcp/views.py
parentb6bbd8f322b155e1969a6f356f1e4c8e8ca7fee2 (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}