示例#1
0
文件: truncate.go 项目: ovh/tatcli
func topicTruncate(topic string) {
	j := tat.TopicNameJSON{Topic: topic}
	if force {
		out, err := internal.Client().TopicTruncate(j)
		internal.Check(err)
		if internal.Verbose {
			internal.Print(out)
		}
	} else {
		fmt.Print("Are you really sure ? You will delete all messages even if a user has a message in his tasks. Please enter again topic name to confirm: ")
		var confirmTopic string
		fmt.Scanln(&confirmTopic)

		if confirmTopic == topic {
			fmt.Printf("Please enter 'yes' to confirm removing all messages from %s: ", topic)
			var confirmYes string
			fmt.Scanln(&confirmYes)
			if confirmYes == "yes" {
				out, err := internal.Client().TopicTruncate(j)
				internal.Check(err)
				internal.Print(out)
				return
			}
		} else {
			fmt.Printf("Error. You enter %s instead of %s\n", confirmTopic, topic)
		}
		fmt.Println("Nothing done")
	}
}
示例#2
0
文件: write.go 项目: ovh/tatcli
func writeTemplate() {
	var templateJSON TemplateJSONType

	if viper.GetString("username") != "" {
		templateJSON.Username = viper.GetString("username")
	}
	if viper.GetString("password") != "" {
		templateJSON.Password = viper.GetString("password")
	}
	if viper.GetString("url") != "" {
		templateJSON.URL = viper.GetString("url")
	}
	if viper.GetString("tatwebui-url") != "" {
		templateJSON.TatwebuiURL = viper.GetString("tatwebui-url")
	}

	jsonStr, err := json.MarshalIndent(templateJSON, "", "  ")
	internal.Check(err)
	jsonStr = append(jsonStr, '\n')
	filename := internal.ConfigFile

	dir := path.Dir(filename)
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		internal.Check(os.Mkdir(dir, 0740))
	}

	internal.Check(ioutil.WriteFile(filename, jsonStr, 0600))
	fmt.Printf("%s is written\n", filename)
}
示例#3
0
func socketRead(c *websocket.Conn) {
	for {
		_, r, err := c.ReadMessage()
		internal.Check(err)
		fmt.Print(color(string(r)))
	}
}
示例#4
0
文件: socket.go 项目: bnjjj/tatcli
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
}
示例#5
0
func topicDeleteParameter(topic string, keys []string) {
	for _, key := range keys {
		t := topicParameterJSON{Topic: topic, Key: key, Recursive: recursive}
		jsonStr, err := json.Marshal(t)
		internal.Check(err)
		internal.PutWant("/topic/remove/parameter", jsonStr)
	}
}
示例#6
0
func topicAddParameter(topic string, parameters []string) {
	for _, param := range parameters {
		parameterSplitted := strings.Split(param, ":")
		if len(parameterSplitted) != 2 {
			continue
		}
		_, err := internal.Client().TopicAddParameter(topic, parameterSplitted[0], parameterSplitted[1], recursive)
		internal.Check(err)
	}
}
示例#7
0
文件: verify.go 项目: ovh/tatcli
func userVerify(username, tokenVerify string) {
	verifyJSON, err := internal.Client().UserVerify(username, tokenVerify)
	internal.Check(err)

	// Display return to user (contains clear password)
	internal.Print(verifyJSON)

	if save && verifyJSON.Password != "" && verifyJSON.Username != "" && verifyJSON.URL != "" {
		verifyJSON.Message = ""
		jsonStr, err := json.MarshalIndent(verifyJSON, "", "  ")
		internal.Check(err)
		jsonStr = append(jsonStr, '\n')
		filename := internal.ConfigFile
		dir := path.Dir(filename)
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			internal.Check(os.Mkdir(dir, 0740))
		}
		internal.Check(ioutil.WriteFile(filename, jsonStr, 0600))
	}
}
示例#8
0
文件: topic.go 项目: bnjjj/tatcli
func topicAddDeleteGroups(method string, topic string, groups []string, path string) {
	for _, groupname := range groups {
		t := topicGroupnameJSON{topic, groupname, recursive}
		jsonStr, err := json.Marshal(t)
		internal.Check(err)
		if method == "PUT" {
			internal.PutWant("/topic"+path, jsonStr)
		} else {
			internal.DeleteWant("/topic"+path, jsonStr)
		}
	}
}
示例#9
0
func groupAddDeleteUsers(method string, groupname string, users []string, path string) {
	for _, username := range users {
		t := groupUsernameJSON{groupname, username}
		jsonStr, err := json.Marshal(t)
		internal.Check(err)
		if method == "PUT" {
			internal.PutWant("/group"+path, jsonStr)
		} else {
			internal.DeleteWant("/group"+path, jsonStr)
		}
	}
}
示例#10
0
文件: reset.go 项目: bnjjj/tatcli
func userReset(username, email string) {
	ssl := ""
	if internal.SSLInsecureSkipVerify {
		ssl = "--sslInsecureSkipVerify=true"
	}

	m := userJSON{
		Username: username,
		Email:    email,
		Callback: fmt.Sprintf("tatcli %s --url=:scheme://:host::port:path user verify --save :username :token", ssl),
	}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	fmt.Printf(internal.PostWant("/user/reset", jsonStr))
}
示例#11
0
文件: verify.go 项目: bnjjj/tatcli
func userVerify(username, tokenVerify string) {
	url := fmt.Sprintf("/user/verify/%s/%s", username, tokenVerify)
	r := internal.GetWantReturn(url)

	var verifyJSON verifyJSON
	err := json.Unmarshal([]byte(r), &verifyJSON)
	internal.Check(err)

	// Display return to user (contains clear password)
	fmt.Printf(r)

	if save && verifyJSON.Password != "" && verifyJSON.Username != "" && verifyJSON.URL != "" {
		verifyJSON.Message = ""
		jsonStr, err := json.MarshalIndent(verifyJSON, "", "  ")
		internal.Check(err)
		jsonStr = append(jsonStr, '\n')
		filename := internal.ConfigFile
		dir := path.Dir(filename)
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			internal.Check(os.Mkdir(dir, 0740))
		}
		internal.Check(ioutil.WriteFile(filename, jsonStr, 0600))
	}
}
示例#12
0
文件: message.go 项目: bnjjj/tatcli
func messageAction(action, topic, idReference, message, option string) {
	m := messageActionJSON{message, idReference, action, option}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	if action == "remove" {
		internal.DeleteWant("/message/"+idReference, nil)
	} else if action == "like" || action == "unlike" ||
		action == "label" || action == "unlabel" ||
		action == "task" || action == "untask" ||
		action == "tag" || action == "untag" ||
		action == "update" {
		internal.PutWant("/message"+topic, jsonStr)
	} else {
		fmt.Print(internal.PostWant(fmt.Sprintf("/message%s", topic), jsonStr))
	}
}
示例#13
0
文件: parameter.go 项目: bnjjj/tatcli
func topicParam(topic string, maxLength int, canForceDate, canUpdateMsg, canDeleteMsg, canUpdateAllMsg, canDeleteAllMsg, isROPublic bool) {
	t := paramJSON{
		Topic:           topic,
		MaxLength:       maxLength,
		CanForceDate:    canForceDate,
		CanUpdateMsg:    canUpdateMsg,
		CanDeleteMsg:    canDeleteMsg,
		CanUpdateAllMsg: canUpdateAllMsg,
		CanDeleteAllMsg: canDeleteAllMsg,
		IsROPublic:      isROPublic,
		Recursive:       recursive,
	}
	jsonStr, err := json.Marshal(t)
	internal.Check(err)
	internal.PutWant("/topic/param", jsonStr)
}
示例#14
0
func socketInteractive() {
	c := newClient()

	done := make(chan bool)
	go socketRead(c)

	r := bufio.NewReader(os.Stdin)
	go func() {
		for {
			line, err := r.ReadString('\n')
			if err != nil && err.Error() != "unexpected newline" {
				internal.Check(err)
			}
			line = analyzeLine(c, line)
			if line != "" {
				if err = c.WriteMessage(1, []byte(line)); err != nil {
					fmt.Fprintf(os.Stderr, "%s\n", err.Error())
				}
			}
		}
	}()
	<-done
}
示例#15
0
文件: set_admin.go 项目: bnjjj/tatcli
func setAdminUserAction(username string) {
	m := usernameUserJSON{username}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	internal.PutWant("/user/setadmin", jsonStr)
}
示例#16
0
文件: create.go 项目: bnjjj/tatcli
func groupCreate(group, description string) {
	m := groupJSON{group, description}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	internal.PostWant("/group", jsonStr)
}
示例#17
0
文件: check.go 项目: bnjjj/tatcli
func checkUserAction(username string, fixPrivateTopics, fixDefaultGroup bool) {
	m := checkUserJSON{username, fixPrivateTopics, fixDefaultGroup}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	fmt.Println(internal.ReqWant("PUT", http.StatusCreated, "/user/check", jsonStr))
}
示例#18
0
文件: rename.go 项目: bnjjj/tatcli
func renameUserAction(username, newUsername string) {
	m := renameUserJSON{username, newUsername}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	internal.PutWant("/user/rename", jsonStr)
}
示例#19
0
文件: add.go 项目: bnjjj/tatcli
func userAdd(username, email, fullname string) {
	m := userJSON{username, fullname, email, "tatcli --url=:scheme://:host::port:path user verify --save :username :token"}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	fmt.Printf(internal.PostWant("/user", jsonStr))
}
示例#20
0
文件: create.go 项目: bnjjj/tatcli
func topicCreate(topic, description string) {
	m := topicJSON{topic, description}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	internal.PostWant("/topic", jsonStr)
}
示例#21
0
func resetSystemUserAction(username string) {
	m := resetSystemUserJSON{username}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	fmt.Print(internal.ReqWant("PUT", http.StatusCreated, "/user/resetsystem", jsonStr))
}
示例#22
0
func convertUserAction(username, canWriteNotifications string) {
	m := convertUserJSON{username, canWriteNotifications}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	fmt.Print(internal.ReqWant("PUT", http.StatusCreated, "/user/convert", jsonStr))
}
示例#23
0
文件: parameter.go 项目: ovh/tatcli
	Use:     "parameter",
	Short:   "Update param on one topic: tatcli topic param [--recursive] <topic> <maxLength> <canForceDate> <canUpdateMsg> <canDeleteMsg> <canUpdateAllMsg> <canDeleteAllMsg> <adminCanUpdateAllMsg> <adminCanDeleteAllMsg> <isAutoComputeTags> <isAutoComputeLabels>",
	Aliases: []string{"param"},
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 11 {
			internal.Exit("Invalid parameter to tatcli topic param. See tatcli topic param --help\n")
		}

		var err error

		p := tat.TopicParameters{
			Topic: args[0],
		}

		p.MaxLength, err = strconv.Atoi(args[1])
		internal.Check(err)
		p.CanForceDate, err = strconv.ParseBool(args[2])
		internal.Check(err)
		p.CanUpdateMsg, err = strconv.ParseBool(args[3])
		internal.Check(err)
		p.CanDeleteMsg, err = strconv.ParseBool(args[4])
		internal.Check(err)
		p.CanUpdateAllMsg, err = strconv.ParseBool(args[5])
		internal.Check(err)
		p.CanDeleteAllMsg, err = strconv.ParseBool(args[6])
		internal.Check(err)
		p.AdminCanUpdateAllMsg, err = strconv.ParseBool(args[7])
		internal.Check(err)
		p.AdminCanDeleteAllMsg, err = strconv.ParseBool(args[8])
		internal.Check(err)
		p.IsAutoComputeTags, err = strconv.ParseBool(args[9])
示例#24
0
文件: archive.go 项目: bnjjj/tatcli
func archiveUserAction(username string) {
	m := usernameUserJSON{username}
	jsonStr, err := json.Marshal(m)
	internal.Check(err)
	internal.PutWant("/user/archive", jsonStr)
}