Skip to content

Commit

Permalink
Fix profileManagerWillLoad depending on config API
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed Nov 6, 2024
1 parent 17f7435 commit 256eec1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ describe("TeamConfig ProfileInfo tests", () => {
it("should return false if secure credentials fail to load", async () => {
const profInfo = createNewProfInfo(teamProjDir);
jest.spyOn((profInfo as any).mCredentials, "isCredentialManagerInAppSettings").mockReturnValueOnce(true);
jest.spyOn((profInfo as any).mCredentials, "loadManager").mockImplementationOnce(async () => {
jest.spyOn((profInfo as any).mCredentials, "activateCredMgrOverride").mockImplementationOnce(async () => {
throw new Error("bad credential manager");
});

Expand Down
25 changes: 16 additions & 9 deletions packages/imperative/src/config/src/ProfileCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ export class ProfileCredentials {
throw new ImperativeError({ msg: "Secure credential storage is not enabled" });
}

await this.activateCredMgrOverride();
await this.mProfileInfo.getTeamConfig().api.secure.load({
load: (key: string): Promise<string> => {
return CredentialManagerFactory.manager.load(key, true);

Check warning on line 80 in packages/imperative/src/config/src/ProfileCredentials.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileCredentials.ts#L79-L80

Added lines #L79 - L80 were not covered by tests
},
save: (key: string, value: any): Promise<void> => {
return CredentialManagerFactory.manager.save(key, value);

Check warning on line 83 in packages/imperative/src/config/src/ProfileCredentials.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileCredentials.ts#L82-L83

Added lines #L82 - L83 were not covered by tests
}
});
}

/**
* Attempt to initialize `CredentialManagerFactory` with the specified override.
* @internal
*/
public async activateCredMgrOverride(): Promise<void> {
if (!CredentialManagerFactory.initialized) {
try {
// TODO? Make CredentialManagerFactory.initialize params optional
Expand All @@ -86,15 +102,6 @@ export class ProfileCredentials {
});
}
}

await this.mProfileInfo.getTeamConfig().api.secure.load({
load: (key: string): Promise<string> => {
return CredentialManagerFactory.manager.load(key, true);
},
save: (key: string, value: any): Promise<void> => {
return CredentialManagerFactory.manager.save(key, value);
}
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/imperative/src/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ export class ProfileInfo {
public async profileManagerWillLoad(): Promise<boolean> {
if (this.mCredentials.isCredentialManagerInAppSettings()) {
try {
await this.mCredentials.loadManager();
await this.mCredentials.activateCredMgrOverride();
return true;
} catch (err) {
this.mImpLogger.warn("Failed to initialize secure credential manager: " + err.message);
Expand Down

0 comments on commit 256eec1

Please sign in to comment.