mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
* basic-functionality demo for token CRUD * Styling for tokens crud * Tokens crud styles * Expires, not expiry * Mobile styles etc * Refresh and redirect rules for policy save and token creation * Delete method and associated serializer change * Ability-checking for tokens * Update policies acceptance tests to reflect new redirect rules * Token ability unit tests * Mirage config methods for token crud * Token CRUD acceptance tests * A couple visual diff snapshots * Add and Delete abilities referenced for token operations * Changing timeouts and adding a copy to clipboard action * replaced accessor with secret when copying to clipboard * PR comments addressed * Simplified error passing for policy editor
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { default as ApplicationAdapter, namespace } from './application';
|
|
import OTTExchangeError from '../utils/ott-exchange-error';
|
|
import classic from 'ember-classic-decorator';
|
|
import { singularize } from 'ember-inflector';
|
|
|
|
@classic
|
|
export default class TokenAdapter extends ApplicationAdapter {
|
|
@service store;
|
|
|
|
namespace = namespace + '/acl';
|
|
|
|
createRecord(_store, type, snapshot) {
|
|
let data = this.serialize(snapshot);
|
|
data.Policies = data.PolicyIDs;
|
|
return this.ajax(`${this.buildURL()}/token`, 'POST', { data });
|
|
}
|
|
|
|
// Delete at /token instead of /tokens
|
|
urlForDeleteRecord(identifier, modelName) {
|
|
return `${this.buildURL()}/${singularize(modelName)}/${identifier}`;
|
|
}
|
|
|
|
findSelf() {
|
|
return this.ajax(`${this.buildURL()}/token/self`, 'GET').then((token) => {
|
|
const store = this.store;
|
|
store.pushPayload('token', {
|
|
tokens: [token],
|
|
});
|
|
|
|
return store.peekRecord('token', store.normalize('token', token).data.id);
|
|
});
|
|
}
|
|
|
|
exchangeOneTimeToken(oneTimeToken) {
|
|
return this.ajax(`${this.buildURL()}/token/onetime/exchange`, 'POST', {
|
|
data: {
|
|
OneTimeSecretID: oneTimeToken,
|
|
},
|
|
})
|
|
.then(({ Token: token }) => {
|
|
const store = this.store;
|
|
store.pushPayload('token', {
|
|
tokens: [token],
|
|
});
|
|
|
|
return store.peekRecord(
|
|
'token',
|
|
store.normalize('token', token).data.id
|
|
);
|
|
})
|
|
.catch(() => {
|
|
throw new OTTExchangeError();
|
|
});
|
|
}
|
|
}
|