Skip to content

Commit

Permalink
feat: optimize vault call (#65)
Browse files Browse the repository at this point in the history
* feat: optimize vault call

* fix: test
  • Loading branch information
mbystedt authored Jun 17, 2024
1 parent cc58630 commit be5a1bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/vault/vault-policy.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('vault-policy.controller', () => {
const vault = {
read: jest.fn(),
write: jest.fn(),
policies: jest.fn(() => Promise.resolve({ data: { policies: [] } })),
} as unknown as nv.client;

const mockRegistrationService = {
Expand Down
10 changes: 7 additions & 3 deletions src/vault/vault-policy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ export default class VaultPolicyController {
* Syncs policies to vault
*/
public async sync(root: string[]): Promise<void> {
const policies = (await this.vault.policies()).data.policies as string[];
for (const policyRoot of this.policyRootServices) {
if (root.length === 0 || root[0] === policyRoot.getName()) {
this.logger.info(`- Sync ${policyRoot.getName()}`);
const specs = await policyRoot.build();
for (const spec of specs) {
await this.addPolicy(spec);
}
await this.removeUnregisteredPolicies(policyRoot.getName(), false);
await this.removeUnregisteredPolicies(
policies,
policyRoot.getName(),
false,
);
}
}
await this.registrationService.clear();
Expand Down Expand Up @@ -69,11 +74,10 @@ export default class VaultPolicyController {
* @param partialRegistration True if not all policies were registered this run and false otherwise
*/
public async removeUnregisteredPolicies(
policies: string[],
group: string,
partialRegistration: boolean,
): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- No typing avialable
const policies = (await this.vault.policies()).data.policies as string[];
try {
const policiesToRemove =
await this.registrationService.filterNamesForUnregistered(
Expand Down

0 comments on commit be5a1bf

Please sign in to comment.