Files
threshold-ui/addons/api/mirage/factories/credential-library.js
T

45 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2021-07-12 16:03:06 -04:00
import factory from '../generated/factories/credential-library';
import { faker } from '@faker-js/faker';
import permissions from '../helpers/permissions';
2022-06-01 14:02:18 -04:00
import generateId from '../helpers/id';
2023-02-01 13:46:23 -05:00
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
TYPES_CREDENTIAL_LIBRARY,
} from 'api/models/credential-library';
2021-07-27 11:52:02 -04:00
2021-07-12 16:03:06 -04:00
export default factory.extend({
2022-06-01 14:02:18 -04:00
id: () => generateId('cl_'),
2023-02-01 13:46:23 -05:00
type: (i) => TYPES_CREDENTIAL_LIBRARY[i % TYPES_CREDENTIAL_LIBRARY.length],
2021-07-12 16:03:06 -04:00
authorized_actions: () =>
permissions.authorizedActionsFor('credential-library') || [
'no-op',
'read',
'update',
'delete',
],
2021-07-12 16:03:06 -04:00
attributes() {
2021-07-27 11:52:02 -04:00
switch (this.type) {
2023-02-01 13:46:23 -05:00
case TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC:
2021-07-27 11:52:02 -04:00
return {
http_method: 'GET',
http_request_body: faker.random.word(),
path: faker.system.directoryPath(),
2021-07-27 11:52:02 -04:00
};
2023-02-01 13:46:23 -05:00
case TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE:
return {
username: faker.random.word(),
key_type: faker.random.word(),
key_bits: faker.datatype.number(999),
path: faker.system.directoryPath(),
};
2021-07-27 11:52:02 -04:00
}
2021-07-12 16:03:06 -04:00
},
});