Skip to content

Commit be5a1bf

Browse files
authored
feat: optimize vault call (#65)
* feat: optimize vault call * fix: test
1 parent cc58630 commit be5a1bf

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/vault/vault-policy.controller.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('vault-policy.controller', () => {
1515
const vault = {
1616
read: jest.fn(),
1717
write: jest.fn(),
18+
policies: jest.fn(() => Promise.resolve({ data: { policies: [] } })),
1819
} as unknown as nv.client;
1920

2021
const mockRegistrationService = {

src/vault/vault-policy.controller.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ export default class VaultPolicyController {
2929
* Syncs policies to vault
3030
*/
3131
public async sync(root: string[]): Promise<void> {
32+
const policies = (await this.vault.policies()).data.policies as string[];
3233
for (const policyRoot of this.policyRootServices) {
3334
if (root.length === 0 || root[0] === policyRoot.getName()) {
3435
this.logger.info(`- Sync ${policyRoot.getName()}`);
3536
const specs = await policyRoot.build();
3637
for (const spec of specs) {
3738
await this.addPolicy(spec);
3839
}
39-
await this.removeUnregisteredPolicies(policyRoot.getName(), false);
40+
await this.removeUnregisteredPolicies(
41+
policies,
42+
policyRoot.getName(),
43+
false,
44+
);
4045
}
4146
}
4247
await this.registrationService.clear();
@@ -69,11 +74,10 @@ export default class VaultPolicyController {
6974
* @param partialRegistration True if not all policies were registered this run and false otherwise
7075
*/
7176
public async removeUnregisteredPolicies(
77+
policies: string[],
7278
group: string,
7379
partialRegistration: boolean,
7480
): Promise<void> {
75-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- No typing avialable
76-
const policies = (await this.vault.policies()).data.policies as string[];
7781
try {
7882
const policiesToRemove =
7983
await this.registrationService.filterNamesForUnregistered(

0 commit comments

Comments
 (0)