Documentation ¶
Index ¶
Constants ¶
View Source
const (
ConfigFile = ".tcasctl/config.json"
)
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "init", Short: "init config", Long: "generate the config file", SuggestionsMinimumDistance: 1, DisableSuggestions: false, Run: func(cmd *cobra.Command, args []string) { url, _ := cmd.Flags().GetString("url") skipssl, _ := cmd.Flags().GetBool("skipssl") homedir, err := os.UserHomeDir() if err != nil { logrus.Errorf("home dir not find, error: %s", err) return } configPath := path.Join(homedir, ConfigFile) configs := new(TCASConfig) if file.IsFile(configPath) == false { logrus.Debugf("config file does not exist, generate new config file") err := os.MkdirAll(path.Dir(configPath), os.ModeDir) if err != nil { logrus.Errorf("creat config dir failed, error: %s", err) return } configs.TCASInfos = map[string]*manager.TCASInfo{url: { APIEndpoint: url, }} } else { configs, err = ReadTCASConfigs(configPath) if err != nil { logrus.Errorf("read tcas configs failed, error: %s", err) return } if _, ok := configs.TCASInfos[url]; !ok { configs.TCASInfos[url] = &manager.TCASInfo{ APIEndpoint: url, } } else { configs = nil } } if configs != nil { configs.TCASInfos[url].SkipVerify = skipssl err = WriteTCASConfigToFile(configs, configPath) if err != nil { logrus.Errorf("write config faield, error: %s", err) return } fmt.Printf("init succuessful, config path: %s\n", configPath) } else { fmt.Println("config is already init") } }, }
Cmd represents the ca command
Functions ¶
func WriteTCASConfigToFile ¶
func WriteTCASConfigToFile(configs *TCASConfig, savePath string) error
Types ¶
type TCASConfig ¶
func ReadTCASConfigs ¶
func ReadTCASConfigs(configPath string) (*TCASConfig, error)
Click to show internal directories.
Click to hide internal directories.