2018-09-25 16:28:26 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import { get, set } from '@ember/object';
|
2018-04-03 14:16:57 +00:00
|
|
|
import ApplicationAdapter from './application';
|
|
|
|
import DS from 'ember-data';
|
|
|
|
|
|
|
|
export default ApplicationAdapter.extend({
|
|
|
|
url(path) {
|
|
|
|
const url = `${this.buildURL()}/auth`;
|
|
|
|
return path ? url + '/' + path : url;
|
|
|
|
},
|
|
|
|
|
|
|
|
// used in updateRecord on the model#tune action
|
|
|
|
pathForType() {
|
|
|
|
return 'mounts/auth';
|
|
|
|
},
|
|
|
|
|
2018-07-05 18:28:12 +00:00
|
|
|
findAll(store, type, sinceToken, snapshotRecordArray) {
|
2018-09-25 16:28:26 +00:00
|
|
|
let isUnauthenticated = get(snapshotRecordArray || {}, 'adapterOptions.unauthenticated');
|
2018-07-05 18:28:12 +00:00
|
|
|
if (isUnauthenticated) {
|
|
|
|
let url = `/${this.urlPrefix()}/internal/ui/mounts`;
|
|
|
|
return this.ajax(url, 'GET', {
|
|
|
|
unauthenticated: true,
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
return {
|
|
|
|
data: result.data.auth,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2018-08-16 17:48:24 +00:00
|
|
|
return {
|
|
|
|
data: {},
|
|
|
|
};
|
2018-07-05 18:28:12 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
return this.ajax(this.url(), 'GET').catch(e => {
|
|
|
|
if (e instanceof DS.AdapterError) {
|
2018-09-25 16:28:26 +00:00
|
|
|
set(e, 'policyPath', 'sys/auth');
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
createRecord(store, type, snapshot) {
|
|
|
|
const serializer = store.serializerFor(type.modelName);
|
|
|
|
const data = serializer.serialize(snapshot);
|
|
|
|
const path = snapshot.attr('path');
|
|
|
|
|
|
|
|
return this.ajax(this.url(path), 'POST', { data }).then(() => {
|
|
|
|
// ember data doesn't like 204s if it's not a DELETE
|
|
|
|
return {
|
2018-09-25 16:28:26 +00:00
|
|
|
data: assign({}, data, { path: path + '/', id: path }),
|
2018-04-03 14:16:57 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
urlForDeleteRecord(id, modelName, snapshot) {
|
|
|
|
return this.url(snapshot.id);
|
|
|
|
},
|
2019-02-14 15:39:19 +00:00
|
|
|
|
|
|
|
exchangeOIDC(path, state, code) {
|
|
|
|
return this.ajax(`/v1/auth/${path}/oidc/callback`, 'GET', { data: { state, code } });
|
|
|
|
},
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|