code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/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  //lint:file-ignore SA5008 duplicated struct tags are ok for config
    17  
    18  package gateway
    19  
    20  import (
    21  	"time"
    22  
    23  	"code.vegaprotocol.io/vega/datanode/config/encoding"
    24  	"code.vegaprotocol.io/vega/datanode/ratelimit"
    25  	libhttp "code.vegaprotocol.io/vega/libs/http"
    26  	"code.vegaprotocol.io/vega/logging"
    27  )
    28  
    29  // ServerConfig represent the configuration of a server in vega.
    30  type ServerConfig struct {
    31  	Port       int    `description:"Listen for connection on port <port>" long:"port"`
    32  	IP         string `description:"Bind to address <ip>"                 long:"ip"`
    33  	MaxMsgSize int    `description:"Max message size in bytes"            long:"max-msg-size"`
    34  }
    35  
    36  // GraphqlServiceConfig represents the configuration of the gateway.
    37  type GraphqlServiceConfig struct {
    38  	Enabled         encoding.Bool `description:"Start the GraphQl gateway"             long:"enabled"`
    39  	ComplexityLimit int           `long:"complexity-limit"`
    40  	Endpoint        string        `description:"Endpoint to expose the graphql API at" long:"endpoint"`
    41  }
    42  
    43  // RESTGatewayServiceConfig represent the configuration of the rest service.
    44  type RESTGatewayServiceConfig struct {
    45  	Enabled    encoding.Bool `choice:"true" choice:"false" description:"Start the REST gateway" long:"enabled"`
    46  	APMEnabled encoding.Bool `choice:"true" choice:"false" description:" "                      long:"apm-enabled"`
    47  }
    48  
    49  // Config represents the general configuration for the gateway.
    50  type Config struct {
    51  	ServerConfig
    52  	Level                    encoding.LogLevel        `choice:"debug"                                                                  choice:"info"                      choice:"warning" long:"log-level"`
    53  	Timeout                  encoding.Duration        `long:"timeout"`
    54  	Node                     ServerConfig             `group:"Node"                                                                    namespace:"node"`
    55  	GraphQL                  GraphqlServiceConfig     `group:"GraphQL"                                                                 namespace:"graphql"`
    56  	REST                     RESTGatewayServiceConfig `group:"REST"                                                                    namespace:"rest"`
    57  	SubscriptionRetries      int                      `description:" "                                                                 long:"subscription-retries"`
    58  	GraphQLPlaygroundEnabled encoding.Bool            `description:"Enables the GraphQL playground"                                    long:"graphql-playground"`
    59  	MaxSubscriptionPerClient uint32                   `description:"Maximum graphql subscriptions allowed per client"                  long:"max-subscription-per-client"`
    60  	CORS                     libhttp.CORSConfig       `group:"CORS"                                                                    namespace:"cors"`
    61  	HTTPSEnabled             encoding.Bool            `description:"If true, GraphQL gateway will require an HTTPS connection"         long:"https-enabled"`
    62  	AutoCertDomain           string                   `description:"Automatically generate and sign https certificate via LetsEncrypt" long:"auto-cert-domain"`
    63  	CertificateFile          string                   `description:"Path to SSL certificate, if using HTTPS but not autocert"          long:"certificate-file"`
    64  	KeyFile                  string                   `description:"Path to private key, if using HTTPS but not autocert"              long:"key-file"`
    65  	RateLimit                ratelimit.Config         `group:"RateLimits"                                                              namespace:"rate-limits"`
    66  }
    67  
    68  // NewDefaultConfig creates an instance of the package specific configuration, given a
    69  // pointer to a logger instance to be used for logging within the package.
    70  func NewDefaultConfig() Config {
    71  	return Config{
    72  		ServerConfig: ServerConfig{
    73  			IP:         "0.0.0.0",
    74  			Port:       3008,
    75  			MaxMsgSize: 20 * 1024 * 1024,
    76  		},
    77  		Level:        encoding.LogLevel{Level: logging.InfoLevel},
    78  		Timeout:      encoding.Duration{Duration: 5 * time.Second},
    79  		HTTPSEnabled: false,
    80  		GraphQL: GraphqlServiceConfig{
    81  			Enabled:  true,
    82  			Endpoint: "/graphql",
    83  		},
    84  		REST: RESTGatewayServiceConfig{
    85  			Enabled:    true,
    86  			APMEnabled: true,
    87  		},
    88  		Node: ServerConfig{
    89  			IP:         "0.0.0.0",
    90  			Port:       3007,
    91  			MaxMsgSize: 20 * 1024 * 1024,
    92  		},
    93  		SubscriptionRetries:      3,
    94  		GraphQLPlaygroundEnabled: true,
    95  		MaxSubscriptionPerClient: 250,
    96  		CORS: libhttp.CORSConfig{
    97  			AllowedOrigins: []string{"*"},
    98  			MaxAge:         7200,
    99  		},
   100  		RateLimit: ratelimit.NewDefaultConfig(),
   101  	}
   102  }