open-vault/ui/app/serializers/role.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

46 lines
1.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
primaryKey: 'name',
// Used for both pki-role (soon to be deprecated) and role-ssh
extractLazyPaginatedData(payload) {
if (payload.zero_address_roles) {
payload.zero_address_roles.forEach((role) => {
// mutate key_info object to add zero_address info
payload.data.key_info[role].zero_address = true;
});
}
if (!payload.data.key_info) {
return payload.data.keys.map((key) => {
const model = {
name: key,
};
if (payload.backend) {
model.backend = payload.backend;
}
return model;
});
}
const ret = payload.data.keys.map((key) => {
const model = {
name: key,
key_type: payload.data.key_info[key].key_type,
zero_address: payload.data.key_info[key].zero_address,
};
if (payload.backend) {
model.backend = payload.backend;
}
return model;
});
delete payload.data.key_info;
return ret;
},
});