import { ConfigObject , RetryOptions , RetryState , ConfigClientOptions } from "../models" ; import { logger } from "../utils" ; import { SpringCloudConfigGatewayImpl } from "../gateways/SpringCloudConfigGatewayImpl" ; import { injectable } from "inversify" ; import { retryFunctionWithState } from "../utils" ; @ injectable ( ) export class SpringCloudConfigServiceImpl { constructor ( private readonly springCloudConfigGatewayImpl ) { } param { ConfigObject } bootstrapConfig returns { Promise < ConfigObject > } public async getConfigFromServer ( bootstrapConfig ) { const configClientOptions = bootstrapConfig . spring . cloud . config ; const retryConfig = configClientOptions . retry ; let cloudConfig = { } ; if ( configClientOptions . enabled ) { logger . debug ( "Spring Cloud Options: " + JSON . stringify ( configClientOptions ) ) ; const retryState = new RetryState ( retryConfig ) ; try { cloudConfig = await this . springCloudConfigGatewayImpl . getConfigFromServer ( configClientOptions ) ; logger . debug ( "Cloud Config: " + JSON . stringify ( cloudConfig ) ) ; } catch ( error ) { logger . warn ( "Error reading cloud config: " , error ) ; if ( configClientOptions [ 'fail-fast' ] === true ) { if ( retryConfig && retryConfig . enabled === true ) { cloudConfig = await retryFunctionWithState < ConfigObject > ( ( ) => this . springCloudConfigGatewayImpl . getConfigFromServer ( configClientOptions ) , retryState ) ; } else { throw error ; } } } } return cloudConfig ; } }