Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: add TLS support #685

Merged
merged 25 commits into from
Aug 14, 2020
Merged
1 change: 1 addition & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
DUBBO_KEY = "dubbo"
RELEASE_KEY = "release"
ANYHOST_KEY = "anyhost"
SSL_ENABLED_KEY = "ssl-enabled"
)

const (
Expand Down
7 changes: 7 additions & 0 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
providerConfig *ProviderConfig
// baseConfig = providerConfig.BaseConfig or consumerConfig
baseConfig *BaseConfig
sslEnabled = false

// configAccessMutex is used to make sure that xxxxConfig will only be created once if needed.
// it should be used combine with double-check to avoid the race condition
Expand Down Expand Up @@ -325,6 +326,12 @@ func GetBaseConfig() *BaseConfig {
return baseConfig
}

func GetSslEnabled() bool {
return sslEnabled
}
func SetSslEnabled(enabled bool) {
sslEnabled = enabled
}
func IsProvider() bool {
return providerConfig != nil
}
9 changes: 6 additions & 3 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

import (
"github.com/creasty/defaults"
"github.com/dubbogo/getty"
perrors "github.com/pkg/errors"
)

Expand All @@ -34,6 +33,10 @@ import (
"github.com/apache/dubbo-go/common/yaml"
)

const (
MaxWheelTimeSpan = 900e9 // 900s, 15 minute
)

/////////////////////////
// consumerConfig
/////////////////////////
Expand Down Expand Up @@ -107,9 +110,9 @@ func ConsumerInit(confConFile string) error {
if consumerConfig.RequestTimeout, err = time.ParseDuration(consumerConfig.Request_Timeout); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(Request_Timeout{%#v})", consumerConfig.Request_Timeout)
}
if consumerConfig.RequestTimeout >= time.Duration(getty.MaxWheelTimeSpan) {
if consumerConfig.RequestTimeout >= time.Duration(MaxWheelTimeSpan) {
return perrors.WithMessagef(err, "request_timeout %s should be less than %s",
consumerConfig.Request_Timeout, time.Duration(getty.MaxWheelTimeSpan))
consumerConfig.Request_Timeout, time.Duration(MaxWheelTimeSpan))
}
}
if consumerConfig.Connect_Timeout != "" {
Expand Down
1 change: 1 addition & 0 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (c *ServiceConfig) Export() error {
common.WithPort(port),
common.WithParams(urlMap),
common.WithParamsValue(constant.BEAN_NAME_KEY, c.id),
common.WithParamsValue(constant.SSL_ENABLED_KEY, strconv.FormatBool(GetSslEnabled())),
common.WithMethods(strings.Split(methods, ",")),
common.WithToken(c.Token),
)
Expand Down
43 changes: 43 additions & 0 deletions config/ssl_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package config

import (
"github.com/dubbogo/getty"
)

var (
serverTlsConfigBuilder getty.TlsConfigBuilder
clientTlsConfigBuilder getty.TlsConfigBuilder
)

func GetServerTlsConfigBuilder() getty.TlsConfigBuilder {
return serverTlsConfigBuilder
}

func GetClientTlsConfigBuilder() getty.TlsConfigBuilder {
return clientTlsConfigBuilder
}

func SetServerTlsConfigBuilder(configBuilder getty.TlsConfigBuilder) {
serverTlsConfigBuilder = configBuilder
}

func SetClientTlsConfigBuilder(configBuilder getty.TlsConfigBuilder) {
clientTlsConfigBuilder = configBuilder
}
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/creasty/defaults v1.3.0
github.com/docker/go-connections v0.4.0 // indirect
github.com/dubbogo/getty v1.3.7
github.com/dubbogo/getty v1.3.8
github.com/dubbogo/go-zookeeper v1.0.1
github.com/dubbogo/gost v1.9.0
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
Expand All @@ -36,8 +36,6 @@ require (
github.com/hashicorp/vault/api v1.0.5-0.20191108163347-bdd38fca2cff // indirect
github.com/hashicorp/vault/sdk v0.1.14-0.20191112033314-390e96e22eb2
github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b // indirect
github.com/magiconair/properties v1.8.1
github.com/mitchellh/hashstructure v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.2.3
Expand All @@ -58,7 +56,6 @@ require (
go.uber.org/zap v1.15.0
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64 // indirect
google.golang.org/grpc v1.23.0
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.16.9
k8s.io/apimachinery v0.16.9
Expand Down
Loading