import * as fs from "fs" ; import { OAuthLevel } from "./models" ; export enum CertOptions { Default , PEM , PFX } export default abstract class ConfigurationBase { public constructor ( public readonly host , public readonly port , public readonly enableAccessLog = false , public readonly accessLogWriteStream ? , public readonly enableDebugLog = false , public readonly debugLogFilePath ? , public readonly loose = false , public readonly skipApiVersionCheck = false , public readonly cert = "" , public readonly key = "" , public readonly pwd = "" , public readonly oauth ? , public readonly disableProductStyleUrl = false ) { } public hasCert ( ) { if ( this . cert . length > 0 && this . key . length > 0 ) { return CertOptions . PEM ; } if ( this . cert . length > 0 && this . pwd . toString ( ) . length > 0 ) { return CertOptions . PFX ; } return CertOptions . Default ; } public getCert ( option ) { switch ( option ) { case CertOptions . PEM : return { cert : fs . readFileSync ( this . cert ) , key : fs . readFileSync ( this . key ) } ; case CertOptions . PFX : return { pfx : fs . readFileSync ( this . cert ) , passphrase : this . pwd . toString ( ) } ; default : return null ; } } public getOAuthLevel ( ) { if ( this . oauth ) { if ( this . oauth . toLowerCase ( ) === "basic" ) { return OAuthLevel . BASIC ; } } return ; } public getHttpServerAddress ( ) { return `http${ this . hasCert ( ) === CertOptions . Default ? "" : "s" }://${ this . host }:${ this . port }` ; } }