@@ -212,7 +212,7 @@ func (a *Aperture) Start(errChan chan error) error {
212212 a .httpsServer .Handler = h2c .NewHandler (handler , & http2.Server {})
213213 } else {
214214 a .httpsServer .TLSConfig , err = getTLSConfig (
215- a .cfg .ServerName , a .cfg .AutoCert ,
215+ a .cfg .ServerName , a .cfg .BaseDir , a . cfg . AutoCert ,
216216 )
217217 if err != nil {
218218 return err
@@ -329,7 +329,19 @@ func getConfig() (*Config, error) {
329329 // If a custom config file is provided, we require that it exists.
330330 var mustExist bool
331331
332+ // Start with our default path for config file.
332333 configFile := filepath .Join (apertureDataDir , defaultConfigFilename )
334+
335+ // If a base directory is set, we'll look in there for a config file.
336+ // We don't require it to exist because we could just want to place
337+ // all of our files here, and specify all config inline.
338+ if cfg .BaseDir != "" {
339+ configFile = filepath .Join (cfg .BaseDir , defaultConfigFilename )
340+ }
341+
342+ // If a specific config file is set, we'll look here for a config file,
343+ // even if a base directory for our files was set. In this case, the
344+ // config file must exist, since we're specifically being pointed it.
333345 if cfg .ConfigFile != "" {
334346 configFile = lnd .CleanAndExpandPath (cfg .ConfigFile )
335347 mustExist = true
@@ -364,7 +376,8 @@ func getConfig() (*Config, error) {
364376 return nil , err
365377 }
366378
367- // Clean and expand our cert and macaroon paths.
379+ // Clean and expand our base dir, cert and macaroon paths.
380+ cfg .BaseDir = lnd .CleanAndExpandPath (cfg .BaseDir )
368381 cfg .Authenticator .TLSPath = lnd .CleanAndExpandPath (
369382 cfg .Authenticator .TLSPath ,
370383 )
@@ -389,7 +402,13 @@ func setupLogging(cfg *Config, interceptor signal.Interceptor) error {
389402
390403 // Now initialize the logger and set the log level.
391404 SetupLoggers (logWriter , interceptor )
405+
406+ // Use our default data dir unless a base dir is set.
392407 logFile := filepath .Join (apertureDataDir , defaultLogFilename )
408+ if cfg .BaseDir != "" {
409+ logFile = filepath .Join (cfg .BaseDir , defaultLogFilename )
410+ }
411+
393412 err := logWriter .InitLogRotator (
394413 logFile , defaultMaxLogFileSize , defaultMaxLogFiles ,
395414 )
@@ -401,7 +420,15 @@ func setupLogging(cfg *Config, interceptor signal.Interceptor) error {
401420
402421// getTLSConfig returns a TLS configuration for either a self-signed certificate
403422// or one obtained through Let's Encrypt.
404- func getTLSConfig (serverName string , autoCert bool ) (* tls.Config , error ) {
423+ func getTLSConfig (serverName , baseDir string , autoCert bool ) (
424+ * tls.Config , error ) {
425+
426+ // Use our default data dir unless a base dir is set.
427+ apertureDir := apertureDataDir
428+ if baseDir != "" {
429+ apertureDir = baseDir
430+ }
431+
405432 // If requested, use the autocert library that will create a new
406433 // certificate through Let's Encrypt as soon as the first client HTTP
407434 // request on the server using the TLS config comes in. Unfortunately
@@ -414,7 +441,7 @@ func getTLSConfig(serverName string, autoCert bool) (*tls.Config, error) {
414441 "required for secure operation" )
415442 }
416443
417- certDir := filepath .Join (apertureDataDir , "autocert" )
444+ certDir := filepath .Join (apertureDir , "autocert" )
418445 log .Infof ("Configuring autocert for server %v with cache dir " +
419446 "%v" , serverName , certDir )
420447
@@ -442,8 +469,8 @@ func getTLSConfig(serverName string, autoCert bool) (*tls.Config, error) {
442469 // If we're not using autocert, we want to create self-signed TLS certs
443470 // and save them at the specified location (if they don't already
444471 // exist).
445- tlsKeyFile := filepath .Join (apertureDataDir , defaultTLSKeyFilename )
446- tlsCertFile := filepath .Join (apertureDataDir , defaultTLSCertFilename )
472+ tlsKeyFile := filepath .Join (apertureDir , defaultTLSKeyFilename )
473+ tlsCertFile := filepath .Join (apertureDir , defaultTLSCertFilename )
447474 tlsExtraDomains := []string {serverName }
448475 if ! fileExists (tlsCertFile ) && ! fileExists (tlsKeyFile ) {
449476 log .Infof ("Generating TLS certificates..." )
0 commit comments