code.vegaprotocol.io/vega@v0.79.0/core/api/config.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package api
    17  
    18  import (
    19  	"time"
    20  
    21  	"code.vegaprotocol.io/vega/libs/config/encoding"
    22  	libhttp "code.vegaprotocol.io/vega/libs/http"
    23  	"code.vegaprotocol.io/vega/logging"
    24  )
    25  
    26  // namedLogger is the identifier for package and should ideally match the package name
    27  // this is simply emitted as a hierarchical label e.g. 'api.grpc'.
    28  const namedLogger = "api.grpc"
    29  
    30  // Config represents the configuration of the api package.
    31  type Config struct {
    32  	Level           encoding.LogLevel `long:"log-level"`
    33  	Timeout         encoding.Duration `long:"timeout"`
    34  	Port            int               `long:"port"`
    35  	IP              string            `long:"ip"`
    36  	StreamRetries   int               `long:"stream-retries"`
    37  	DisableTxCommit bool              `long:"disable-tx-commit"`
    38  
    39  	REST RESTServiceConfig `group:"REST" namespace:"rest"`
    40  }
    41  
    42  // RESTGatewayServiceConfig represent the configuration of the rest service.
    43  type RESTServiceConfig struct {
    44  	Port       int                `description:"Listen for connection on port <port>" long:"port"`
    45  	IP         string             `description:"Bind to address <ip>"                 long:"ip"`
    46  	Enabled    encoding.Bool      `choice:"true"                                      description:"Start the REST gateway" long:"enabled"`
    47  	APMEnabled encoding.Bool      `choice:"true"                                      description:" "                      long:"apm-enabled"`
    48  	CORS       libhttp.CORSConfig `group:"CORS"                                       namespace:"cors"`
    49  }
    50  
    51  // NewDefaultConfig creates an instance of the package specific configuration, given a
    52  // pointer to a logger instance to be used for logging within the package.
    53  func NewDefaultConfig() Config {
    54  	return Config{
    55  		Level:   encoding.LogLevel{Level: logging.InfoLevel},
    56  		Timeout: encoding.Duration{Duration: 5000 * time.Millisecond},
    57  
    58  		IP:              "0.0.0.0",
    59  		Port:            3002,
    60  		StreamRetries:   3,
    61  		DisableTxCommit: true,
    62  		REST: RESTServiceConfig{
    63  			IP:         "0.0.0.0",
    64  			Port:       3003,
    65  			Enabled:    true,
    66  			APMEnabled: true,
    67  			CORS: libhttp.CORSConfig{
    68  				AllowedOrigins: []string{"*"},
    69  				MaxAge:         7200,
    70  			},
    71  		},
    72  	}
    73  }