2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-10-01 08:33:22 +00:00
|
|
|
import Route from 'consul-ui/routing/route';
|
2021-09-15 18:50:11 +00:00
|
|
|
import { action } from '@ember/object';
|
2022-03-09 08:29:27 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2018-12-04 17:01:59 +00:00
|
|
|
|
|
|
|
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
export default class ApplicationRoute extends Route.extend(WithBlockingActions) {
|
2022-03-09 08:29:27 +00:00
|
|
|
@service('client/http') client;
|
2022-09-08 10:43:39 +00:00
|
|
|
@service('env') env;
|
2022-10-18 14:16:42 +00:00
|
|
|
@service() hcp;
|
2022-03-09 08:29:27 +00:00
|
|
|
|
|
|
|
data;
|
|
|
|
|
2022-09-08 10:43:39 +00:00
|
|
|
async model() {
|
2022-09-15 08:43:17 +00:00
|
|
|
if (this.env.var('CONSUL_ACLS_ENABLED')) {
|
2022-10-18 14:16:42 +00:00
|
|
|
await this.hcp.updateTokenIfNecessary(this.env.var('CONSUL_HTTP_TOKEN'));
|
2022-09-08 10:43:39 +00:00
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-03-09 08:29:27 +00:00
|
|
|
@action
|
|
|
|
onClientChanged(e) {
|
|
|
|
let data = e.data;
|
2022-09-15 08:43:17 +00:00
|
|
|
if (data === '') {
|
2022-03-09 08:29:27 +00:00
|
|
|
data = { blocking: true };
|
|
|
|
}
|
|
|
|
// this.data is always undefined first time round and its the 'first read'
|
|
|
|
// of the value so we don't need to abort anything
|
2022-09-15 08:43:17 +00:00
|
|
|
if (typeof this.data === 'undefined') {
|
2022-03-09 08:29:27 +00:00
|
|
|
this.data = Object.assign({}, data);
|
|
|
|
return;
|
|
|
|
}
|
2022-09-15 08:43:17 +00:00
|
|
|
if (this.data.blocking === true && data.blocking === false) {
|
2022-03-09 08:29:27 +00:00
|
|
|
this.client.abort();
|
|
|
|
}
|
|
|
|
this.data = Object.assign({}, data);
|
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@action
|
|
|
|
error(e, transition) {
|
|
|
|
// TODO: Normalize all this better
|
|
|
|
let error = {
|
|
|
|
status: e.code || e.statusCode || '',
|
|
|
|
message: e.message || e.detail || 'Error',
|
|
|
|
};
|
|
|
|
if (e.errors && e.errors[0]) {
|
|
|
|
error = e.errors[0];
|
|
|
|
error.message = error.message || error.title || error.detail || 'Error';
|
|
|
|
}
|
|
|
|
if (error.status === '') {
|
|
|
|
error.message = 'Error';
|
|
|
|
}
|
|
|
|
this.controllerFor('application').setProperties({ error: error });
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|