Skip to content

Commit

Permalink
refactor: simplify getCredentialsProxy method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Nov 20, 2024
1 parent b672dba commit a27d376
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ export class AwsIamRoleChainedService extends AwsSessionService {
return await this.fileService.replaceWriteSync(this.awsCoreService.awsCredentialPath(), credentialsFile);
}

generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo> {
return this.generateCredentials(sessionId);
}

async generateCredentials(sessionId: string): Promise<CredentialsInfo> {
// Retrieve Session
const session = this.repository.getSessionById(sessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ export class AwsIamRoleFederatedService extends AwsSessionService {
return await this.fileService.replaceWriteSync(this.awsCoreService.awsCredentialPath(), credentialsFile);
}

generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo> {
return this.generateCredentials(sessionId);
}

async generateCredentials(sessionId: string): Promise<CredentialsInfo> {
// Get the session in question
const session = this.repository.getSessionById(sessionId);
Expand Down
19 changes: 7 additions & 12 deletions packages/core/src/services/session/aws/aws-iam-user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,14 @@ export class AwsIamUserService extends AwsSessionService {
return await this.fileService.replaceWriteSync(this.awsCoreService.awsCredentialPath(), credentialsFile);
}

generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo> {
return new Promise<CredentialsInfo>((resolve, reject) => {
async generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo> {
try {
this.mfaCodePrompterProxy = this.remoteMfaCodePrompter;
this.generateCredentials(sessionId)
.then((credentialsInfo: CredentialsInfo) => {
this.mfaCodePrompterProxy = this.localMfaCodePrompter;
resolve(credentialsInfo);
})
.catch((err) => {
this.mfaCodePrompterProxy = this.localMfaCodePrompter;
reject(err);
});
});
const credentialsInfo = await this.generateCredentials(sessionId)
return credentialsInfo;
} finally {
this.mfaCodePrompterProxy = this.localMfaCodePrompter;
}
}

async generateCredentials(sessionId: string): Promise<CredentialsInfo> {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/services/session/aws/aws-session-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ export abstract class AwsSessionService extends SessionService {
}
}

abstract getAccountNumberFromCallerIdentity(session: Session): Promise<string>;
generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo> {
return this.generateCredentials(sessionId);
}

abstract generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo>;
abstract getAccountNumberFromCallerIdentity(session: Session): Promise<string>;

abstract generateCredentials(sessionId: string): Promise<CredentialsInfo>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ export class AwsSsoRoleService extends AwsSessionService implements BrowserWindo
await this.fileService.replaceWriteSync(this.awsCoreService.awsCredentialPath(), credentialsFile);
}

generateCredentialsProxy(sessionId: string): Promise<CredentialsInfo> {
return this.generateCredentials(sessionId);
}

async generateCredentials(sessionId: string): Promise<CredentialsInfo> {
const session: AwsSsoRoleSession = this.repository.getSessionById(sessionId) as AwsSsoRoleSession;
const awsSsoConfiguration = this.repository.getAwsSsoIntegration(session.awsSsoConfigurationId);
Expand Down

0 comments on commit a27d376

Please sign in to comment.