summaryrefslogtreecommitdiff
path: root/plugins/grpc/config.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-09-16 21:46:50 +0300
committerGitHub <[email protected]>2021-09-16 21:46:50 +0300
commit3581b45f237a3f7aa29591ceb2bf6f4a4642a2f5 (patch)
treee723b19ec1ac16b7ccc7b3c2da69d4a416d63d81 /plugins/grpc/config.go
parent337d292dd2d6ff0a555098b1970d8194d8df8bc2 (diff)
parent823d831b57b75f70c7c3bbbee355f2016633bb3b (diff)
[#803]: feat(plugins): move plugins to a separate repositoryv2.5.0-alpha.2
[#803]: feat(plugins): move plugins to a separate repository
Diffstat (limited to 'plugins/grpc/config.go')
-rw-r--r--plugins/grpc/config.go128
1 files changed, 0 insertions, 128 deletions
diff --git a/plugins/grpc/config.go b/plugins/grpc/config.go
deleted file mode 100644
index fedd4998..00000000
--- a/plugins/grpc/config.go
+++ /dev/null
@@ -1,128 +0,0 @@
-package grpc
-
-import (
- "math"
- "os"
- "strings"
- "time"
-
- "github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/pkg/pool"
-)
-
-type Config struct {
- Listen string `mapstructure:"listen"`
- Proto string `mapstructure:"proto"`
-
- TLS *TLS
-
- // Env is environment variables passed to the http pool
- Env map[string]string `mapstructure:"env"`
-
- GrpcPool *pool.Config `mapstructure:"pool"`
- MaxSendMsgSize int64 `mapstructure:"max_send_msg_size"`
- MaxRecvMsgSize int64 `mapstructure:"max_recv_msg_size"`
- MaxConnectionIdle time.Duration `mapstructure:"max_connection_idle"`
- MaxConnectionAge time.Duration `mapstructure:"max_connection_age"`
- MaxConnectionAgeGrace time.Duration `mapstructure:"max_connection_age_grace"`
- MaxConcurrentStreams int64 `mapstructure:"max_concurrent_streams"`
- PingTime time.Duration `mapstructure:"ping_time"`
- Timeout time.Duration `mapstructure:"timeout"`
-}
-
-type TLS struct {
- Key string
- Cert string
- RootCA string
-}
-
-func (c *Config) InitDefaults() error { //nolint:gocognit
- const op = errors.Op("grpc_plugin_config")
- if c.GrpcPool == nil {
- c.GrpcPool = &pool.Config{}
- }
-
- c.GrpcPool.InitDefaults()
-
- if !strings.Contains(c.Listen, ":") {
- return errors.E(op, errors.Errorf("mailformed grpc grpc address, provided: %s", c.Listen))
- }
-
- if c.EnableTLS() {
- if _, err := os.Stat(c.TLS.Key); err != nil {
- if os.IsNotExist(err) {
- return errors.E(op, errors.Errorf("key file '%s' does not exists", c.TLS.Key))
- }
-
- return errors.E(op, err)
- }
-
- if _, err := os.Stat(c.TLS.Cert); err != nil {
- if os.IsNotExist(err) {
- return errors.E(op, errors.Errorf("cert file '%s' does not exists", c.TLS.Cert))
- }
-
- return errors.E(op, err)
- }
-
- // RootCA is optional, but if provided - check it
- if c.TLS.RootCA != "" {
- if _, err := os.Stat(c.TLS.RootCA); err != nil {
- if os.IsNotExist(err) {
- return errors.E(op, errors.Errorf("root ca path provided, but key file '%s' does not exists", c.TLS.RootCA))
- }
- return errors.E(op, err)
- }
- }
- }
-
- // used to set max time
- infinity := time.Duration(math.MaxInt64)
-
- if c.PingTime == 0 {
- c.PingTime = time.Hour * 2
- }
-
- if c.Timeout == 0 {
- c.Timeout = time.Second * 20
- }
-
- if c.MaxConcurrentStreams == 0 {
- c.MaxConcurrentStreams = 10
- }
- // set default
- if c.MaxConnectionAge == 0 {
- c.MaxConnectionAge = infinity
- }
-
- // set default
- if c.MaxConnectionIdle == 0 {
- c.MaxConnectionIdle = infinity
- }
-
- if c.MaxConnectionAgeGrace == 0 {
- c.MaxConnectionAgeGrace = infinity
- }
-
- if c.MaxRecvMsgSize == 0 {
- c.MaxRecvMsgSize = 1024 * 1024 * 50
- } else {
- c.MaxRecvMsgSize = 1024 * 1024 * c.MaxRecvMsgSize
- }
-
- if c.MaxSendMsgSize == 0 {
- c.MaxSendMsgSize = 1024 * 1024 * 50
- } else {
- c.MaxSendMsgSize = 1024 * 1024 * c.MaxSendMsgSize
- }
-
- return nil
-}
-
-func (c *Config) EnableTLS() bool {
- if c.TLS != nil {
- return (c.TLS.RootCA != "" && c.TLS.Key != "" && c.TLS.Cert != "") || (c.TLS.Key != "" && c.TLS.Cert != "")
- }
-
- return false
-}