import { inject , injectable } from "inversify" ; import { Logger } from "../utils/logger" ; import { Credentials } from "./credentials" ; import { CredentialsStore } from "./credentialsstore" ; import { MessageConstants } from "../utils/messageconstants" ; import { TYPES } from "../utils/constants" ; import { SignIn } from "../commands/signin" ; import { RemoteLogin } from "../../dal/remotelogin" ; import { Settings } from "../entities/settings" ; import { Output } from "../../view/output" ; import { PersistentStorageManager } from "./persistentstoragemanager" ; import { TeamCityStatusBarItem } from "../../view/teamcitystatusbaritem" ; import { MessageManager } from "../../view/messagemanager" ; import { WindowProxy } from "../moduleproxies/window-proxy" ; import { Context } from "../../view/Context" ; @ injectable ( ) export class InMemoryCredentialsStore implements CredentialsStore { constructor ( @ inject ( TYPES . RemoteLogin ) private readonly remoteLogin , @ inject ( TYPES . Output ) private readonly output , @ inject ( TYPES . Settings ) private readonly settings , @ inject ( TYPES . PersistentStorageManager ) private persistentStorageManager , @ inject ( TYPES . TeamCityStatusBarItem ) private readonly statusBarItem , @ inject ( TYPES . MessageManager ) private readonly messageManager , @ inject ( TYPES . WindowProxy ) private readonly windowProxy , @ inject ( TYPES . Context ) private readonly myContext ) { } private credentials : Credentials ; public async setCredentials ( credentials ) { this . credentials = credentials ; } public async getCredentials ( ) { let credentials = this . getCredentialsSilently ( ) ; if ( ! credentials ) { Logger . logInfo ( "InMemoryCredentialsStore#getCredentials: credentials is undefined. An attempt to get them" ) ; await this . signIn ( ) ; credentials = this . getCredentialsSilently ( ) ; if ( ! credentials ) { Logger . logWarning ( "InMemoryCredentialsStore#getCredentials: An attempt to get credentials failed" ) ; return Promise . reject ( MessageConstants . NO_CREDENTIALS_RUN_SIGNIN ) ; } } return Promise . resolve < Credentials > ( credentials ) ; } private async signIn ( ) { const signInCommand = new SignIn ( this . remoteLogin , this , this . settings , this . persistentStorageManager , this . statusBarItem , this . messageManager , this . windowProxy , this . myContext ) ; return signInCommand . exec ( ) ; } public getCredentialsSilently ( ) { return this . credentials ; } public async removeCredentials ( ) { if ( this . credentials ) { Logger . logInfo ( `The credentials for ${ this . credentials . user } will be deleted from the CredentialsStore` ) ; this . credentials = undefined ; } } }