2018-08-28 00:54:30 +00:00
|
|
|
import ApplicationAdapter from './application';
|
|
|
|
|
|
|
|
export default ApplicationAdapter.extend({
|
|
|
|
createRecord(store, type, snapshot) {
|
|
|
|
let ttl = snapshot.attr('ttl');
|
|
|
|
let roleArn = snapshot.attr('roleArn');
|
2018-09-28 21:45:30 +00:00
|
|
|
let roleType = snapshot.attr('credentialType');
|
|
|
|
let method = 'POST';
|
|
|
|
let options;
|
2018-08-28 00:54:30 +00:00
|
|
|
let data = {};
|
2018-09-28 21:45:30 +00:00
|
|
|
if (roleType === 'iam_user') {
|
|
|
|
method = 'GET';
|
|
|
|
} else {
|
|
|
|
if (ttl !== undefined) {
|
|
|
|
data.ttl = ttl;
|
|
|
|
}
|
|
|
|
if (roleType === 'assumed_role' && roleArn) {
|
|
|
|
data.role_arn = roleArn;
|
|
|
|
}
|
|
|
|
options = data.ttl || data.role_arn ? { data } : {};
|
2018-08-28 00:54:30 +00:00
|
|
|
}
|
|
|
|
let role = snapshot.attr('role');
|
|
|
|
let url = `/v1/${role.backend}/creds/${role.name}`;
|
|
|
|
|
|
|
|
return this.ajax(url, method, options).then(response => {
|
|
|
|
response.id = snapshot.id;
|
|
|
|
response.modelName = type.modelName;
|
|
|
|
store.pushPayload(type.modelName, response);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|