2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-08-28 00:54:30 +00:00
|
|
|
import ApplicationAdapter from './application';
|
|
|
|
|
|
|
|
export default ApplicationAdapter.extend({
|
|
|
|
createRecord(store, type, snapshot) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const ttl = snapshot.attr('ttl');
|
|
|
|
const roleArn = snapshot.attr('roleArn');
|
|
|
|
const roleType = snapshot.attr('credentialType');
|
2018-09-28 21:45:30 +00:00
|
|
|
let method = 'POST';
|
|
|
|
let options;
|
2022-11-09 23:15:31 +00:00
|
|
|
const 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
|
|
|
}
|
2022-11-09 23:15:31 +00:00
|
|
|
const role = snapshot.attr('role');
|
|
|
|
const url = `/v1/${role.backend}/creds/${role.name}`;
|
2018-08-28 00:54:30 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
return this.ajax(url, method, options).then((response) => {
|
2018-08-28 00:54:30 +00:00
|
|
|
response.id = snapshot.id;
|
|
|
|
response.modelName = type.modelName;
|
|
|
|
store.pushPayload(type.modelName, response);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|