Skip to content

Commit

Permalink
F #3951: Only FireEdge features when FireEdge configured (#953)
Browse files Browse the repository at this point in the history
Signed-off-by: Frederick Borges <[email protected]>
  • Loading branch information
Frederick Borges authored Mar 11, 2021
1 parent ec5c2c6 commit 6ca3799
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 59 deletions.
52 changes: 26 additions & 26 deletions src/sunstone/public/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ var _commonDialogs = [
// $('#loading').hide();
//});

$(document).ready(function() {
Sunstone.addDialogs(_commonDialogs);
Sunstone.addMainTabs();
Sunstone.insertTabs();

if (Config.isTabEnabled(PROVISION_TAB_ID)){
Menu.insertProvision();
}else{
Menu.insert();
Sunstone.setupNavigoRoutes();
}

_setupAccordion();
_setupCloseDropdownsOnClick();
_insertUserAndZoneSelector();

if (Config.isTabEnabled(PROVISION_TAB_ID)) {
Sunstone.showTab(PROVISION_TAB_ID);
}

var create_socket = function(token){
if (Websocket.disconnected()){
Websocket.start(token);
}
}
$(document).ready(function() {
Sunstone.addDialogs(_commonDialogs);
Sunstone.addMainTabs();
Sunstone.insertTabs();

if (Config.isTabEnabled(PROVISION_TAB_ID)){
Menu.insertProvision();
}else{
Menu.insert();
Sunstone.setupNavigoRoutes();
}

_setupAccordion();
_setupCloseDropdownsOnClick();
_insertUserAndZoneSelector();

if (Config.isTabEnabled(PROVISION_TAB_ID)) {
Sunstone.showTab(PROVISION_TAB_ID);
}

var create_socket = function(token){
if (Websocket.disconnected()){
Websocket.start(token);
}
}

FireedgeValidator.checkFireedgePublicURL(FireedgeValidator.validateFireedgeToken, create_socket);
FireedgeValidator.checkFireedgePublicURL(FireedgeValidator.validateFireedgeToken, create_socket);

$('#loading').hide();
});
Expand Down
4 changes: 2 additions & 2 deletions src/sunstone/public/app/tabs/vms-tab/hooks/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ define(function(require) {
}

var show_buttons = function(fireedgeToken) {
if (fireedgeToken != "") {
if ((fireedgeToken && fireedgeToken != "") || is_fireedge_configured) {
show_fireedge_buttons();
}
else{
show_noVNC_buttons();
}
}

FireedgeValidator.validateFireedgeToken(show_buttons, show_noVNC_buttons);
FireedgeValidator.validateFireedgeToken(show_buttons, show_buttons);
}


Expand Down
43 changes: 17 additions & 26 deletions src/sunstone/public/app/utils/fireedge-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ define(function (require) {
// user config
const fireedge_endpoint = Config.publicFireedgeEndpoint;

const STATUS = {
DISCONNECTED: 0,
CONNECTED: 1,
PROCESSING: 2
};

var connection = STATUS.DISCONNECTED;

var _connected = function(){
return connection == STATUS.CONNECTED;
};

var _disconnected = function(){
return connection == STATUS.DISCONNECTED;
};

var _processing = function(){
return connection == STATUS.PROCESSING;
};

/**
* Aux function to change the fireedge_token value.
*
Expand All @@ -65,7 +45,12 @@ define(function (require) {
* be "".
*/
var _validate_fireedge_token = function(success, error) {
if (is_fireedge_configured && fireedge_token == "" && fireedge_endpoint){
/*
* sunstone_fireedge_active is a variable to control if we already did
* validations. If that variable is true, that means that fireedge
* endpoint was working last time we checked it.
*/
if (sunstone_fireedge_active && fireedge_token == "" && fireedge_endpoint){
$.ajax({
url: "/fireedge",
type: "GET",
Expand All @@ -77,19 +62,25 @@ define(function (require) {
},
error: function(request, response, data) {
Notifier.onError(request, {error:{ message: "FireEdge private endpoint is not working, please contact your cloud administrator"}});
is_fireedge_configured = false;
sunstone_fireedge_active = false;
clear_fireedge_token();
if (typeof error === "function"){
error();
}
}
});
}
else if (is_fireedge_configured){
/**
* is_fireedge_configured is a variable to control if fireedge
* configurations are available on sunstone-server.conf.
* If they are available then we must use fireedge for everything.
*/
else if (sunstone_fireedge_active || is_fireedge_configured){
if (typeof success === "function"){
success(fireedge_token);
}
}
// If fireedge it is not available and not configured then we dont use it
else{
if (typeof error === "function"){
error();
Expand All @@ -103,22 +94,22 @@ define(function (require) {
url: fireedge_endpoint,
type: "GET",
success: function() {
is_fireedge_configured = true;
sunstone_fireedge_active = true;
if (typeof success === "function" && typeof aux === "function"){
success(aux);
}
},
error: function(request, response, data) {
Notifier.onError(request, {error:{ message: "FireEdge public endpoint is not working, please contact your cloud administrator"}});
is_fireedge_configured = false;
sunstone_fireedge_active = false;
if (typeof error === "function"){
error();
}
}
});
}
else {
is_fireedge_configured = false;
sunstone_fireedge_active = false;
if (typeof error === "function"){
error();
}
Expand Down
6 changes: 1 addition & 5 deletions src/sunstone/public/app/utils/remote-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,8 @@ define(function(require) {
id: data.id,
success: function(response) {
FireedgeValidator.validateFireedgeToken(
function(fireedgeToken) {
if (fireedgeToken !== '') {
function() {
OpenNebulaVM.isVMRCSupported(response) ? _callVMRC(data) : _callGuacVNC(data)
} else {
_callVNC(data)
}
},
function() {
_callVNC(data)
Expand Down
1 change: 1 addition & 0 deletions src/sunstone/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var csrftoken = '<%= session[:csrftoken] %>';
var fireedge_token = '<%= session[:fireedge_token] %>';
var is_fireedge_configured = <%= !$conf[:public_fireedge_endpoint].nil? && !$conf[:private_fireedge_endpoint].nil? %>
var sunstone_fireedge_active = is_fireedge_configured;
var view = JSON.parse('<%= view.to_json %>')
var available_views = JSON.parse('["<%=
$views_config.available_views(session[:user], session[:user_gname]).join('","')
Expand Down

0 comments on commit 6ca3799

Please sign in to comment.