Skip to content

Commit

Permalink
refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwowen committed Jul 19, 2024
1 parent b9b1c17 commit e640dd8
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h4 class="panel-title pull-left">Base Images Events</h4>
globalNotificationBanner.info = "Request sent successfully";
},
error: function (data) { // if error occured
globalNotificationBanner.error = data;
globalNotificationBanner.error = data.responseJSON.error;
},
});
});
Expand All @@ -72,7 +72,7 @@ <h4 class="panel-title pull-left">Base Images Events</h4>
globalNotificationBanner.info = "Request sent successfully";
},
error: function (data) { // if error occured
globalNotificationBanner.error = data;
globalNotificationBanner.error = data.responseJSON.error;
},
});
});
Expand Down Expand Up @@ -137,4 +137,4 @@ <h4 class="modal-title">Promote Image Confirm</h4>
</div>
</div>

{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
scope.imageNameChange(data[0]);
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});

Expand Down Expand Up @@ -697,7 +697,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
capacitySetting.selectedSecurityZoneValue = data[0]?.abstract_name;
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});

Expand All @@ -719,7 +719,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
placements ? placements.getFullList(false, cell == initialCell ? currentPlacements : null) : null;
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
})
},
Expand Down Expand Up @@ -747,7 +747,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
scope.imageNameChange(imageName);
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
// grab all the host types
Expand Down Expand Up @@ -777,7 +777,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
})
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down Expand Up @@ -811,7 +811,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
capacitySetting.pinImageEnabled = isPinImageEnabled(goldenImage);
},
error: function(data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down
4 changes: 2 additions & 2 deletions deploy-board/deploy_board/templates/configs/capacity.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
window.location.href=window.location.href
},
error: function(data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down Expand Up @@ -138,7 +138,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
window.location.href=window.location.href
},
error: function(data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down
11 changes: 3 additions & 8 deletions deploy-board/deploy_board/templates/configs/capacity.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,15 @@
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
if(data != null && data.success == false) {
globalNotificationBanner.error = data;
} else {
globalNotificationBanner.info = "Saved Successfully";
window.location.href='/env/{{ env.envName }}/{{ env.stageName }}/config/capacity/'
}
globalNotificationBanner.info = "Saved Successfully";
window.location.href='/env/{{ env.envName }}/{{ env.stageName }}/config/capacity/'
},
error: function (data) {
globalNotificationBanner.error = data;
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
}
}
)
</script>

17 changes: 6 additions & 11 deletions deploy-board/deploy_board/templates/configs/env_config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,15 @@
btn.button('loading');
},
success: function (data) {
if (data != null && data.success == false) {
$('#errorBannerId').append(data.error);
if ($('#stageTypeValueId').val() == 'DEFAULT') {
$('#errorBannerId').append("<a href='{{stage_type_info_link}}'>pinch/teletraan-stagetypes</a>");
}
$('#errorBannerId').show();
} else {
$("#envConfigId").parent().html(data.html);
$('#errorBannerId').empty().hide();
}
$("#envConfigId").parent().html(data.html);
$('#errorBannerId').empty().hide();
btn.button('reset');
},
error: function (data) {
$('#errorBannerId').append(data.responseText);
$('#errorBannerId').append(data.responseJSON.error);
if ($('#stageTypeValueId').val() == 'DEFAULT') {
$('#errorBannerId').append("<a href='{{stage_type_info_link}}'>pinch/teletraan-stagetypes</a>");
}
$('#errorBannerId').show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
onSuccess(data)
},
error: function(data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down Expand Up @@ -322,7 +322,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
scope.imageNameChange(data && data.length > 0 ? data[0] : null);
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});

Expand Down Expand Up @@ -351,7 +351,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
capacitySetting.selectedSecurityZoneValue = data && data.length > 0 ? data[0].abstract_name : null;
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});

