Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
model(params) {
let { section } = params;
let itemType = this.modelFor('vault.cluster.access.identity') + '-alias';
let tabs = TABS[itemType];
let modelType = `identity/${itemType}`;
if (!tabs.includes(section)) {
const error = new AdapterError();
set(error, 'httpStatus', 404);
throw error;
}
// TODO peekRecord here to see if we have the record already
return hash({
model: this.store.findRecord(modelType, params.item_alias_id),
section,
});
},
model(params) {
let { section } = params;
let itemType = this.modelFor('vault.cluster.access.identity');
let tabs = TABS[itemType];
let modelType = `identity/${itemType}`;
if (!tabs.includes(section)) {
const error = new AdapterError();
set(error, 'httpStatus', 404);
throw error;
}
// if the record is in the store use that
let model = this.store.peekRecord(modelType, params.item_id);
// if we don't have creationTime, we only have a partial model so reload
if (model && !model.get('creationTime')) {
model = model.reload();
}
// if there's no model, we need to fetch it
if (!model) {
model = this.store.findRecord(modelType, params.item_id);
}
import JSONAPIAdapter from "@ember-data/adapter/json-api";
import { computed } from "@ember/object";
import { pluralize } from "ember-inflector";
import { underscore } from "@ember/string";
import ENV from "../config/environment";
export default JSONAPIAdapter.extend({
namespace: "api",
pathForType(type) {
return pluralize(underscore(type));
},
headers: computed(function () {
/* eslint-disable no-undef */
return {
"X-CSRF-Token": ENV.CSRFToken,
"content-type": "application/json"
};
/* eslint-enable no-undef */
})
});
import RESTAdapter from '@ember-data/adapter/rest';
import flatten from 'lodash-es/flatten';
import isArray from 'lodash-es/isArray';
import isPlainObject from 'lodash-es/isPlainObject';
import isString from 'lodash-es/isString';
export default RESTAdapter.extend({
// Build the URL using the customizable "urlRoot" attribute that can be set
// on the model class.
buildURL(modelName, id, snapshot) {
if(snapshot && snapshot.type && snapshot.type.urlRoot) {
let url = snapshot.type.urlRoot;
if(id) {
url += '/' + encodeURIComponent(id);
}
return url;
} else {
return this._super(...arguments);
}
},
// Ember data requires that errors from the API be returned as an array. This
import RESTAdapter from '@ember-data/adapter/rest';
import { inject as service } from '@ember/service';
import AdapterFetch from 'ember-fetch/mixins/adapter-fetch';
export default RESTAdapter.extend(AdapterFetch, {
encryption: service(),
// set namespace to api.php in same subdirectory
namespace:
window.location.pathname
// remove index.html if it's there
.replace(/index.html$/, '')
// remove tests prefix which is added by testem (starting with a number)
.replace(/\/\d+\/tests/, '')
// remove tests prefix which is added by tests run in browser
.replace(/tests/, '')
// remove leading and trailing slash
.replace(/\/$/, '')
// add api.php
.concat('/api/index.php')
// remove leading slash
export default RESTAdapter.extend({
headers: computed(function() {
return {
'API_KEY': get(document.cookie.match(/apiKey\=([^;]*)/), '1'),
'ANOTHER_HEADER': 'Some header value'
};
}).volatile()
});
@class RESTAdapter @constructor @extends Adapter @uses BuildURLMixin */ const RESTAdapter = Adapter.extend(BuildURLMixin, { defaultSerializer: '-rest',
_defaultContentType: 'application/json; charset=utf-8',
fastboot: computed({ // Avoid computed property override deprecation in fastboot as suggested by: // https://deprecations.emberjs.com/v3.x/#toc_computed-property-override get() { if (this._fastboot) { return this._fastboot; } return (this._fastboot = getOwner(this).lookup('service:fastboot')); }, set(key, value) { return (this._fastboot = value); },
model(params) {
let model = MODEL_FROM_PARAM[params.item_type];
if (!model) {
const error = new AdapterError();
set(error, 'httpStatus', 404);
throw error;
}
return model;
},
});
model(params) {
const { section_name: section } = params;
if (section !== 'configuration') {
const error = new AdapterError();
set(error, 'httpStatus', 404);
throw error;
}
let backend = this.modelFor('vault.cluster.access.method');
this.wizard.transitionFeatureMachine(this.wizard.featureState, 'DETAILS', backend.type);
return backend;
},
return this.store.findAll('auth-method').then(modelArray => {
const model = modelArray.findBy('id', path);
if (!model) {
const error = new AdapterError();
set(error, 'httpStatus', 404);
throw error;
}
return this.pathHelp.getPaths(model.apiPath, path).then(paths => {
model.set('paths', paths);
return model;
});
});
},
switch (status) {
case 401:
return new UnauthorizedError(errors, detailedMessage);
case 403:
return new ForbiddenError(errors, detailedMessage);
case 404:
return new NotFoundError(errors, detailedMessage);
case 409:
return new ConflictError(errors, detailedMessage);
default:
if (status >= 500) {
return new ServerError(errors, detailedMessage);
}
}
return new AdapterError(errors, detailedMessage);
},