Skip to content

Commit

Permalink
Use new function in TA generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dasansol92 committed Dec 16, 2021
1 parent 0eb7b63 commit 769f286
Showing 1 changed file with 3 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
} from '../../../../fleet/common';
import { newTrustedAppToCreateExceptionListItem } from '../../../public/management/pages/trusted_apps/service/mappers';
import { randomPolicyIdGenerator } from '../common/random_policy_id_generator';

const defaultLogger = new ToolingLog({ level: 'info', writeTo: process.stdout });
const separator = '----------------------------------------';
Expand Down Expand Up @@ -88,35 +89,9 @@ export const run: (options?: RunOptions) => Promise<TrustedApp[]> = async ({
// and
// and ensure the trusted apps list is created
logger.info('setting up Fleet with endpoint and creating trusted apps list');
const [installedEndpointPackage] = await Promise.all([
setupFleetForEndpoint(kbnClient).then((response) => response.endpointPackage),

ensureCreateEndpointTrustedAppsList(kbnClient),
]);

// Setup a list of real endpoint policies and return a method to randomly select one
const randomPolicyId: () => string = await (async () => {
const randomN = (max: number): number => Math.floor(Math.random() * max);
const policyIds: string[] =
(await fetchEndpointPolicies(kbnClient)).data.items.map((policy) => policy.id) || [];

// If the number of existing policies is less than 5, then create some more policies
if (policyIds.length < 5) {
for (let i = 0, t = 5 - policyIds.length; i < t; i++) {
policyIds.push(
(
await indexFleetEndpointPolicy(
kbnClient,
`Policy for Trusted App assignment ${i + 1}`,
installedEndpointPackage.version
)
).integrationPolicies[0].id
);
}
}
ensureCreateEndpointTrustedAppsList(kbnClient);

return () => policyIds[randomN(policyIds.length)];
})();
const randomPolicyId = await randomPolicyIdGenerator(kbnClient, logger);

return pMap(
Array.from({ length: count }),
Expand Down

0 comments on commit 769f286

Please sign in to comment.