Expand All @@ -373,7 +373,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
capacitySetting.placements = placements ? placements.getFullList(false, null) : null;
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand All @@ -400,7 +400,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
scope.imageNameChange(imageName);
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
// grab all the host types
Expand All @@ -424,7 +424,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
})
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down Expand Up @@ -458,7 +458,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
capacitySetting.pinImageEnabled = isPinImageEnabled(goldenImage);
},
error: function (data) {
globalNotificationBanner.error = data
globalNotificationBanner.error = data.responseJSON.error;
}
});
},
Expand Down
5 changes: 3 additions & 2 deletions deploy-board/deploy_board/templates/error.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div class="panel panel-default">
<div class="alert alert-danger" role="alert">{{ message }}</div>
<div class="alert" role="alert">Sorry for the inconvenience, please contact your friendly Teletraan owners for
immediate assistance!</div>
<div class="alert" role="alert">
Sorry for the inconvenience, please read the error message. If the problem persists, please contact your friendly Teletraan owners for further assistance.
</div>
<div class="alert alert-danger" role="alert">
<pre>
{{ stacktrace }}
Expand Down
5 changes: 2 additions & 3 deletions deploy-board/deploy_board/webapp/helpers/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ def api(path, token=None, params=None, data=None):

if response.status_code == 401:
raise FailedAuthenticationException(
"Oops! Teletraan was unable to authenticate you. Contact an environment ADMIN for "
"assistance. " + response.text)
f"Oops! Teletraan was unable to authenticate you. Please re-login. Server message: {response.json()['message']}")

if response.status_code == 403:
raise NotAuthorizedException(f'{UNAUTHORIZED_ERROR_TEXT}: {response.text}')
raise NotAuthorizedException(f"{UNAUTHORIZED_ERROR_TEXT}. Server message: {response.json()['message']}")

if response.status_code == 400 or response.status_code == 422:
raise IllegalArgumentException(response.text)
Expand Down
11 changes: 5 additions & 6 deletions deploy-board/deploy_board/webapp/helpers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
# -*- coding: utf-8 -*-
"""Backend server all exception
"""


class FailedAuthenticationException(Exception):
pass


class NotFoundException(Exception):
pass

Expand All @@ -35,6 +29,11 @@ class IllegalArgumentException(TeletraanException):
def __init__(self, message: str) -> None:
super().__init__(message, status=400)

class FailedAuthenticationException(TeletraanException):
def __init__(self, message: str) -> None:
super().__init__(message, status=401)


class NotAuthorizedException(TeletraanException):
def __init__(self, message: str) -> None:
super().__init__(message, status=403)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.dropwizard.auth.AuthFilter;
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.CachingAuthenticator;
import io.dropwizard.auth.JSONUnauthorizedHandler;
import io.dropwizard.auth.chained.ChainedAuthFilter;
import java.util.Arrays;
import javax.ws.rs.container.ContainerRequestFilter;
Expand All @@ -50,6 +51,7 @@ public ContainerRequestFilter create(TeletraanServiceContext context) throws Exc
new EnvoyAuthFilter.Builder<TeletraanPrincipal>()
.setAuthenticator(authenticator)
.setAuthorizer(context.getAuthorizationFactory().create(context))
.setUnauthorizedHandler(new JSONUnauthorizedHandler())
.buildAuthFilter();

return new ChainedAuthFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.dropwizard.auth.Authenticator;
import io.dropwizard.auth.Authorizer;
import io.dropwizard.auth.CachingAuthenticator;
import io.dropwizard.auth.JSONUnauthorizedHandler;
import io.dropwizard.auth.chained.ChainedAuthFilter;
import io.dropwizard.auth.oauth.OAuthCredentialAuthFilter;
import java.util.Arrays;
Expand Down Expand Up @@ -115,6 +116,7 @@ AuthFilter<String, ScriptTokenPrincipal<ValueBasedRole>> createScriptTokenAuthFi
context.getAuthorizationFactory()
.create(context, ServicePrincipal.class))
.setPrefix("token")
.setUnauthorizedHandler(new JSONUnauthorizedHandler())
.buildAuthFilter();
}

Expand All @@ -135,6 +137,7 @@ AuthFilter<String, UserPrincipal> createOauthTokenAuthFilter(TeletraanServiceCon
context.getAuthorizationFactory()
.create(context, UserPrincipal.class))
.setPrefix("token")
.setUnauthorizedHandler(new JSONUnauthorizedHandler())
.buildAuthFilter();
}

Expand All @@ -152,6 +155,7 @@ AuthFilter<String, UserPrincipal> createJwtTokenAuthFilter(TeletraanServiceConte
(Authorizer<UserPrincipal>) context.getAuthorizationFactory()
.create(context, UserPrincipal.class))
.setPrefix("Bearer")
.setUnauthorizedHandler(new JSONUnauthorizedHandler())
.buildAuthFilter();
}
}

0 comments on commit e640dd8

Please sign in to comment.