Skip to content

Commit

Permalink
Merge branch 'feature/ARVE_authentication_verification' into 'master'
Browse files Browse the repository at this point in the history
Added verifications for the ARVE API

See merge request cara/caimira!400
  • Loading branch information
andrejhenriques committed Sep 28, 2022
2 parents 2730a50 + 7dd45aa commit 70ccfaa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 7 additions & 3 deletions caimira/apps/calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ async def get(self, hotel_id, floor_id):
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'
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 12 additions & 3 deletions caimira/apps/calculator/static/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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)
}
});
}
};
Expand Down
4 changes: 3 additions & 1 deletion caimira/apps/templates/cern/calculator.form.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 70ccfaa

Please sign in to comment.