Merge branch 'feature/ARVE_authentication_verification' into 'master'

Added verifications for the ARVE API

See merge request cara/caimira!400
This commit is contained in:
Andre Henriques 2022-09-28 19:22:44 +02:00
commit 70ccfaa978
3 changed files with 22 additions and 7 deletions

View file

@ -256,6 +256,10 @@ class ArveData(BaseRequestHandler):
client_secret = self.settings['arve_client_secret']
arve_api_key = self.settings['arve_api_key']
if (client_id == None or client_secret == None or arve_api_key == None):
# If the credentials are not defined, we skip the ARVE API connection
return self.send_error(401)
http_client = AsyncHTTPClient()
URL = 'https://arveapi.auth.eu-central-1.amazoncognito.com/oauth2/token'
@ -345,9 +349,9 @@ def make_app(
# COOKIE_SECRET being undefined will result in no login information being
# presented to the user.
cookie_secret=os.environ.get('COOKIE_SECRET', '<undefined>'),
arve_client_id=os.environ.get('ARVE_CLIENT_ID', '<undefined>'),
arve_client_secret=os.environ.get('ARVE_CLIENT_SECRET', '<undefined>'),
arve_api_key=os.environ.get('ARVE_API_KEY', '<undefined>'),
arve_client_id=os.environ.get('ARVE_CLIENT_ID', None),
arve_client_secret=os.environ.get('ARVE_CLIENT_SECRET', None),
arve_api_key=os.environ.get('ARVE_API_KEY', None),
# Process parallelism controls. There is a balance between serving a single report
# requests quickly or serving multiple requests concurrently.

View file

@ -314,8 +314,15 @@ function show_sensors_data(url) {
success: function (result) {
DATA_FROM_SENSORS = result;
result.map(room => {
if (room['Details']['Online'] == false) return; // If the sensor is offline, it should not be added to the list.
$("#sensors").append(`<option id=${room.RoomId} value=${room.RoomId}>Sensor ${room.RoomId}</option>`);
});
if ($('#sensors > option').length == 0) {
$('#offline_sensors').show();
$('#DIVsensors_data').hide();
$('#arve_sensor_yes').prop('disabled', true)
return; // All sensors are offline
}
populate_temp_hum_values(result, 0);
if (url.searchParams.has('sensor_in_use')) {
$("#sensors").val(url.searchParams.get('sensor_in_use'));
@ -324,9 +331,11 @@ function show_sensors_data(url) {
}));
}
},
error: function() {
alert('Authentication Error - Something went wrong during the authentication process.');
},
error: function(_, _, errorThrown) {
$("#arve_api_error_message").val(errorThrown).show();
$('#DIVsensors_data').hide();
$('#arve_sensor_yes').prop('disabled', true)
}
});
}
};

View file

@ -14,7 +14,9 @@
<label for="arve_sensor_yes">Yes</label>
</div>
</div>
<div id="DIVsensors_data" style="display:none">
<p id="offline_sensors" class="red_text mb-2" style="display: none">All sensors are offline.</p>
<p id="arve_api_error_message" class="red_text mb-2" style="display:none; max-width: 85%;">Unauthorized - Something went wrong during the ARVE API authentication process.</p>
<div id="DIVsensors_data" class="mb-1" style="display:none">
<div class="form-group row mb-0">
<div class="col-sm-4"><label class="col-form-label">Sensor:</label></div>
<div class="col-sm-6">