1d65f9e41a
* ui: Adds model layer required for SSO 1. oidc-provider ember-data triplet plus repo, plus addition of torii addon 2. Make blocking queries support a Cache-Control: no-cache header 3. Tweaks to the token model layer in preparation for SSO work * Fix up meta related Cache-Control tests * Add tests adapter tests for URL shapes * Reset Cache-Control to the original value, return something from logout
60 lines
2 KiB
JavaScript
60 lines
2 KiB
JavaScript
import Serializer from './application';
|
|
import { get } from '@ember/object';
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/token';
|
|
|
|
import WithPolicies from 'consul-ui/mixins/policy/as-many';
|
|
import WithRoles from 'consul-ui/mixins/role/as-many';
|
|
|
|
export default Serializer.extend(WithPolicies, WithRoles, {
|
|
primaryKey: PRIMARY_KEY,
|
|
slugKey: SLUG_KEY,
|
|
serialize: function(snapshot, options) {
|
|
let data = this._super(...arguments);
|
|
// If a token has Rules, use the old API shape
|
|
// notice we use a null check here (not an undefined check)
|
|
// as we are dealing with the serialized model not raw user data
|
|
if (data['Rules'] !== null) {
|
|
data = {
|
|
ID: data.SecretID,
|
|
Name: data.Description,
|
|
Type: data.Type,
|
|
Rules: data.Rules,
|
|
};
|
|
}
|
|
// make sure we never send the SecretID
|
|
// TODO: If we selectively format the request payload in the adapter
|
|
// we won't have to do this here
|
|
// see side note in https://github.com/hashicorp/consul/pull/6285
|
|
// which will mean most if not all of this method can go
|
|
if (data) {
|
|
delete data['SecretID'];
|
|
}
|
|
return data;
|
|
},
|
|
respondForSelf: function(respond, query) {
|
|
return this.respondForQueryRecord(respond, query);
|
|
},
|
|
respondForUpdateRecord: function(respond, serialized, data) {
|
|
return this._super(
|
|
cb =>
|
|
respond((headers, body) => {
|
|
// Sometimes we get `Policies: null`, make null equal an empty array
|
|
if (typeof body.Policies === 'undefined' || body.Policies === null) {
|
|
body.Policies = [];
|
|
}
|
|
// Convert an old style update response to a new style
|
|
if (typeof body['ID'] !== 'undefined') {
|
|
const item = this.store.peekAll('token').findBy('SecretID', body['ID']);
|
|
if (item) {
|
|
body['SecretID'] = body['ID'];
|
|
body['AccessorID'] = get(item, 'AccessorID');
|
|
}
|
|
}
|
|
return cb(headers, body);
|
|
}),
|
|
serialized,
|
|
data
|
|
);
|
|
},
|
|
});
|