open-nomad/ui/app/controllers/application.js
Buck Doyle 6d67e90763
Add exchange of one-time token on UI load (#10066)
This adds UI support for receiving the one-time token passed via query parameter, as in #10134
and related PRs, and exchanging it for its corresponding secret ID. When this works, it’s mostly
invisible, with a brief flash of the OTT onscreen.

The authentication failure message now suggests the -authenticate flag.

When OTT exchange fails, it shows a whole-page error.

This includes a known UX shortcoming in that the OTT will not disappear from the URL when an
identifier is specified on the command line, like nomad ui -authenticate jobname. The goal is to
address that shortcoming in a forthcoming pull request.
2021-04-01 13:21:30 -05:00

79 lines
1.7 KiB
JavaScript

/* eslint-disable ember/no-observers */
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
import { observes } from '@ember-decorators/object';
import { computed } from '@ember/object';
import Ember from 'ember';
import codesForError from '../utils/codes-for-error';
import NoLeaderError from '../utils/no-leader-error';
import OTTExchangeError from '../utils/ott-exchange-error';
import classic from 'ember-classic-decorator';
@classic
export default class ApplicationController extends Controller {
@service config;
@service system;
queryParams = [
{
region: 'region',
},
];
region = null;
error = null;
@computed('error')
get errorStr() {
return this.error.toString();
}
@computed('error')
get errorCodes() {
return codesForError(this.error);
}
@computed('errorCodes.[]')
get is403() {
return this.errorCodes.includes('403');
}
@computed('errorCodes.[]')
get is404() {
return this.errorCodes.includes('404');
}
@computed('errorCodes.[]')
get is500() {
return this.errorCodes.includes('500');
}
@computed('error')
get isNoLeader() {
const error = this.error;
return error instanceof NoLeaderError;
}
@computed('error')
get isOTTExchange() {
const error = this.error;
return error instanceof OTTExchangeError;
}
@observes('error')
throwError() {
if (this.get('config.isDev')) {
run.next(() => {
throw this.error;
});
} else if (!Ember.testing) {
run.next(() => {
// eslint-disable-next-line
console.warn('UNRECOVERABLE ERROR:', this.error);
});
}
}
}