Exemple #1
0
func newClient() *websocket.Conn {
	internal.ReadConfig()
	if viper.GetString("url") == "" {
		fmt.Fprintf(os.Stderr, "Invalid Configuration: invalid URL. See tatcli config --help\n")
		os.Exit(1)
	}

	i := strings.Index(viper.GetString("url"), ":")
	endURL := viper.GetString("url")[i:] + "/socket/ws"

	url := "ws" + endURL
	dialer := websocket.DefaultDialer
	if internal.IsHTTPS() {
		url = "wss" + endURL
		dialer = &websocket.Dialer{
			TLSClientConfig:  internal.GetTLSConfig(),
			HandshakeTimeout: time.Duration(time.Duration(time.Second) * 9),
		}
	}

	r, _ := http.NewRequest("GET", url, nil)
	r.Header.Add("Content-Type", "application/json")

	c, _, err := dialer.Dial(url, r.Header)
	internal.Check(err)
	fmt.Printf("Connected to %s [Ctrl+c to quit]\n", url)

	wsActionConnect(c)
	return c
}
Exemple #2
0
func (ui *tatui) loadConfig() {
	internal.ReadConfig()
	filters := viper.GetStringSlice("filters")

	// no range to keep order
	for index := 0; index < len(filters); index++ {
		filter := filters[index]
		tuples := strings.Split(filter, " ")
		if len(tuples) <= 2 {
			continue
		}
		topic := tuples[1]
		if _, ok := ui.currentFilterMessages[topic]; !ok {
			ui.currentFilterMessages[topic] = make(map[int]*tat.MessageCriteria)
			ui.currentFilterMessagesText[topic] = make(map[int]string)
		}
		c, criteriaText := ui.prepareFilterMessages(strings.Join(tuples[2:], " "), tuples[0], topic)
		ui.currentFilterMessages[topic][len(ui.currentFilterMessages[topic])] = c
		ui.currentFilterMessagesText[topic][len(ui.currentFilterMessagesText[topic])] = criteriaText
	}

	commands := viper.GetStringSlice("commands")
	// no range to keep order
	for index := 0; index < len(commands); index++ {
		commandsOnTopic := commands[index]
		tuples := strings.Split(strings.TrimSpace(commandsOnTopic), " ")
		if len(tuples) <= 1 {
			continue
		}
		topic := tuples[0]
		ui.uiTopicCommands[topic] = commandsOnTopic[len(topic):]
	}

	var conf config.TemplateJSONType
	err := viper.Unmarshal(&conf)
	if err != nil {
		internal.Exit("unable to decode confif file, err: %v", err)
	}

	ui.hooks = conf.Hooks
}
Exemple #3
0
// VERSION of tatcli
const VERSION = "0.51.1"

var versionNewLine bool

func init() {
	Cmd.Flags().BoolVarP(&versionNewLine, "versionNewLine", "", true, "New line after version number. If true, display Version Engine too")
}

// Cmd version
var Cmd = &cobra.Command{
	Use:     "version",
	Short:   "Display Version of tatcli and tat engine if configured : tatcli version",
	Long:    `tatcli version`,
	Aliases: []string{"v"},
	Run: func(cmd *cobra.Command, args []string) {
		if versionNewLine {
			fmt.Printf("Version tatcli : %s\n", VERSION)
			internal.ReadConfig()
			if viper.GetString("url") == "" {
				fmt.Fprintf(os.Stderr, "Version Engine : No Engine Configured. See tatcli config --help\n")
			} else {
				fmt.Printf("Version Engine on %s : %s\n", viper.GetString("url"), internal.GetWantReturn("/version"))
			}
		} else {
			fmt.Print(VERSION)
		}
	},
}
Exemple #4
0
func show() {
	internal.ReadConfig()
	fmt.Printf("username:%s\n", viper.GetString("username"))
	fmt.Printf("password:%s\n", viper.GetString("password"))
	fmt.Printf("url:%s\n", viper.GetString("url"))
}