import * as uuidv4 from 'uuid/v4' ; import * as json_config from '../infrastructure/json_config' ; import { DataLimit } from '../model/access_key' ; export interface ServerConfigJson { serverId ? : string ; metricsEnabled ? : boolean ; name ? : string ; createdTimestampMs ? : number ; portForNewAccessKeys ? : number ; rollouts ? : RolloutConfigJson [ ] ; hostname ? : string ; accessKeyDataLimit ? : DataLimit ; } export interface RolloutConfigJson { id : string ; enabled : boolean ; } export function readServerConfig ( filename ) { try { const config = json_config . loadFileConfig < ServerConfigJson > ( filename ) ; config . data ( ) . serverId = config . data ( ) . serverId || uuidv4 ( ) ; config . data ( ) . metricsEnabled = config . data ( ) . metricsEnabled || false ; config . data ( ) . createdTimestampMs = config . data ( ) . createdTimestampMs || Date . now ( ) ; config . data ( ) . hostname = config . data ( ) . hostname || process . env . SB_PUBLIC_IP ; config . write ( ) ; return config ; } catch ( error ) { throw new Error ( `Failed to read server config at ${ filename }: ${ error }` ) ; } }