github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/adapters/token.js (about) 1 import { inject as service } from '@ember/service'; 2 import { default as ApplicationAdapter, namespace } from './application'; 3 import OTTExchangeError from '../utils/ott-exchange-error'; 4 import classic from 'ember-classic-decorator'; 5 6 @classic 7 export default class TokenAdapter extends ApplicationAdapter { 8 @service store; 9 10 namespace = namespace + '/acl'; 11 12 findSelf() { 13 return this.ajax(`${this.buildURL()}/token/self`, 'GET').then((token) => { 14 const store = this.store; 15 store.pushPayload('token', { 16 tokens: [token], 17 }); 18 19 return store.peekRecord('token', store.normalize('token', token).data.id); 20 }); 21 } 22 23 exchangeOneTimeToken(oneTimeToken) { 24 return this.ajax(`${this.buildURL()}/token/onetime/exchange`, 'POST', { 25 data: { 26 OneTimeSecretID: oneTimeToken, 27 }, 28 }) 29 .then(({ Token: token }) => { 30 const store = this.store; 31 store.pushPayload('token', { 32 tokens: [token], 33 }); 34 35 return store.peekRecord( 36 'token', 37 store.normalize('token', token).data.id 38 ); 39 }) 40 .catch(() => { 41 throw new OTTExchangeError(); 42 }); 43 } 44 }