github.com/XiaoMi/Gaea@v1.2.5/models/cc.go (about) 1 // Copyright 2019 The Gaea Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package models 16 17 import ( 18 "strings" 19 20 "github.com/go-ini/ini" 21 ) 22 23 // CCConfig means gaea cc config 24 type CCConfig struct { 25 Addr string `ini:"addr"` 26 AdminUserName string `ini:"admin_username"` 27 AdminPassword string `ini:"admin_password"` 28 ProxyUserName string `ini:"proxy_username"` 29 ProxyPassword string `ini:"proxy_password"` 30 // etcd 相关配置 31 CoordinatorType string `ini:"coordinator_type"` 32 CoordinatorAddr string `ini:"coordinator_addr"` 33 CoordinatorRoot string `ini:"coordinator_root"` 34 UserName string `ini:"username"` 35 Password string `ini:"password"` 36 37 DefaultCluster string `ini:"default_cluster"` 38 39 LogPath string `ini:"log_path"` 40 LogLevel string `ini:"log_level"` 41 LogFileName string `ini:"log_filename"` 42 LogOutput string `ini:"log_output"` 43 44 EncryptKey string `ini:"encrypt_key"` 45 } 46 47 // ParseCCConfig parser gaea cc config from file 48 func ParseCCConfig(cfgFile string) (*CCConfig, error) { 49 cfg, err := ini.Load(cfgFile) 50 51 if err != nil { 52 return nil, err 53 } 54 55 ccConfig := new(CCConfig) 56 err = cfg.MapTo(ccConfig) 57 if ccConfig.DefaultCluster == "" && ccConfig.CoordinatorRoot != "" { 58 ccConfig.DefaultCluster = strings.TrimPrefix(ccConfig.CoordinatorRoot, "/") 59 } 60 if ccConfig.CoordinatorType == "" { 61 ccConfig.CoordinatorType = ConfigEtcd 62 } 63 return ccConfig, err 64 } 65 66 // Verify verify cc config 67 func (cc *CCConfig) Verify() error { 68 return nil 69 }