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 <[email protected]>
  • Loading branch information
t1m0thyj committed Nov 25, 2024
1 parent 0a007a2 commit 848beb8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,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
30 changes: 19 additions & 11 deletions packages/imperative/src/config/src/ProfileCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ export class ProfileCredentials {
throw new ImperativeError({ msg: "Secure credential storage is not enabled" });
}

await this.activateCredMgrOverride();

if (this.mProfileInfo.usingTeamConfig) {
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);
}
});
}
}

/**
* 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,17 +105,6 @@ export class ProfileCredentials {
});
}
}

if (this.mProfileInfo.usingTeamConfig) {
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 @@ -1018,7 +1018,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 848beb8

Please sign in to comment.