github.com/polarismesh/polaris@v1.17.8/common/secure/config.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package secure 19 20 import ( 21 "github.com/mitchellh/mapstructure" 22 23 "github.com/polarismesh/polaris/common/log" 24 ) 25 26 // TLSConfig tls 相关配置 27 type TLSConfig struct { 28 // CertFile 证书 29 CertFile string `mapstructure:"certFile"` 30 // KeyFile 密钥 31 KeyFile string `mapstructure:"keyFile"` 32 // TrustedCAFile CA 证书 33 TrustedCAFile string `mapstructure:"trustedCAFile"` 34 // ServerName 客户端发送的 Server Name Indication 扩展的值 35 ServerName string `mapstructure:"serverName"` 36 37 // InsecureSkipVerify tls 的一个配置 38 // 客户端是否验证证书和服务器主机名 39 InsecureSkipVerify bool `mapstructure:"insecureSkipTlsVerify"` 40 } 41 42 // ParseTLSConfig 解析 tls 配置 43 func ParseTLSConfig(raw map[interface{}]interface{}) (*TLSConfig, error) { 44 if raw == nil { 45 return nil, nil 46 } 47 48 tlsConfig := &TLSConfig{} 49 decodeConfig := &mapstructure.DecoderConfig{ 50 DecodeHook: mapstructure.StringToTimeDurationHookFunc(), 51 Result: tlsConfig, 52 } 53 decoder, err := mapstructure.NewDecoder(decodeConfig) 54 if err != nil { 55 log.Errorf("tls config new decoder err: %s", err.Error()) 56 return nil, err 57 } 58 59 err = decoder.Decode(raw) 60 if err != nil { 61 log.Errorf("parse tls config(%+v) err: %s", raw, err.Error()) 62 return nil, err 63 } 64 65 return tlsConfig, nil 66 }