github.com/palantir/witchcraft-go-server/v2@v2.76.0/config/runtime.go (about)

     1  // Copyright (c) 2018 Palantir Technologies. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package config
    16  
    17  import (
    18  	"strings"
    19  
    20  	"github.com/palantir/conjure-go-runtime/v2/conjure-go-client/httpclient"
    21  	"github.com/palantir/witchcraft-go-logging/wlog"
    22  )
    23  
    24  // Runtime specifies the base runtime configuration fields that should be included in all witchcraft-server-go
    25  // server runtime configurations.
    26  type Runtime struct {
    27  	DiagnosticsConfig DiagnosticsConfig         `yaml:"diagnostics,omitempty"`
    28  	HealthChecks      HealthChecksConfig        `yaml:"health-checks,omitempty"`
    29  	LoggerConfig      *LoggerConfig             `yaml:"logging,omitempty"`
    30  	ServiceDiscovery  httpclient.ServicesConfig `yaml:"service-discovery,omitempty"`
    31  }
    32  
    33  type DiagnosticsConfig struct {
    34  	// DebugSharedSecret is a string which, if provided, will be used as the access key to the diagnostics route.
    35  	// This takes precedence over DebugSharedSecretFile.
    36  	DebugSharedSecret string `yaml:"debug-shared-secret"`
    37  	// DebugSharedSecretFile is an on-disk location containing the shared secret. If DebugSharedSecretFile is provided and
    38  	// DebugSharedSecret is not, the content of the file will be used as the shared secret.
    39  	DebugSharedSecretFile string `yaml:"debug-shared-secret-file"`
    40  }
    41  
    42  type HealthChecksConfig struct {
    43  	SharedSecret string `yaml:"shared-secret"`
    44  }
    45  
    46  type LoggerConfig struct {
    47  	// Level configures the log level for leveled loggers (such as service logs). Does not impact non-leveled loggers
    48  	// (such as request logs).
    49  	Level wlog.LogLevel `yaml:"level"`
    50  }
    51  
    52  func (c *LoggerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
    53  	type loggerConfigAlias LoggerConfig
    54  	var cfg loggerConfigAlias
    55  	if err := unmarshal(&cfg); err != nil {
    56  		return err
    57  	}
    58  	*c = LoggerConfig(cfg)
    59  	c.Level = wlog.LogLevel(strings.ToLower(string(c.Level)))
    60  	return nil
    61  }